Skip to content

Commit

Permalink
Merge pull request #256 from matter-labs/fix-optional
Browse files Browse the repository at this point in the history
value as optional parameter
  • Loading branch information
skywinder authored Apr 4, 2020
2 parents 2035f08 + fe16739 commit e7db23c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 206 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ cache: bundler
xcode_project: web3swift.xcworkspace
xcode_scheme: web3swift-iOS
xcode_destination: platform=iOS Simulator, OS=12.2, name=iPhone X
before_install:
- brew install carthage || true
- brew outdated carthage || brew upgrade carthage
before_script:
- carthage bootstrap --platform iOS --no-use-binaries --cache-builds
#before_install:
# - brew install carthage || true
# - brew outdated carthage || brew upgrade carthage
#before_script:
# - carthage bootstrap --platform iOS --no-use-binaries --cache-builds
script:
- xcodebuild -scheme web3swift -project web3swift.xcodeproj -sdk iphonesimulator build test
after_success:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = "Alexander Vlasov";
ORGANIZATIONNAME = "Matter Labs";
TargetAttributes = {
81E09B1B2002623A005DF51D = {
CreatedOnToolsVersion = 9.2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class ViewController: BrowserViewController {
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])

webView.load(URLRequest(url: URL(string: "https://app.compound.finance")!))

let urlToOpen = "https://1inch.exchange/"
// let urlToOpen = "https://app.compound.finance"
webView.load(URLRequest(url: URL(string: urlToOpen)!))

do {
let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
Expand Down
17 changes: 11 additions & 6 deletions Sources/web3swift/Transaction/EthereumTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public struct EthereumTransaction: CustomStringConvertible {
public var nonce: BigUInt
public var gasPrice: BigUInt = BigUInt(0)
public var gasLimit: BigUInt = BigUInt(0)
// The destination address of the message, left undefined for a contract-creation transaction.
public var to: EthereumAddress
public var value: BigUInt
// (optional) The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.
public var value: BigUInt?
public var data: Data
public var v: BigUInt = BigUInt(1)
public var r: BigUInt = BigUInt(0)
Expand Down Expand Up @@ -87,8 +89,8 @@ public struct EthereumTransaction: CustomStringConvertible {
toReturn = toReturn + "Nonce: " + String(self.nonce) + "\n"
toReturn = toReturn + "Gas price: " + String(self.gasPrice) + "\n"
toReturn = toReturn + "Gas limit: " + String(describing: self.gasLimit) + "\n"
toReturn = toReturn + "To: " + self.to.address + "\n"
toReturn = toReturn + "Value: " + String(self.value) + "\n"
toReturn = toReturn + "To: " + self.to.address + "\n"
toReturn = toReturn + "Value: " + String(self.value ?? "nil") + "\n"
toReturn = toReturn + "Data: " + self.data.toHexString().addHexPrefix().lowercased() + "\n"
toReturn = toReturn + "v: " + String(self.v) + "\n"
toReturn = toReturn + "r: " + String(self.r) + "\n"
Expand Down Expand Up @@ -193,7 +195,7 @@ public struct EthereumTransaction: CustomStringConvertible {
params.gas = gasEncoding?.toHexString().addHexPrefix().stripLeadingZeroes()
let gasPriceEncoding = self.gasPrice.abiEncode(bits: 256)
params.gasPrice = gasPriceEncoding?.toHexString().addHexPrefix().stripLeadingZeroes()
let valueEncoding = self.value.abiEncode(bits: 256)
let valueEncoding = self.value?.abiEncode(bits: 256)
params.value = valueEncoding?.toHexString().addHexPrefix().stripLeadingZeroes()
if (self.data != Data()) {
params.data = self.data.toHexString().addHexPrefix()
Expand Down Expand Up @@ -310,8 +312,11 @@ public extension EthereumTransaction {
self.gasLimit = BigUInt(UInt64(21000))
}
}

self.value = merged.value!

if let value = merged.value {
self.value = value
}

self.to = to
self.data = data
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/web3swift/Web3/Web3+Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public protocol TransactionOptionsInheritable {
public struct TransactionOptions {
/// Sets the transaction destination. It can either be a contract address or a private key controlled wallet address.
///
/// Usually should never be nil.
/// Usually should never be nil, left undefined for a contract-creation transaction.
public var to: EthereumAddress? = nil
/// Sets from what account a transaction should be sent. Used only internally as the sender of Ethereum transaction
/// is determined purely from the transaction signature. Indicates to the Ethereum node or to the local keystore what private key
Expand All @@ -40,6 +40,7 @@ public struct TransactionOptions {
}
public var gasPrice: GasPricePolicy?

/// The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.
public var value: BigUInt? = nil

public enum NoncePolicy {
Expand Down
Loading

0 comments on commit e7db23c

Please sign in to comment.