EtherscanTransaction.fromJsonErc20 constructor
Implementation
factory EtherscanTransaction.fromJsonErc20(
Json json, {
required EvmCoinEntity currency,
required String address,
}) {
if (json
case {
'blockNumber': String block_s,
'timeStamp': String timeStamp_s,
'hash': String hash,
'from': String from,
'to': String to,
'value': String value_s,
'gas': String gas_s,
'gasUsed': String gasUsed_s,
'gasPrice': String gasPrice_s,
'input': String input,
'contractAddress': String contractAddress,
'tokenDecimal': String decimals_s,
'tokenSymbol': String symbol,
'tokenName': String name,
}) {
final block = block_s.toIntOrNull ?? -1;
final confirmations = block_s.toIntOrNull ?? -1;
final timeMilli = timeStamp_s.toIntOrNull ?? -1;
final token = ERC20Entity(
name: name,
symbol: symbol,
decimals: decimals_s.toIntOrNull ?? 18,
contractAddress: contractAddress,
chainID: currency.chainID,
);
final amount = Amount(
value: BigInt.tryParse(value_s) ?? BigInt.from(-1),
decimals: token.decimals,
);
final fee = Amount(
value: gasPrice_s.toBigInt * gasUsed_s.toBigInt,
decimals: currency.decimals,
);
final gasPrice = Amount(
value: gasPrice_s.toBigInt,
decimals: currency.decimals,
);
final transferMethod =
TransactionTransferMethod.fromAddress(address, to, from);
return EtherscanTransaction(
hash: hash,
block: block,
confirmations: confirmations,
timeMilli: timeMilli * 1000,
amount: amount,
fee: fee,
gasUsed: gasUsed_s.toInt,
sender: from,
recipient: to,
gas: gas_s.toInt,
gasPrice: gasPrice,
transferMethod: transferMethod,
token: token,
status: ConfirmationStatus.fromConfirmations(confirmations),
input: input.hexToBytesWithPrefixOrNull ?? Uint8List(0),
);
}
throw UnsupportedError("Invalid JSON for EtherscanTransaction");
}