status-lib/status/transactions.nim

20 lines
733 B
Nim
Raw Permalink Normal View History

2021-09-08 18:05:39 +00:00
import
options, strutils
import
stint, web3/ethtypes
from utils as status_utils import toUInt64, gwei2Wei, parseAddress
proc buildTransaction*(source: Address, value: Uint256, gas = "", gasPrice = "", data = ""): EthSend =
result = EthSend(
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
)
proc buildTokenTransaction*(source, contractAddress: Address, gas = "", gasPrice = ""): EthSend =
result = buildTransaction(source, 0.u256, gas, gasPrice)
result.to = contractAddress.some