Skip to content

Commit e7db23c

Browse files
authored
Merge pull request #256 from matter-labs/fix-optional
value as optional parameter
2 parents 2035f08 + fe16739 commit e7db23c

File tree

7 files changed

+42
-206
lines changed

7 files changed

+42
-206
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ cache: bundler
44
xcode_project: web3swift.xcworkspace
55
xcode_scheme: web3swift-iOS
66
xcode_destination: platform=iOS Simulator, OS=12.2, name=iPhone X
7-
before_install:
8-
- brew install carthage || true
9-
- brew outdated carthage || brew upgrade carthage
10-
before_script:
11-
- carthage bootstrap --platform iOS --no-use-binaries --cache-builds
7+
#before_install:
8+
# - brew install carthage || true
9+
# - brew outdated carthage || brew upgrade carthage
10+
#before_script:
11+
# - carthage bootstrap --platform iOS --no-use-binaries --cache-builds
1212
script:
1313
- xcodebuild -scheme web3swift -project web3swift.xcodeproj -sdk iphonesimulator build test
1414
after_success:

Example/web3swiftBrowser/web3swiftBrowser.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
attributes = {
222222
LastSwiftUpdateCheck = 0920;
223223
LastUpgradeCheck = 0920;
224-
ORGANIZATIONNAME = "Alexander Vlasov";
224+
ORGANIZATIONNAME = "Matter Labs";
225225
TargetAttributes = {
226226
81E09B1B2002623A005DF51D = {
227227
CreatedOnToolsVersion = 9.2;

Example/web3swiftBrowser/web3swiftBrowser/ViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class ViewController: BrowserViewController {
2222
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
2323
])
2424

25-
webView.load(URLRequest(url: URL(string: "https://app.compound.finance")!))
25+
26+
let urlToOpen = "https://1inch.exchange/"
27+
// let urlToOpen = "https://app.compound.finance"
28+
webView.load(URLRequest(url: URL(string: urlToOpen)!))
2629

2730
do {
2831
let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

Sources/web3swift/Transaction/EthereumTransaction.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ public struct EthereumTransaction: CustomStringConvertible {
1414
public var nonce: BigUInt
1515
public var gasPrice: BigUInt = BigUInt(0)
1616
public var gasLimit: BigUInt = BigUInt(0)
17+
// The destination address of the message, left undefined for a contract-creation transaction.
1718
public var to: EthereumAddress
18-
public var value: BigUInt
19+
// (optional) The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.
20+
public var value: BigUInt?
1921
public var data: Data
2022
public var v: BigUInt = BigUInt(1)
2123
public var r: BigUInt = BigUInt(0)
@@ -87,8 +89,8 @@ public struct EthereumTransaction: CustomStringConvertible {
8789
toReturn = toReturn + "Nonce: " + String(self.nonce) + "\n"
8890
toReturn = toReturn + "Gas price: " + String(self.gasPrice) + "\n"
8991
toReturn = toReturn + "Gas limit: " + String(describing: self.gasLimit) + "\n"
90-
toReturn = toReturn + "To: " + self.to.address + "\n"
91-
toReturn = toReturn + "Value: " + String(self.value) + "\n"
92+
toReturn = toReturn + "To: " + self.to.address + "\n"
93+
toReturn = toReturn + "Value: " + String(self.value ?? "nil") + "\n"
9294
toReturn = toReturn + "Data: " + self.data.toHexString().addHexPrefix().lowercased() + "\n"
9395
toReturn = toReturn + "v: " + String(self.v) + "\n"
9496
toReturn = toReturn + "r: " + String(self.r) + "\n"
@@ -193,7 +195,7 @@ public struct EthereumTransaction: CustomStringConvertible {
193195
params.gas = gasEncoding?.toHexString().addHexPrefix().stripLeadingZeroes()
194196
let gasPriceEncoding = self.gasPrice.abiEncode(bits: 256)
195197
params.gasPrice = gasPriceEncoding?.toHexString().addHexPrefix().stripLeadingZeroes()
196-
let valueEncoding = self.value.abiEncode(bits: 256)
198+
let valueEncoding = self.value?.abiEncode(bits: 256)
197199
params.value = valueEncoding?.toHexString().addHexPrefix().stripLeadingZeroes()
198200
if (self.data != Data()) {
199201
params.data = self.data.toHexString().addHexPrefix()
@@ -310,8 +312,11 @@ public extension EthereumTransaction {
310312
self.gasLimit = BigUInt(UInt64(21000))
311313
}
312314
}
313-
314-
self.value = merged.value!
315+
316+
if let value = merged.value {
317+
self.value = value
318+
}
319+
315320
self.to = to
316321
self.data = data
317322
}

Sources/web3swift/Web3/Web3+Options.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public protocol TransactionOptionsInheritable {
1616
public struct TransactionOptions {
1717
/// Sets the transaction destination. It can either be a contract address or a private key controlled wallet address.
1818
///
19-
/// Usually should never be nil.
19+
/// Usually should never be nil, left undefined for a contract-creation transaction.
2020
public var to: EthereumAddress? = nil
2121
/// Sets from what account a transaction should be sent. Used only internally as the sender of Ethereum transaction
2222
/// is determined purely from the transaction signature. Indicates to the Ethereum node or to the local keystore what private key
@@ -40,6 +40,7 @@ public struct TransactionOptions {
4040
}
4141
public var gasPrice: GasPricePolicy?
4242

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

4546
public enum NoncePolicy {

0 commit comments

Comments
 (0)