mirror of
https://github.com/status-im/nim-ethers.git
synced 2025-03-01 15:40:38 +00:00
Introduce separate type for transaction overrides
This commit is contained in:
parent
a7d1944406
commit
083af80dcc
@ -16,6 +16,11 @@ type
|
|||||||
provider: Provider
|
provider: Provider
|
||||||
signer: ?Signer
|
signer: ?Signer
|
||||||
address: Address
|
address: Address
|
||||||
|
TransactionOverrides* = object
|
||||||
|
nonce*: ?UInt256
|
||||||
|
gasPrice*: ?UInt256
|
||||||
|
gasLimit*: ?UInt256
|
||||||
|
|
||||||
ContractError* = object of EthersError
|
ContractError* = object of EthersError
|
||||||
Confirmable* = ?TransactionResponse
|
Confirmable* = ?TransactionResponse
|
||||||
EventHandler*[E: Event] = proc(event: E) {.gcsafe, upraises:[].}
|
EventHandler*[E: Event] = proc(event: E) {.gcsafe, upraises:[].}
|
||||||
@ -48,13 +53,16 @@ template raiseContractError(message: string) =
|
|||||||
proc createTransaction(contract: Contract,
|
proc createTransaction(contract: Contract,
|
||||||
function: string,
|
function: string,
|
||||||
parameters: tuple,
|
parameters: tuple,
|
||||||
overrides = Transaction.default): Transaction =
|
overrides = TransactionOverrides.default): Transaction =
|
||||||
let selector = selector(function, typeof parameters).toArray
|
let selector = selector(function, typeof parameters).toArray
|
||||||
let data = @selector & AbiEncoder.encode(parameters)
|
let data = @selector & AbiEncoder.encode(parameters)
|
||||||
var transaction = overrides
|
Transaction(
|
||||||
transaction.to = contract.address
|
to: contract.address,
|
||||||
transaction.data = data
|
data: data,
|
||||||
return transaction
|
gasPrice: overrides.gasPrice,
|
||||||
|
gasLimit: overrides.gasLimit,
|
||||||
|
nonce: overrides.nonce
|
||||||
|
)
|
||||||
|
|
||||||
proc decodeResponse(T: type, multiple: static bool, bytes: seq[byte]): T =
|
proc decodeResponse(T: type, multiple: static bool, bytes: seq[byte]): T =
|
||||||
when multiple:
|
when multiple:
|
||||||
@ -84,7 +92,7 @@ proc call(contract: Contract,
|
|||||||
proc send(contract: Contract,
|
proc send(contract: Contract,
|
||||||
function: string,
|
function: string,
|
||||||
parameters: tuple,
|
parameters: tuple,
|
||||||
overrides = Transaction.default):
|
overrides = TransactionOverrides.default):
|
||||||
Future[?TransactionResponse] {.async.} =
|
Future[?TransactionResponse] {.async.} =
|
||||||
if signer =? contract.signer:
|
if signer =? contract.signer:
|
||||||
let transaction = createTransaction(contract, function, parameters, overrides)
|
let transaction = createTransaction(contract, function, parameters, overrides)
|
||||||
@ -122,7 +130,7 @@ func addOverrides(procedure: var NimNode) =
|
|||||||
newIdentDefs(
|
newIdentDefs(
|
||||||
ident("overrides"),
|
ident("overrides"),
|
||||||
newEmptyNode(),
|
newEmptyNode(),
|
||||||
quote do: Transaction.default
|
quote do: TransactionOverrides.default
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ suite "Contracts":
|
|||||||
check (await token.connect(provider).balanceOf(accounts[2])) == 25.u256
|
check (await token.connect(provider).balanceOf(accounts[2])) == 25.u256
|
||||||
|
|
||||||
test "takes custom values for nonce, gasprice and gaslimit":
|
test "takes custom values for nonce, gasprice and gaslimit":
|
||||||
let overrides = Transaction(
|
let overrides = TransactionOverrides(
|
||||||
nonce: some 100.u256,
|
nonce: some 100.u256,
|
||||||
gasPrice: some 200.u256,
|
gasPrice: some 200.u256,
|
||||||
gasLimit: some 300.u256
|
gasLimit: some 300.u256
|
||||||
|
Loading…
x
Reference in New Issue
Block a user