Skip to content

Commit fa38a7a

Browse files
committed
- Add extra check to not transact to the non-mutating function
1 parent 3e90f67 commit fa38a7a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

web3swift/Web3/Classes/Web3+MutatingTransaction.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ public class WriteTransaction: ReadTransaction {
1616
var assembledTransaction : EthereumTransaction = self.transaction
1717
let queue = self.web3.requestDispatcher.queue
1818
let returnPromise = Promise<EthereumTransaction> { seal in
19+
if self.method != "fallback" {
20+
let m = self.contract.methods[self.method]
21+
if m == nil {
22+
seal.reject(Web3Error.inputError(desc: "Contract's ABI does not have such method"))
23+
return
24+
}
25+
switch m! {
26+
case .function(let function):
27+
if function.constant {
28+
seal.reject(Web3Error.inputError(desc: "Trying to transact to the constant function"))
29+
return
30+
}
31+
case .constructor(_):
32+
break
33+
default:
34+
seal.reject(Web3Error.inputError(desc: "Contract's ABI does not have such method"))
35+
return
36+
}
37+
}
38+
1939
var mergedOptions = self.transactionOptions.merge(transactionOptions)
2040

2141
var forAssemblyPipeline : (EthereumTransaction, EthereumContract, TransactionOptions) = (assembledTransaction, self.contract, mergedOptions)

0 commit comments

Comments
 (0)