Fixed serialization compatibility with geth. Added getMinedTransactionReceipt
This commit is contained in:
parent
ecd2fb45a6
commit
37fc461114
|
@ -15,7 +15,7 @@ proc deployContract*(web3: Web3, code: string, gasPrice = 0): Future[Address] {.
|
|||
tr.gasPrice = some(gasPrice)
|
||||
|
||||
let r = await web3.send(tr)
|
||||
let receipt = await provider.eth_getTransactionReceipt(r)
|
||||
let receipt = await web3.getMinedTransactionReceipt(r)
|
||||
result = receipt.contractAddress.get
|
||||
|
||||
proc ethToWei*(eth: UInt256): UInt256 =
|
||||
|
|
19
web3.nim
19
web3.nim
|
@ -686,9 +686,9 @@ proc send*(web3: Web3, c: EthSend): Future[TxHash] {.async.} =
|
|||
if web3.signatureEnabled():
|
||||
var cc = c
|
||||
if not cc.nonce.isSome:
|
||||
let fromAddress = web3.privateKey.getPublicKey.toCanonicalAddress
|
||||
let fromAddress = web3.privateKey.getPublicKey.toCanonicalAddress.Address
|
||||
cc.nonce = some(int(await web3.provider.eth_getTransactionCount(fromAddress, "latest")))
|
||||
let t = encodeTransaction(cc, web3.privateKey)
|
||||
let t = "0x" & encodeTransaction(cc, web3.privateKey)
|
||||
return await web3.provider.eth_sendRawTransaction(t)
|
||||
else:
|
||||
return await web3.provider.eth_sendTransaction(c)
|
||||
|
@ -718,11 +718,20 @@ proc call*[T](c: ContractCall[T], value = 0.u256, gas = 3000000'u64): Future[T]
|
|||
discard decode(strip0xPrefix(response), 0, res)
|
||||
return res
|
||||
|
||||
proc getMinedTransactionReceipt*(web3: Web3, tx: TxHash): Future[ReceiptObject] {.async.} =
|
||||
## Returns the receipt for the transaction. Waits for it to be mined if necessary.
|
||||
# TODO: Potentially more optimal solution is to subscribe and wait for appropriate
|
||||
# notification. Now we're just polling every 500ms which should be ok for most cases.
|
||||
var r: Option[ReceiptObject]
|
||||
while r.isNone:
|
||||
r = await web3.provider.eth_getTransactionReceipt(tx)
|
||||
if r.isNone:
|
||||
await sleepAsync(500.milliseconds)
|
||||
result = r.get
|
||||
|
||||
proc exec*[T](c: ContractCall[T], value = 0.u256, gas = 3000000'u64): Future[T] {.async.} =
|
||||
let h = await c.send(value, gas)
|
||||
# TODO: Wait for tx to be mined
|
||||
|
||||
let receipt = await c.web3.provider.eth_getTransactionReceipt(h)
|
||||
let receipt = await c.web3.getMinedTransactionReceipt(h)
|
||||
|
||||
# TODO: decode result from receipt
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
## This module contains signatures for the Ethereum client RPCs.
|
||||
## The signatures are not imported directly, but read and processed with parseStmt,
|
||||
## then a procedure body is generated to marshal native Nim parameters to json and visa versa.
|
||||
import json, stint, ethtypes
|
||||
import json, options, stint, ethtypes
|
||||
|
||||
proc web3_clientVersion(): string
|
||||
proc web3_sha3(data: string): string
|
||||
|
@ -17,14 +17,14 @@ proc eth_gasPrice(): int64
|
|||
proc eth_accounts(): seq[Address]
|
||||
proc eth_blockNumber(): Quantity
|
||||
proc eth_getBalance(data: Address, quantityTag: string): UInt256
|
||||
proc eth_getStorageAt(data: array[20, byte], quantity: int, quantityTag: string): seq[byte]
|
||||
proc eth_getTransactionCount(data: array[20, byte], quantityTag: string): Quantity
|
||||
proc eth_getStorageAt(data: Address, quantity: int, quantityTag: string): seq[byte]
|
||||
proc eth_getTransactionCount(data: Address, quantityTag: string): Quantity
|
||||
proc eth_getBlockTransactionCountByHash(data: BlockHash)
|
||||
proc eth_getBlockTransactionCountByNumber(quantityTag: string)
|
||||
proc eth_getUncleCountByBlockHash(data: BlockHash)
|
||||
proc eth_getUncleCountByBlockNumber(quantityTag: string)
|
||||
proc eth_getCode(data: array[20, byte], quantityTag: string): seq[byte]
|
||||
proc eth_sign(data: array[20, byte], message: seq[byte]): seq[byte]
|
||||
proc eth_getCode(data: Address, quantityTag: string): seq[byte]
|
||||
proc eth_sign(data: Address, message: seq[byte]): seq[byte]
|
||||
proc eth_sendTransaction(obj: EthSend): TxHash
|
||||
proc eth_sendRawTransaction(data: string): TxHash
|
||||
proc eth_call(call: EthCall, quantityTag: string): string #UInt256
|
||||
|
@ -34,7 +34,7 @@ proc eth_getBlockByNumber(quantityTag: string, fullTransactions: bool): BlockObj
|
|||
proc eth_getTransactionByHash(data: TxHash): TransactionObject
|
||||
proc eth_getTransactionByBlockHashAndIndex(data: UInt256, quantity: int): TransactionObject
|
||||
proc eth_getTransactionByBlockNumberAndIndex(quantityTag: string, quantity: int): TransactionObject
|
||||
proc eth_getTransactionReceipt(data: TxHash): ReceiptObject
|
||||
proc eth_getTransactionReceipt(data: TxHash): Option[ReceiptObject]
|
||||
proc eth_getUncleByBlockHashAndIndex(data: UInt256, quantity: int64): BlockObject
|
||||
proc eth_getUncleByBlockNumberAndIndex(quantityTag: string, quantity: int64): BlockObject
|
||||
proc eth_getCompilers(): seq[string]
|
||||
|
|
Loading…
Reference in New Issue