@@ -84,13 +84,15 @@ class EtherSpace(val web3: Web3,
8484 val np = options.nonceProvider ? : nonceProvider
8585
8686 val encodedFunction = web3.abi.encodeFunctionCall(args, functionName)
87- val nonce = np.getNonce(web3, cd.address)
88- val transactionObject = Web3 .TransactionObject (cd.address,
89- toAddress,
90- encodedFunction,
91- options,
92- nonce)
93- val transactionHash = web3.eth.sendTransaction(transactionObject, cd)
87+ val transactionHash = np.provideNonce(web3, cd.address) { nonce ->
88+ val transactionObject = Web3 .TransactionObject (cd.address,
89+ toAddress,
90+ encodedFunction,
91+ options,
92+ nonce)
93+ web3.eth.sendTransaction(transactionObject, cd)
94+ }
95+
9496 val returnTypeToken = TypeToken .of(returnType)
9597 return when {
9698 returnTypeToken.isSubtypeOf(String ::class .java) -> transactionHash
@@ -150,7 +152,11 @@ class EtherSpace(val web3: Web3,
150152 }
151153
152154 object TransactionCountNonceProvider : NonceProvider {
153- override fun getNonce (web3 : Web3 , address : String ): BigInteger {
155+ override fun provideNonce (web3 : Web3 , address : String , sendTransaction : (BigInteger ) -> String ): String {
156+ return sendTransaction(getNonce(web3, address))
157+ }
158+
159+ private fun getNonce (web3 : Web3 , address : String ): BigInteger {
154160 return web3.eth.getTransactionCount(address, Web3 .DefaultBlock .PENDING )
155161 }
156162 }
0 commit comments