Respect chainId from TransactionArgs when signing (#152)

This commit is contained in:
Yuriy Glukhov 2024-06-10 10:14:14 +02:00 committed by GitHub
parent ac93b9a993
commit 954c23cca2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View File

@ -304,7 +304,7 @@ proc send*(web3: Web3, c: TransactionArgs): Future[TxHash] {.async.} =
else:
return await web3.provider.eth_sendTransaction(c)
proc send*(web3: Web3, c: TransactionArgs, chainId: ChainId): Future[TxHash] {.async.} =
proc send*(web3: Web3, c: TransactionArgs, chainId: ChainId): Future[TxHash] {.deprecated: "Provide chainId in TransactionArgs", async.} =
doAssert(web3.privateKey.isSome())
var cc = c
if cc.nonce.isNone:
@ -325,6 +325,8 @@ proc sendData(web3: Web3,
else: none(Quantity)
nonce = if web3.privateKey.isSome(): some(await web3.nextNonce())
else: none(Quantity)
chainId = if chainId.isSome(): some(Quantity(chainId.get))
else: none(Quantity)
cc = TransactionArgs(
data: some(data),
@ -334,12 +336,10 @@ proc sendData(web3: Web3,
value: some(value),
nonce: nonce,
gasPrice: gasPrice,
chainId: chainId
)
if chainId.isNone:
return await web3.send(cc)
else:
return await web3.send(cc, chainId.get)
proc send*[T](c: ContractInvocation[T, Web3SenderImpl],
value = 0.u256,

View File

@ -50,10 +50,14 @@ func encodeTransaction*(s: TransactionArgs, pk: PrivateKey): seq[byte] =
tr.value = s.value.get
tr.nonce = uint64(s.nonce.get)
tr.payload = s.payload
if s.chainId.isSome():
tr.chainId = ChainId(s.chainId.get)
signTransactionEip155(tr, pk)
else:
signTransaction(tr, pk)
return rlp.encode(tr)
func encodeTransaction*(s: TransactionArgs, pk: PrivateKey, chainId: ChainId): seq[byte] =
func encodeTransaction*(s: TransactionArgs, pk: PrivateKey, chainId: ChainId): seq[byte] {.deprecated: "Provide chainId in TransactionArgs".} =
var tr = Transaction(txType: TxLegacy, chainId: chainId)
tr.gasLimit = s.gas.get.GasInt
tr.gasPrice = s.gasPrice.get.GasInt