Use "pending" blocktag by default, instead of "latest"
This allows better simulation of the effects of sending a transaction before actually sending it. Especially when the block timestamp is used in the transaction.
This commit is contained in:
parent
3c12a65769
commit
e856b57669
|
@ -80,19 +80,17 @@ proc decodeResponse(T: type, multiple: static bool, bytes: seq[byte]): T =
|
||||||
|
|
||||||
proc call(contract: Contract,
|
proc call(contract: Contract,
|
||||||
function: string,
|
function: string,
|
||||||
parameters: tuple,
|
parameters: tuple) {.async.} =
|
||||||
blockTag = BlockTag.latest) {.async.} =
|
|
||||||
let transaction = createTransaction(contract, function, parameters)
|
let transaction = createTransaction(contract, function, parameters)
|
||||||
discard await contract.provider.call(transaction, blockTag)
|
discard await contract.provider.call(transaction)
|
||||||
|
|
||||||
proc call(contract: Contract,
|
proc call(contract: Contract,
|
||||||
function: string,
|
function: string,
|
||||||
parameters: tuple,
|
parameters: tuple,
|
||||||
ReturnType: type,
|
ReturnType: type,
|
||||||
returnMultiple: static bool,
|
returnMultiple: static bool): Future[ReturnType] {.async.} =
|
||||||
blockTag = BlockTag.latest): Future[ReturnType] {.async.} =
|
|
||||||
let transaction = createTransaction(contract, function, parameters)
|
let transaction = createTransaction(contract, function, parameters)
|
||||||
let response = await contract.provider.call(transaction, blockTag)
|
let response = await contract.provider.call(transaction)
|
||||||
return decodeResponse(ReturnType, returnMultiple, response)
|
return decodeResponse(ReturnType, returnMultiple, response)
|
||||||
|
|
||||||
proc send(contract: Contract,
|
proc send(contract: Contract,
|
||||||
|
|
|
@ -59,7 +59,7 @@ method getBlock*(provider: Provider, tag: BlockTag): Future[?Block] {.base.} =
|
||||||
|
|
||||||
method call*(provider: Provider,
|
method call*(provider: Provider,
|
||||||
tx: Transaction,
|
tx: Transaction,
|
||||||
blockTag = BlockTag.latest): Future[seq[byte]] {.base.} =
|
blockTag = BlockTag.pending): Future[seq[byte]] {.base.} =
|
||||||
doAssert false, "not implemented"
|
doAssert false, "not implemented"
|
||||||
|
|
||||||
method getGasPrice*(provider: Provider): Future[UInt256] {.base.} =
|
method getGasPrice*(provider: Provider): Future[UInt256] {.base.} =
|
||||||
|
@ -67,7 +67,7 @@ method getGasPrice*(provider: Provider): Future[UInt256] {.base.} =
|
||||||
|
|
||||||
method getTransactionCount*(provider: Provider,
|
method getTransactionCount*(provider: Provider,
|
||||||
address: Address,
|
address: Address,
|
||||||
blockTag = BlockTag.latest):
|
blockTag = BlockTag.pending):
|
||||||
Future[UInt256] {.base.} =
|
Future[UInt256] {.base.} =
|
||||||
doAssert false, "not implemented"
|
doAssert false, "not implemented"
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ method getGasPrice*(provider: JsonRpcProvider): Future[UInt256] {.async.} =
|
||||||
|
|
||||||
method getTransactionCount*(provider: JsonRpcProvider,
|
method getTransactionCount*(provider: JsonRpcProvider,
|
||||||
address: Address,
|
address: Address,
|
||||||
blockTag = BlockTag.latest):
|
blockTag = BlockTag.pending):
|
||||||
Future[UInt256] {.async.} =
|
Future[UInt256] {.async.} =
|
||||||
convertError:
|
convertError:
|
||||||
let client = await provider.client
|
let client = await provider.client
|
||||||
|
|
|
@ -27,7 +27,7 @@ method getGasPrice*(signer: Signer): Future[UInt256] {.base.} =
|
||||||
signer.provider.getGasPrice()
|
signer.provider.getGasPrice()
|
||||||
|
|
||||||
method getTransactionCount*(signer: Signer,
|
method getTransactionCount*(signer: Signer,
|
||||||
blockTag = BlockTag.latest):
|
blockTag = BlockTag.pending):
|
||||||
Future[UInt256] {.base, async.} =
|
Future[UInt256] {.base, async.} =
|
||||||
let address = await signer.getAddress()
|
let address = await signer.getAddress()
|
||||||
return await signer.provider.getTransactionCount(address, blockTag)
|
return await signer.provider.getTransactionCount(address, blockTag)
|
||||||
|
@ -55,7 +55,7 @@ method populateTransaction*(signer: Signer,
|
||||||
if transaction.sender.isNone:
|
if transaction.sender.isNone:
|
||||||
populated.sender = some(await signer.getAddress())
|
populated.sender = some(await signer.getAddress())
|
||||||
if transaction.nonce.isNone:
|
if transaction.nonce.isNone:
|
||||||
populated.nonce = some(await signer.getTransactionCount(BlockTag.pending))
|
populated.nonce = some(await signer.getTransactionCount())
|
||||||
if transaction.chainId.isNone:
|
if transaction.chainId.isNone:
|
||||||
populated.chainId = some(await signer.getChainId())
|
populated.chainId = some(await signer.getChainId())
|
||||||
if transaction.gasPrice.isNone and (transaction.maxFee.isNone or transaction.maxPriorityFee.isNone):
|
if transaction.gasPrice.isNone and (transaction.maxFee.isNone or transaction.maxPriorityFee.isNone):
|
||||||
|
|
|
@ -27,7 +27,7 @@ suite "JsonRpcSigner":
|
||||||
|
|
||||||
test "can retrieve transaction count":
|
test "can retrieve transaction count":
|
||||||
let signer = provider.getSigner(accounts[9])
|
let signer = provider.getSigner(accounts[9])
|
||||||
let count = await signer.getTransactionCount(BlockTag.pending)
|
let count = await signer.getTransactionCount()
|
||||||
check count == 0.u256
|
check count == 0.u256
|
||||||
|
|
||||||
test "can estimate gas cost of a transaction":
|
test "can estimate gas cost of a transaction":
|
||||||
|
@ -51,7 +51,7 @@ suite "JsonRpcSigner":
|
||||||
let populated = await signer.populateTransaction(transaction)
|
let populated = await signer.populateTransaction(transaction)
|
||||||
check !populated.sender == await signer.getAddress()
|
check !populated.sender == await signer.getAddress()
|
||||||
check !populated.gasPrice == await signer.getGasPrice()
|
check !populated.gasPrice == await signer.getGasPrice()
|
||||||
check !populated.nonce == await signer.getTransactionCount(BlockTag.pending)
|
check !populated.nonce == await signer.getTransactionCount()
|
||||||
check !populated.gasLimit == await signer.estimateGas(transaction)
|
check !populated.gasLimit == await signer.estimateGas(transaction)
|
||||||
check !populated.chainId == await signer.getChainId()
|
check !populated.chainId == await signer.getChainId()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue