Skip to content

Commit dcbfee3

Browse files
Rename ReadOperation.decodedData() method to more appropriate callContractMethod.
Rename `WriteOperation.send(:)` method to more appropriate `writeToChain`
1 parent bac93d1 commit dcbfee3

31 files changed

+295
-317
lines changed

Sources/web3swift/Operations/ReadTransaction.swift

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,8 @@ public class ReadOperation {
3232
}
3333
}
3434

35-
// FIXME: Update all properties of transaction relating gon contract specifics.
36-
public func prepareTransaction() {
37-
38-
}
39-
40-
public func execute() async throws -> Data {
41-
let data: Data = try await self.web3.eth.callTransaction(transaction)
42-
return data
43-
}
44-
45-
46-
// FIXME: This is wrong naming, because this method doesn't decode,
47-
// it's merging Transactions Oprions sending request (Transaction with appropriate binary data) to contract, get's Data response
48-
// and only then it decodes it.
49-
// It should be splitted in this way up to three (merge, send, decode)
5035
// TODO: Remove type erasing here, some broad wide protocol should be added instead
51-
// FIXME: Rewrite this to CodableTransaction
52-
public func decodedData() async throws -> [String: Any] {
36+
public func callContractMethod() async throws -> [String: Any] {
5337
// MARK: Read data from ABI flow
5438
// FIXME: This should be dropped, and after `execute()` call, just to decode raw data.
5539
let data: Data = try await self.web3.eth.callTransaction(transaction)
@@ -62,10 +46,4 @@ public class ReadOperation {
6246
}
6347
return decodedData
6448
}
65-
66-
// FIXME: Rewrite this to CodableTransaction
67-
// FIXME: Useless wrapper, delete me
68-
public func call() async throws -> [String: Any] {
69-
return try await self.decodedData()
70-
}
7149
}

Sources/web3swift/Operations/WriteOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Core
1111
public class WriteOperation: ReadOperation {
1212

1313
// FIXME: Rewrite this to CodableTransaction
14-
public func send(password: String) async throws -> TransactionSendingResult {
14+
public func writeToChain(password: String) async throws -> TransactionSendingResult {
1515
if let attachedKeystoreManager = self.web3.provider.attachedKeystoreManager {
1616
do {
1717
try Web3Signer.signTX(transaction: &transaction,

Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class ERC1155: IERC1155 {
7373
var transactionOptions = CodableTransaction.emptyTransaction
7474
transactionOptions.callOnBlock = .latest
7575

76-
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.decodedData() else {return}
76+
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return}
7777

7878
guard let tokenId = tokenIdPromise["0"] as? BigUInt else {return}
7979
self._tokenId = tokenId
@@ -108,7 +108,7 @@ public class ERC1155: IERC1155 {
108108
transactionOptions.callOnBlock = .latest
109109
let result = try await contract
110110
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
111-
.decodedData()
111+
.callContractMethod()
112112

113113
/*
114114
let result = try await contract
@@ -135,7 +135,7 @@ public class ERC1155: IERC1155 {
135135
let contract = self.contract
136136
var basicOptions = CodableTransaction.emptyTransaction
137137
basicOptions.callOnBlock = .latest
138-
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data() )!.decodedData()
138+
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data() )!.callContractMethod()
139139
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
140140
return res
141141
}
@@ -145,7 +145,7 @@ public class ERC1155: IERC1155 {
145145
var transactionOptions = CodableTransaction.emptyTransaction
146146
transactionOptions.callOnBlock = .latest
147147
transactionOptions.gasLimitPolicy = .manual(30000)
148-
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.decodedData()
148+
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod()
149149
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
150150
return res
151151
}

Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
9898
let contract = self.contract
9999
var transactionOptions = CodableTransaction.emptyTransaction
100100
transactionOptions.callOnBlock = .latest
101-
let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.decodedData()
101+
let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod()
102102
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
103103
return res
104104
}
@@ -107,7 +107,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
107107
let contract = self.contract
108108
var transactionOptions = CodableTransaction.emptyTransaction
109109
transactionOptions.callOnBlock = .latest
110-
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data() )!.decodedData()
110+
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data() )!.callContractMethod()
111111
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
112112
return res
113113
}
@@ -120,7 +120,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
120120
basicOptions.callOnBlock = .latest
121121

122122
// get the decimals manually
123-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
123+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
124124
var decimals = BigUInt(0)
125125
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
126126
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -142,7 +142,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
142142
basicOptions.callOnBlock = .latest
143143

144144
// get the decimals manually
145-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
145+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
146146
var decimals = BigUInt(0)
147147
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
148148
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -165,7 +165,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
165165
basicOptions.callOnBlock = .latest
166166

167167
// get the decimals manually
168-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
168+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
169169
var decimals = BigUInt(0)
170170
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
171171
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -188,7 +188,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
188188
basicOptions.callOnBlock = .latest
189189

190190
// get the decimals manually
191-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
191+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
192192
var decimals = BigUInt(0)
193193
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
194194
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -207,7 +207,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
207207
let contract = self.contract
208208
var transactionOptions = CodableTransaction.emptyTransaction
209209
transactionOptions.callOnBlock = .latest
210-
let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.decodedData()
210+
let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod()
211211
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
212212
return res
213213
}
@@ -220,7 +220,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
220220
basicOptions.callOnBlock = .latest
221221

222222
// get the decimals manually
223-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
223+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
224224
var decimals = BigUInt(0)
225225
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
226226
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -246,7 +246,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
246246
basicOptions.callOnBlock = .latest
247247

248248
// get the decimals manually
249-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
249+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
250250
var decimals = BigUInt(0)
251251
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
252252
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -269,7 +269,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
269269
basicOptions.callOnBlock = .latest
270270

271271
// get the decimals manually
272-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
272+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
273273
var decimals = BigUInt(0)
274274
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
275275
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -298,7 +298,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
298298
let contract = self.contract
299299
var transactionOptions = CodableTransaction.emptyTransaction
300300
transactionOptions.callOnBlock = .latest
301-
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data() )!.decodedData()
301+
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data() )!.callContractMethod()
302302
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
303303
return res
304304
}
@@ -311,7 +311,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
311311
basicOptions.callOnBlock = .latest
312312

313313
// get the decimals manually
314-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
314+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
315315
var decimals = BigUInt(0)
316316
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
317317
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -333,7 +333,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
333333
basicOptions.callOnBlock = .latest
334334

335335
// get the decimals manually
336-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
336+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
337337
var decimals = BigUInt(0)
338338
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
339339
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -351,7 +351,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
351351
let contract = self.contract
352352
var transactionOptions = CodableTransaction.emptyTransaction
353353
transactionOptions.callOnBlock = .latest
354-
let result = try await contract.createReadOperation("nonceOf", parameters: [owner] as [AnyObject], extraData: Data() )!.decodedData()
354+
let result = try await contract.createReadOperation("nonceOf", parameters: [owner] as [AnyObject], extraData: Data() )!.callContractMethod()
355355
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
356356
return res
357357
}
@@ -375,7 +375,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
375375
basicOptions.callOnBlock = .latest
376376

377377
// get the decimals manually
378-
let callResult = try await contract.createReadOperation("decimals" )!.decodedData()
378+
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
379379
var decimals = BigUInt(0)
380380
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
381381
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -396,7 +396,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
396396
let contract = self.contract
397397
var transactionOptions = CodableTransaction.emptyTransaction
398398
transactionOptions.callOnBlock = .latest
399-
let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data() )!.decodedData()
399+
let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data() )!.callContractMethod()
400400
guard let res = result["0"] as? DirectDebit else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
401401
return res
402402
}

0 commit comments

Comments
 (0)