Skip to content

Commit 51970c7

Browse files
committed
clean up deprecated warnings created as a result of the updates to EthereumTransaction
1 parent ead7b71 commit 51970c7

File tree

8 files changed

+36
-29
lines changed

8 files changed

+36
-29
lines changed

Sources/web3swift/Contract/EthereumContract.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,18 @@ public struct EthereumContract: ContractProtocol {
114114
} else if extraData != Data() {
115115
fullData.append(extraData)
116116
}
117-
let transaction = EthereumTransaction(gasPrice: BigUInt(0), gasLimit: BigUInt(0), to: to, value: BigUInt(0), data: fullData)
117+
let params = EthereumParameters(gasLimit: BigUInt(0), gasPrice: BigUInt(0))
118+
let transaction = EthereumTransaction(to: to, value: BigUInt(0), data: fullData, parameters: params)
118119
return transaction
119120
}
120121

121122
public func method(_ method: String = "fallback", parameters: [AnyObject] = [AnyObject](), extraData: Data = Data()) -> EthereumTransaction? {
122123
guard let to = self.address else {return nil}
123124

124125
if (method == "fallback") {
125-
let transaction = EthereumTransaction(gasPrice: BigUInt(0), gasLimit: BigUInt(0), to: to, value: BigUInt(0), data: extraData)
126+
let params = EthereumParameters(gasLimit: BigUInt(0), gasPrice: BigUInt(0))
127+
let transaction = EthereumTransaction(to: to, value: BigUInt(0), data: extraData, parameters: params)
128+
126129
return transaction
127130
}
128131
let foundMethod = self.methods.filter { (key, value) -> Bool in
@@ -131,7 +134,8 @@ public struct EthereumContract: ContractProtocol {
131134
guard foundMethod.count == 1 else {return nil}
132135
let abiMethod = foundMethod[method]
133136
guard let encodedData = abiMethod?.encodeParameters(parameters) else {return nil}
134-
let transaction = EthereumTransaction(gasPrice: BigUInt(0), gasLimit: BigUInt(0), to: to, value: BigUInt(0), data: encodedData)
137+
let params = EthereumParameters(gasLimit: BigUInt(0), gasPrice: BigUInt(0))
138+
let transaction = EthereumTransaction(to: to, value: BigUInt(0), data: encodedData, parameters: params)
135139
return transaction
136140
}
137141

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ extension web3.BrowserFunctions {
134134
var options = opts
135135
guard let _ = options.from else {return (nil, nil)}
136136
let gasPrice = try self.web3.eth.getGasPrice()
137-
transaction.gasPrice = gasPrice
137+
transaction.parameters.gasPrice = gasPrice
138138
options.gasPrice = .manual(gasPrice)
139139
guard let gasEstimate = self.estimateGas(transaction, transactionOptions: options) else {return (nil, nil)}
140-
transaction.gasLimit = gasEstimate
140+
transaction.parameters.gasLimit = gasEstimate
141141
options.gasLimit = .limited(gasEstimate)
142142
print(transaction)
143143
return (transaction, options)
@@ -176,18 +176,18 @@ extension web3.BrowserFunctions {
176176
guard let noncePolicy = transactionOptions.nonce else {return nil}
177177
switch gasPricePolicy {
178178
case .manual(let gasPrice):
179-
transaction.gasPrice = gasPrice
179+
transaction.parameters.gasPrice = gasPrice
180180
default:
181181
let gasPrice = try self.web3.eth.getGasPrice()
182-
transaction.gasPrice = gasPrice
182+
transaction.parameters.gasPrice = gasPrice
183183
}
184184

185185
switch gasLimitPolicy {
186186
case .manual(let gasLimit):
187-
transaction.gasLimit = gasLimit
187+
transaction.parameters.gasLimit = gasLimit
188188
default:
189189
let gasLimit = try self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
190-
transaction.gasLimit = gasLimit
190+
transaction.parameters.gasLimit = gasLimit
191191
}
192192

193193
switch noncePolicy {
@@ -205,7 +205,7 @@ extension web3.BrowserFunctions {
205205
guard let keystore = keystoreManager.walletForAddress(from) else {return nil}
206206
try Web3Signer.signTX(transaction: &transaction, keystore: keystore, account: from, password: password)
207207
print(transaction)
208-
let signedData = transaction.encode(forSignature: false, chainID: nil)?.toHexString().addHexPrefix()
208+
let signedData = transaction.encode()?.toHexString().addHexPrefix()
209209
return signedData
210210
} catch {
211211
return nil

Sources/web3swift/Transaction/EthereumTransaction.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ public struct EthereumTransaction: CustomStringConvertible {
4848
set(newValue) { envelope.parameters.data = newValue }
4949
}
5050

51-
// transaction type specific parameters should be accessed with TransactionOptions via getOptions()
51+
// transaction type specific parameters should be accessed with EthereumParameters
52+
public var parameters: EthereumParameters {
53+
get { return envelope.parameters }
54+
set(val) { envelope.parameters = val }
55+
}
5256

5357
// signature data is read-only
5458
/// signature v component (read only)
@@ -239,15 +243,12 @@ extension EthereumTransaction {
239243
/// - v: signature v parameter (default 1) - will get set properly once signed
240244
/// - r: signature r parameter (default 0) - will get set properly once signed
241245
/// - s: signature s parameter (default 0) - will get set properly once signed
242-
/// - options: TransactionObject containing additional parametrs for the transaction like gas
246+
/// - parameters: EthereumParameters object containing additional parametrs for the transaction like gas
243247
public init(type: TransactionType? = nil, to: EthereumAddress, nonce: BigUInt = 0,
244248
chainID: BigUInt? = nil, value: BigUInt? = nil, data: Data,
245-
v: BigUInt = 1, r: BigUInt = 0, s: BigUInt = 0, options: TransactionOptions? = nil) {
249+
v: BigUInt = 1, r: BigUInt = 0, s: BigUInt = 0, parameters: EthereumParameters? = nil) {
246250

247-
var params: EthereumParameters
248-
// swiftlint:disable force_unwrapping
249-
if options != nil { params = EthereumParameters(from: options!) } else { params = EthereumParameters() }
250-
// swiftlint:enable force_unwrapping
251+
var params = parameters ?? EthereumParameters()
251252

252253
params.chainID = chainID ?? params.chainID
253254
params.value = value ?? params.value

Tests/web3swiftTests/localTests/LocalTests.xctestplan

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
{
1616
"skippedTests" : [
1717
"ENSTests",
18-
"RemoteTests",
1918
"GasOracleTests",
2019
"InfuraTests",
20+
"OracleTests",
2121
"RemoteParsingTests",
22+
"RemoteTests",
2223
"ST20AndSecurityTokenTests",
23-
"WebsocketTests",
24+
"WebsocketTests"
2425
],
2526
"target" : {
2627
"containerPath" : "container:web3swift.xcodeproj",

Tests/web3swiftTests/localTests/web3swiftBasicLocalNodeTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class web3swiftBasicLocalNodeTests: XCTestCase {
9292
print("Balance after from: " + balanceAfterFrom.description)
9393

9494
XCTAssert(balanceAfterTo - balanceBeforeTo == valueToSend)
95-
XCTAssert(balanceBeforeFrom - (balanceAfterFrom + receipt.gasUsed * details.transaction.gasPrice) == valueToSend)
95+
let txnGasPrice = details.transaction.parameters.gasPrice ?? 0
96+
XCTAssert(balanceBeforeFrom - (balanceAfterFrom + receipt.gasUsed * txnGasPrice) == valueToSend)
9697
}
9798

9899
// FIXME: Crashes on CI/CD

Tests/web3swiftTests/localTests/web3swiftPromisesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class web3swiftPromisesTests: XCTestCase {
3434
let txHash = writeResult.hash
3535
let result = try web3.eth.getTransactionDetailsPromise(txHash).wait()
3636
print(result)
37-
XCTAssert(result.transaction.gasLimit == BigUInt(gasLimit))
37+
XCTAssert(result.transaction.parameters.gasLimit == BigUInt(gasLimit))
3838
}
3939

4040
func testEstimateGasPromise() throws {

Tests/web3swiftTests/localTests/web3swiftTransactionsTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,13 @@ class web3swiftTransactionsTests: XCTestCase {
598598

599599
func testDirectTransaction() throws {
600600
do {
601-
var options = TransactionOptions()
602-
options.gasPrice = .manual(20000000000)
603-
options.gasLimit = .manual(21000)
601+
var params = EthereumParameters()
602+
params.gasPrice = 20000000000
603+
params.gasLimit = 21000
604604
var transaction = EthereumTransaction(
605605
to: EthereumAddress("0x3535353535353535353535353535353535353535")!,
606606
nonce: 9, value: 1000000000000000000, data: Data(),
607-
v: 0, r: 0, s: 0, options: options)
607+
v: 0, r: 0, s: 0, parameters: params)
608608
let privateKeyData = Data.fromHex("0x4646464646464646464646464646464646464646464646464646464646464646")!
609609
let publicKey = Web3.Utils.privateToPublic(privateKeyData, compressed: false)
610610
let sender = Web3.Utils.publicToAddress(publicKey!)
@@ -654,7 +654,7 @@ class web3swiftTransactionsTests: XCTestCase {
654654

655655
let details = try web3.eth.getTransactionDetails(txHash)
656656
print(details)
657-
let txnGasLimit = details.transaction.gasLimit
657+
let txnGasLimit = details.transaction.parameters.gasLimit
658658
XCTAssert(txnGasLimit == BigUInt(78423))
659659
} catch Web3Error.nodeError(let descr) {
660660
guard descr == "insufficient funds for gas * price + value" else {return XCTFail()}

Tests/web3swiftTests/localTests/web3swiftUserCases.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class web3swiftUserCases: XCTestCase {
4747
let gasEstimate = try writeTX.estimateGasPromise().wait()
4848
writeTX.transactionOptions.gasLimit = .manual(gasEstimate + 1234)
4949
let assembled = try writeTX.assemblePromise().wait()
50-
let txnGasLimit = assembled.gasLimit
50+
let txnGasLimit = assembled.parameters.gasLimit
5151
XCTAssert(txnGasLimit == gasEstimate + 1234)
5252
}
5353

@@ -62,8 +62,8 @@ class web3swiftUserCases: XCTestCase {
6262
let gasEstimate = try writeTX.estimateGasPromise().wait()
6363
writeTX.transactionOptions.gasLimit = .manual(gasEstimate + 1234)
6464
let assembled = try writeTX.assemblePromise().wait()
65-
let txnGasLimit = assembled.gasLimit
66-
let txnGasPrice = assembled.gasPrice
65+
let txnGasLimit = assembled.parameters.gasLimit
66+
let txnGasPrice = assembled.parameters.gasPrice
6767

6868
XCTAssert(txnGasLimit == gasEstimate + 1234)
6969
XCTAssert(txnGasPrice == gasPrice * 2)

0 commit comments

Comments
 (0)