@@ -14,8 +14,10 @@ public struct EthereumTransaction: CustomStringConvertible {
14
14
public var nonce : BigUInt
15
15
public var gasPrice : BigUInt = BigUInt ( 0 )
16
16
public var gasLimit : BigUInt = BigUInt ( 0 )
17
+ // The destination address of the message, left undefined for a contract-creation transaction.
17
18
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 ?
19
21
public var data : Data
20
22
public var v : BigUInt = BigUInt ( 1 )
21
23
public var r : BigUInt = BigUInt ( 0 )
@@ -87,8 +89,8 @@ public struct EthereumTransaction: CustomStringConvertible {
87
89
toReturn = toReturn + " Nonce: " + String( self . nonce) + " \n "
88
90
toReturn = toReturn + " Gas price: " + String( self . gasPrice) + " \n "
89
91
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 "
92
94
toReturn = toReturn + " Data: " + self . data. toHexString ( ) . addHexPrefix ( ) . lowercased ( ) + " \n "
93
95
toReturn = toReturn + " v: " + String( self . v) + " \n "
94
96
toReturn = toReturn + " r: " + String( self . r) + " \n "
@@ -193,7 +195,7 @@ public struct EthereumTransaction: CustomStringConvertible {
193
195
params. gas = gasEncoding? . toHexString ( ) . addHexPrefix ( ) . stripLeadingZeroes ( )
194
196
let gasPriceEncoding = self . gasPrice. abiEncode ( bits: 256 )
195
197
params. gasPrice = gasPriceEncoding? . toHexString ( ) . addHexPrefix ( ) . stripLeadingZeroes ( )
196
- let valueEncoding = self . value. abiEncode ( bits: 256 )
198
+ let valueEncoding = self . value? . abiEncode ( bits: 256 )
197
199
params. value = valueEncoding? . toHexString ( ) . addHexPrefix ( ) . stripLeadingZeroes ( )
198
200
if ( self . data != Data ( ) ) {
199
201
params. data = self . data. toHexString ( ) . addHexPrefix ( )
@@ -310,8 +312,11 @@ public extension EthereumTransaction {
310
312
self . gasLimit = BigUInt ( UInt64 ( 21000 ) )
311
313
}
312
314
}
313
-
314
- self . value = merged. value!
315
+
316
+ if let value = merged. value {
317
+ self . value = value
318
+ }
319
+
315
320
self . to = to
316
321
self . data = data
317
322
}
0 commit comments