status-lib/status/transactions.nim

27 lines
1.3 KiB
Nim
Raw Normal View History

2021-09-08 18:05:39 +00:00
import
options, strutils
import
2021-09-10 17:27:49 +00:00
stint, web3/ethtypes, types/transaction
2021-09-08 18:05:39 +00:00
from utils as status_utils import toUInt64, gwei2Wei, parseAddress
2021-09-10 17:27:49 +00:00
proc buildTransaction*(source: Address, value: Uint256, gas = "", gasPrice = "", isEIP1559Enabled = false, maxPriorityFeePerGas = "", maxFeePerGas = "", data = ""): TransactionData =
result = TransactionData(
2021-09-08 18:05:39 +00:00
source: source,
value: value.some,
gas: (if gas.isEmptyOrWhitespace: Quantity.none else: Quantity(cast[uint64](parseFloat(gas).toUInt64)).some),
gasPrice: (if gasPrice.isEmptyOrWhitespace: int.none else: gwei2Wei(parseFloat(gasPrice)).truncate(int).some),
data: data
)
2021-09-10 17:27:49 +00:00
if isEIP1559Enabled:
result.txType = "0x02"
result.maxPriorityFeePerGas = if maxFeePerGas.isEmptyOrWhitespace: Uint256.none else: gwei2Wei(parseFloat(maxPriorityFeePerGas)).some
result.maxFeePerGas = (if maxFeePerGas.isEmptyOrWhitespace: Uint256.none else: gwei2Wei(parseFloat(maxFeePerGas)).some)
else:
result.txType = "0x00"
2021-09-08 18:05:39 +00:00
2021-09-10 17:27:49 +00:00
proc buildTokenTransaction*(source, contractAddress: Address, gas = "", gasPrice = "", isEIP1559Enabled = false, maxPriorityFeePerGas = "", maxFeePerGas = ""): TransactionData =
result = buildTransaction(source, 0.u256, gas, gasPrice, isEIP1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
result.to = contractAddress.some