2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-03-20 07:35:38 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-11-01 03:32:09 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2023-09-30 12:20:29 +00:00
|
|
|
import
|
2023-10-04 03:47:18 +00:00
|
|
|
std/[tables],
|
2023-09-30 12:20:29 +00:00
|
|
|
eth/keys,
|
2024-10-04 14:34:31 +00:00
|
|
|
eth/common/transaction_utils,
|
2023-09-30 12:20:29 +00:00
|
|
|
stew/endians2,
|
|
|
|
nimcrypto/sha2,
|
|
|
|
chronicles,
|
|
|
|
./engine_client,
|
2023-10-19 03:28:52 +00:00
|
|
|
./cancun/blobs,
|
2023-09-30 12:20:29 +00:00
|
|
|
../../../nimbus/transaction,
|
2023-10-04 03:47:18 +00:00
|
|
|
../../../nimbus/common,
|
|
|
|
../../../nimbus/utils/utils
|
2023-09-30 12:20:29 +00:00
|
|
|
|
2024-06-14 14:41:59 +00:00
|
|
|
from std/sequtils import mapIt
|
|
|
|
|
2023-09-30 12:20:29 +00:00
|
|
|
type
|
|
|
|
BaseTx* = object of RootObj
|
2024-06-14 07:31:08 +00:00
|
|
|
recipient* : Opt[EthAddress]
|
2024-04-19 19:43:13 +00:00
|
|
|
gasLimit* : GasInt
|
|
|
|
amount* : UInt256
|
|
|
|
payload* : seq[byte]
|
2024-06-14 07:31:08 +00:00
|
|
|
txType* : Opt[TxType]
|
2024-04-19 19:43:13 +00:00
|
|
|
gasTip* : GasInt
|
|
|
|
gasFee* : GasInt
|
|
|
|
blobGasFee*: UInt256
|
|
|
|
blobCount* : int
|
|
|
|
blobID* : BlobID
|
2023-09-30 12:20:29 +00:00
|
|
|
|
|
|
|
BigInitcodeTx* = object of BaseTx
|
|
|
|
initcodeLength*: int
|
|
|
|
padByte* : uint8
|
|
|
|
initcode* : seq[byte]
|
|
|
|
|
2023-10-19 03:28:52 +00:00
|
|
|
# Blob transaction creator
|
|
|
|
BlobTx* = object of BaseTx
|
|
|
|
|
|
|
|
TestAccount* = object
|
2023-10-31 03:18:37 +00:00
|
|
|
key* : PrivateKey
|
|
|
|
address*: EthAddress
|
|
|
|
index* : int
|
2023-09-30 12:20:29 +00:00
|
|
|
|
|
|
|
TxSender* = ref object
|
|
|
|
accounts: seq[TestAccount]
|
|
|
|
nonceMap: Table[EthAddress, uint64]
|
|
|
|
txSent : int
|
|
|
|
chainId : ChainID
|
|
|
|
|
|
|
|
MakeTxParams* = object
|
|
|
|
chainId*: ChainID
|
|
|
|
key* : PrivateKey
|
|
|
|
nonce* : AccountNonce
|
|
|
|
|
2023-10-31 03:18:37 +00:00
|
|
|
CustSig* = object
|
2024-06-14 07:31:08 +00:00
|
|
|
V*: uint64
|
2023-10-31 03:18:37 +00:00
|
|
|
R*: UInt256
|
|
|
|
S*: UInt256
|
|
|
|
|
2023-10-19 03:28:52 +00:00
|
|
|
CustomTransactionData* = object
|
2024-06-14 07:31:08 +00:00
|
|
|
nonce* : Opt[uint64]
|
|
|
|
gasPriceOrGasFeeCap*: Opt[GasInt]
|
|
|
|
gasTipCap* : Opt[GasInt]
|
|
|
|
gas* : Opt[GasInt]
|
|
|
|
to* : Opt[common.EthAddress]
|
|
|
|
value* : Opt[UInt256]
|
|
|
|
data* : Opt[seq[byte]]
|
|
|
|
chainId* : Opt[ChainId]
|
|
|
|
signature* : Opt[CustSig]
|
2023-10-19 03:28:52 +00:00
|
|
|
|
2023-09-30 12:20:29 +00:00
|
|
|
const
|
|
|
|
TestAccountCount = 1000
|
2023-10-19 03:28:52 +00:00
|
|
|
gasPrice* = 30.gwei
|
|
|
|
gasTipPrice* = 1.gwei
|
2024-04-19 19:43:13 +00:00
|
|
|
blobGasPrice* = 1.gwei
|
2023-09-30 12:20:29 +00:00
|
|
|
|
|
|
|
func toAddress(key: PrivateKey): EthAddress =
|
|
|
|
toKeyPair(key).pubkey.toCanonicalAddress()
|
|
|
|
|
|
|
|
proc createAccount(idx: int): TestAccount =
|
|
|
|
let
|
|
|
|
seed = toBytesBE(idx.uint64)
|
|
|
|
seedHash = sha256.digest(seed)
|
|
|
|
|
|
|
|
result.index = idx
|
|
|
|
result.key = PrivateKey.fromRaw(seedHash.data).valueOr:
|
|
|
|
echo error
|
|
|
|
quit(QuitFailure)
|
|
|
|
result.address = toAddress(result.key)
|
|
|
|
|
|
|
|
proc createAccounts(sender: TxSender) =
|
|
|
|
for i in 0..<TestAccountCount:
|
|
|
|
sender.accounts.add createAccount(i.int)
|
|
|
|
|
2023-10-31 03:18:37 +00:00
|
|
|
proc getNextAccount*(sender: TxSender): TestAccount =
|
2023-09-30 12:20:29 +00:00
|
|
|
sender.accounts[sender.txSent mod sender.accounts.len]
|
|
|
|
|
|
|
|
proc getNextNonce(sender: TxSender, address: EthAddress): uint64 =
|
|
|
|
let nonce = sender.nonceMap.getOrDefault(address, 0'u64)
|
|
|
|
sender.nonceMap[address] = nonce + 1
|
|
|
|
nonce
|
|
|
|
|
2023-10-19 03:28:52 +00:00
|
|
|
proc getLastNonce(sender: TxSender, address: EthAddress): uint64 =
|
2023-11-01 10:30:47 +00:00
|
|
|
if sender.nonceMap.hasKey(address):
|
|
|
|
return 0
|
|
|
|
sender.nonceMap[address] - 1
|
2023-10-19 03:28:52 +00:00
|
|
|
|
2023-09-30 12:20:29 +00:00
|
|
|
proc fillBalance(sender: TxSender, params: NetworkParams) =
|
|
|
|
for x in sender.accounts:
|
|
|
|
params.genesis.alloc[x.address] = GenesisAccount(
|
|
|
|
balance: UInt256.fromHex("0x123450000000000000000"),
|
|
|
|
)
|
|
|
|
|
|
|
|
proc new*(_: type TxSender, params: NetworkParams): TxSender =
|
2024-03-20 07:35:38 +00:00
|
|
|
result = TxSender(chainId: params.config.chainId)
|
2023-09-30 12:20:29 +00:00
|
|
|
result.createAccounts()
|
|
|
|
result.fillBalance(params)
|
|
|
|
|
|
|
|
proc getTxType(tc: BaseTx, nonce: uint64): TxType =
|
|
|
|
if tc.txType.isNone:
|
|
|
|
if nonce mod 2 == 0:
|
|
|
|
TxLegacy
|
|
|
|
else:
|
|
|
|
TxEIP1559
|
|
|
|
else:
|
|
|
|
tc.txType.get
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeTxOfType(params: MakeTxParams, tc: BaseTx): PooledTransaction =
|
2024-04-19 19:43:13 +00:00
|
|
|
let
|
|
|
|
gasFeeCap = if tc.gasFee != 0.GasInt: tc.gasFee
|
|
|
|
else: gasPrice
|
|
|
|
gasTipCap = if tc.gasTip != 0.GasInt: tc.gasTip
|
|
|
|
else: gasTipPrice
|
2023-09-30 12:20:29 +00:00
|
|
|
|
|
|
|
let txType = tc.getTxType(params.nonce)
|
2024-04-19 19:43:13 +00:00
|
|
|
case txType
|
|
|
|
of TxLegacy:
|
2024-05-15 03:07:59 +00:00
|
|
|
PooledTransaction(
|
|
|
|
tx: Transaction(
|
|
|
|
txType : TxLegacy,
|
|
|
|
nonce : params.nonce,
|
|
|
|
to : tc.recipient,
|
|
|
|
value : tc.amount,
|
|
|
|
gasLimit: tc.gasLimit,
|
|
|
|
gasPrice: gasPrice,
|
2024-10-04 14:34:31 +00:00
|
|
|
payload : tc.payload,
|
|
|
|
chainId : params.chainId,
|
2024-05-15 03:07:59 +00:00
|
|
|
)
|
2024-04-19 19:43:13 +00:00
|
|
|
)
|
|
|
|
of TxEip1559:
|
2024-05-15 03:07:59 +00:00
|
|
|
PooledTransaction(
|
|
|
|
tx: Transaction(
|
|
|
|
txType : TxEIP1559,
|
|
|
|
nonce : params.nonce,
|
|
|
|
gasLimit: tc.gasLimit,
|
2024-06-14 07:31:08 +00:00
|
|
|
maxFeePerGas: gasFeeCap,
|
|
|
|
maxPriorityFeePerGas: gasTipCap,
|
2024-05-15 03:07:59 +00:00
|
|
|
to : tc.recipient,
|
|
|
|
value : tc.amount,
|
|
|
|
payload : tc.payload,
|
|
|
|
chainId : params.chainId
|
|
|
|
)
|
2024-04-19 19:43:13 +00:00
|
|
|
)
|
|
|
|
of TxEip4844:
|
|
|
|
doAssert(tc.recipient.isSome, "recipient must be some")
|
|
|
|
let
|
|
|
|
blobCount = if tc.blobCount != 0: tc.blobCount
|
|
|
|
else: MAX_BLOBS_PER_BLOCK
|
|
|
|
blobFeeCap = if tc.blobGasFee != 0.u256: tc.blobGasFee
|
|
|
|
else: blobGasPrice.u256
|
|
|
|
|
|
|
|
# Need tx wrap data that will pass blob verification
|
|
|
|
var blobData = blobDataGenerator(tc.blobID, blobCount)
|
|
|
|
#tc.blobID += BlobID(blobCount)
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
PooledTransaction(
|
|
|
|
tx: Transaction(
|
|
|
|
txType : TxEIP4844,
|
|
|
|
nonce : params.nonce,
|
|
|
|
chainId : params.chainId,
|
2024-06-14 07:31:08 +00:00
|
|
|
maxFeePerGas: gasFeeCap,
|
|
|
|
maxPriorityFeePerGas: gasTipCap,
|
2024-05-15 03:07:59 +00:00
|
|
|
gasLimit: tc.gasLimit,
|
|
|
|
to : tc.recipient,
|
|
|
|
value : tc.amount,
|
|
|
|
payload : tc.payload,
|
|
|
|
#AccessList: tc.AccessList,
|
|
|
|
maxFeePerBlobGas: blobFeeCap,
|
|
|
|
versionedHashes: system.move(blobData.hashes),
|
|
|
|
),
|
2024-04-19 19:43:13 +00:00
|
|
|
networkPayload: NetworkPayload(
|
2024-06-14 14:41:59 +00:00
|
|
|
blobs: blobData.blobs.mapIt(it.bytes),
|
2024-10-06 10:11:44 +00:00
|
|
|
commitments: blobData.commitments.mapIt(KzgCommitment it.bytes),
|
|
|
|
proofs: blobData.proofs.mapIt(KzgProof it.bytes),
|
2024-04-19 19:43:13 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
2024-05-15 03:07:59 +00:00
|
|
|
raiseAssert "unsupported tx type"
|
2023-09-30 12:20:29 +00:00
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeTx(params: MakeTxParams, tc: BaseTx): PooledTransaction =
|
2023-09-30 12:20:29 +00:00
|
|
|
# Build the transaction depending on the specified type
|
2024-04-19 19:43:13 +00:00
|
|
|
let tx = makeTxOfType(params, tc)
|
2024-05-15 03:07:59 +00:00
|
|
|
PooledTransaction(
|
2024-10-04 14:34:31 +00:00
|
|
|
tx: signTransaction(tx.tx, params.key),
|
2024-05-15 03:07:59 +00:00
|
|
|
networkPayload: tx.networkPayload)
|
2023-09-30 12:20:29 +00:00
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeTx(params: MakeTxParams, tc: BigInitcodeTx): PooledTransaction =
|
2023-09-30 12:20:29 +00:00
|
|
|
var tx = tc
|
|
|
|
if tx.payload.len == 0:
|
|
|
|
# Prepare initcode payload
|
|
|
|
if tx.initcode.len != 0:
|
|
|
|
doAssert(tx.initcode.len <= tx.initcodeLength, "invalid initcode (too big)")
|
|
|
|
tx.payload = tx.initcode
|
|
|
|
|
|
|
|
while tx.payload.len < tx.initcodeLength:
|
|
|
|
tx.payload.add tx.padByte
|
|
|
|
|
|
|
|
doAssert(tx.recipient.isNone, "invalid configuration for big contract tx creator")
|
|
|
|
params.makeTx(tx.BaseTx)
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeTx*(
|
|
|
|
sender: TxSender, tc: BaseTx, nonce: AccountNonce): PooledTransaction =
|
2023-09-30 12:20:29 +00:00
|
|
|
let acc = sender.getNextAccount()
|
|
|
|
let params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-09-30 12:20:29 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: nonce
|
|
|
|
)
|
|
|
|
params.makeTx(tc)
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeTx*(
|
|
|
|
sender: TxSender,
|
|
|
|
tc: BigInitcodeTx,
|
|
|
|
nonce: AccountNonce): PooledTransaction =
|
2023-09-30 12:20:29 +00:00
|
|
|
let acc = sender.getNextAccount()
|
|
|
|
let params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-09-30 12:20:29 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: nonce
|
|
|
|
)
|
|
|
|
params.makeTx(tc)
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeNextTx*(sender: TxSender, tc: BaseTx): PooledTransaction =
|
2023-09-30 12:20:29 +00:00
|
|
|
let
|
|
|
|
acc = sender.getNextAccount()
|
|
|
|
nonce = sender.getNextNonce(acc.address)
|
|
|
|
params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-09-30 12:20:29 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: nonce
|
|
|
|
)
|
|
|
|
params.makeTx(tc)
|
|
|
|
|
|
|
|
proc sendNextTx*(sender: TxSender, client: RpcClient, tc: BaseTx): bool =
|
|
|
|
let tx = sender.makeNextTx(tc)
|
|
|
|
let rr = client.sendTransaction(tx)
|
|
|
|
if rr.isErr:
|
2023-10-31 03:18:37 +00:00
|
|
|
error "sendNextTx: Unable to send transaction", msg=rr.error
|
2023-09-30 12:20:29 +00:00
|
|
|
return false
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
inc sender.txSent
|
2023-09-30 12:20:29 +00:00
|
|
|
return true
|
|
|
|
|
|
|
|
proc sendTx*(sender: TxSender, client: RpcClient, tc: BaseTx, nonce: AccountNonce): bool =
|
|
|
|
let
|
|
|
|
acc = sender.getNextAccount()
|
|
|
|
params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-09-30 12:20:29 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: nonce
|
|
|
|
)
|
|
|
|
tx = params.makeTx(tc)
|
|
|
|
|
|
|
|
let rr = client.sendTransaction(tx)
|
|
|
|
if rr.isErr:
|
2023-10-31 03:18:37 +00:00
|
|
|
error "sendTx: Unable to send transaction", msg=rr.error
|
2023-09-30 12:20:29 +00:00
|
|
|
return false
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
inc sender.txSent
|
2023-09-30 12:20:29 +00:00
|
|
|
return true
|
|
|
|
|
|
|
|
proc sendTx*(sender: TxSender, client: RpcClient, tc: BigInitcodeTx, nonce: AccountNonce): bool =
|
|
|
|
let
|
|
|
|
acc = sender.getNextAccount()
|
|
|
|
params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-09-30 12:20:29 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: nonce
|
|
|
|
)
|
|
|
|
tx = params.makeTx(tc)
|
|
|
|
|
|
|
|
let rr = client.sendTransaction(tx)
|
|
|
|
if rr.isErr:
|
|
|
|
error "Unable to send transaction", msg=rr.error
|
|
|
|
return false
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
inc sender.txSent
|
2023-09-30 12:20:29 +00:00
|
|
|
return true
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc sendTx*(client: RpcClient, tx: PooledTransaction): bool =
|
2023-09-30 12:20:29 +00:00
|
|
|
let rr = client.sendTransaction(tx)
|
|
|
|
if rr.isErr:
|
|
|
|
error "Unable to send transaction", msg=rr.error
|
|
|
|
return false
|
|
|
|
return true
|
2023-10-19 03:28:52 +00:00
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeTx*(params: MakeTxParams, tc: BlobTx): PooledTransaction =
|
2023-10-19 03:28:52 +00:00
|
|
|
# Need tx wrap data that will pass blob verification
|
|
|
|
let data = blobDataGenerator(tc.blobID, tc.blobCount)
|
|
|
|
doAssert(tc.recipient.isSome, "nil recipient address")
|
|
|
|
|
|
|
|
let
|
|
|
|
gasFeeCap = if tc.gasFee != 0.GasInt: tc.gasFee
|
|
|
|
else: gasPrice
|
|
|
|
gasTipCap = if tc.gasTip != 0.GasInt: tc.gasTip
|
|
|
|
else: gasTipPrice
|
|
|
|
|
2024-04-19 19:43:13 +00:00
|
|
|
# Collect fields for transaction
|
2023-10-19 03:28:52 +00:00
|
|
|
let unsignedTx = Transaction(
|
2023-10-22 07:05:20 +00:00
|
|
|
txType : TxEip4844,
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId : params.chainId,
|
2023-10-19 03:28:52 +00:00
|
|
|
nonce : params.nonce,
|
2024-06-14 07:31:08 +00:00
|
|
|
maxPriorityFeePerGas: gasTipCap,
|
|
|
|
maxFeePerGas: gasFeeCap,
|
2023-10-19 03:28:52 +00:00
|
|
|
gasLimit : tc.gasLimit,
|
|
|
|
to : tc.recipient,
|
|
|
|
value : tc.amount,
|
|
|
|
payload : tc.payload,
|
|
|
|
maxFeePerBlobGas: tc.blobGasFee,
|
|
|
|
versionedHashes: data.hashes,
|
|
|
|
)
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
PooledTransaction(
|
2024-10-04 14:34:31 +00:00
|
|
|
tx: signTransaction(unsignedTx, params.key),
|
2024-05-15 03:07:59 +00:00
|
|
|
networkPayload: NetworkPayload(
|
2024-06-14 14:41:59 +00:00
|
|
|
blobs : data.blobs.mapIt(it.bytes),
|
2024-10-06 10:11:44 +00:00
|
|
|
commitments: data.commitments.mapIt(KzgCommitment it.bytes),
|
|
|
|
proofs : data.proofs.mapIt(KzgProof it.bytes),
|
2024-05-15 03:07:59 +00:00
|
|
|
),
|
2023-10-19 03:28:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
proc getAccount*(sender: TxSender, idx: int): TestAccount =
|
|
|
|
sender.accounts[idx]
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc sendTx*(
|
|
|
|
sender: TxSender,
|
|
|
|
acc: TestAccount,
|
|
|
|
client: RpcClient,
|
|
|
|
tc: BlobTx): Result[PooledTransaction, void] =
|
2023-10-19 03:28:52 +00:00
|
|
|
let
|
|
|
|
params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-10-19 03:28:52 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: sender.getNextNonce(acc.address),
|
|
|
|
)
|
|
|
|
tx = params.makeTx(tc)
|
|
|
|
|
|
|
|
let rr = client.sendTransaction(tx)
|
|
|
|
if rr.isErr:
|
|
|
|
error "Unable to send transaction", msg=rr.error
|
|
|
|
return err()
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
inc sender.txSent
|
2023-10-19 03:28:52 +00:00
|
|
|
return ok(tx)
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc replaceTx*(
|
|
|
|
sender: TxSender,
|
|
|
|
acc: TestAccount,
|
|
|
|
client: RpcClient,
|
|
|
|
tc: BlobTx): Result[PooledTransaction, void] =
|
2023-10-19 03:28:52 +00:00
|
|
|
let
|
|
|
|
params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-10-19 03:28:52 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: sender.getLastNonce(acc.address),
|
|
|
|
)
|
|
|
|
tx = params.makeTx(tc)
|
|
|
|
|
|
|
|
let rr = client.sendTransaction(tx)
|
|
|
|
if rr.isErr:
|
|
|
|
error "Unable to send transaction", msg=rr.error
|
|
|
|
return err()
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
inc sender.txSent
|
2023-10-19 03:28:52 +00:00
|
|
|
return ok(tx)
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc makeTx*(
|
|
|
|
sender: TxSender,
|
|
|
|
tc: BaseTx,
|
|
|
|
acc: TestAccount,
|
|
|
|
nonce: AccountNonce): PooledTransaction =
|
2023-10-31 03:18:37 +00:00
|
|
|
let
|
|
|
|
params = MakeTxParams(
|
2024-03-20 07:35:38 +00:00
|
|
|
chainId: sender.chainId,
|
2023-10-31 03:18:37 +00:00
|
|
|
key: acc.key,
|
|
|
|
nonce: nonce,
|
|
|
|
)
|
|
|
|
params.makeTx(tc)
|
|
|
|
|
|
|
|
proc customizeTransaction*(sender: TxSender,
|
|
|
|
acc: TestAccount,
|
|
|
|
baseTx: Transaction,
|
|
|
|
custTx: CustomTransactionData): Transaction =
|
|
|
|
# Create a modified transaction base, from the base transaction and custTx mix
|
|
|
|
var modTx = baseTx
|
|
|
|
if custTx.nonce.isSome:
|
|
|
|
modTx.nonce = custTx.nonce.get.AccountNonce
|
|
|
|
|
|
|
|
if custTx.gasPriceOrGasFeeCap.isSome:
|
|
|
|
modTx.gasPrice = custTx.gasPriceOrGasFeeCap.get.GasInt
|
|
|
|
|
|
|
|
if custTx.gas.isSome:
|
|
|
|
modTx.gasLimit = custTx.gas.get.GasInt
|
|
|
|
|
|
|
|
if custTx.to.isSome:
|
|
|
|
modTx.to = custTx.to
|
|
|
|
|
|
|
|
if custTx.value.isSome:
|
|
|
|
modTx.value = custTx.value.get
|
|
|
|
|
|
|
|
if custTx.data.isSome:
|
|
|
|
modTx.payload = custTx.data.get
|
|
|
|
|
2024-10-04 14:34:31 +00:00
|
|
|
if custTx.chainId.isSome:
|
|
|
|
modTx.chainId = custTx.chainId.get
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
if baseTx.txType in {TxEip1559, TxEip4844}:
|
|
|
|
if custTx.gasPriceOrGasFeeCap.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
modTx.maxFeePErGas = custTx.gasPriceOrGasFeeCap.get.GasInt
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
if custTx.gasTipCap.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
modTx.maxPriorityFeePerGas = custTx.gasTipCap.get.GasInt
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
if baseTx.txType == TxEip4844:
|
|
|
|
if modTx.to.isNone:
|
|
|
|
var address: EthAddress
|
2024-06-14 07:31:08 +00:00
|
|
|
modTx.to = Opt.some(address)
|
2023-10-31 03:18:37 +00:00
|
|
|
|
2024-10-04 14:34:31 +00:00
|
|
|
if custTx.signature.isSome:
|
|
|
|
let signature = custTx.signature.get
|
|
|
|
modTx.V = signature.V
|
|
|
|
modTx.R = signature.R
|
|
|
|
modTx.S = signature.S
|
|
|
|
else:
|
|
|
|
modTx.signature = modTx.sign(acc.key, eip155 = true)
|
2023-10-31 03:18:37 +00:00
|
|
|
|
2024-10-04 14:34:31 +00:00
|
|
|
modTx
|