EtherscanTransaction.fromJsonErc721 constructor

EtherscanTransaction.fromJsonErc721(
  1. Json json, {
  2. required EvmCoinEntity currency,
  3. required String address,
})

Implementation

factory EtherscanTransaction.fromJsonErc721(
  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,
        'gas': String gas_s,
        'gasUsed': String gasUsed_s,
        'gasPrice': String gasPrice_s,
        'contractAddress': String contractAddress,
        'tokenID': String tokenID_s,
        'tokenName': String name,
        'tokenSymbol': String symbol,
        'tokenDecimal': String _,
      }) {
    final block = block_s.toIntOrNull ?? -1;
    final confirmations = block_s.toIntOrNull ?? -1;

    final timeMilli = timeStamp_s.toIntOrNull ?? -1;

    final tokenId = BigInt.tryParse(tokenID_s) ?? BigInt.from(-1);
    final token = ERC721Entity(
      name: name,
      symbol: symbol,
      contractAddress: contractAddress,
      chainID: currency.chainID,
      tokenId: tokenId,
    );

    final amount = Amount(
      value: BigInt.zero,
      decimals: 0,
    );

    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,
      sender: from,
      gasPrice: gasPrice,
      gas: gas_s.toInt,
      gasUsed: gasUsed_s.toInt,
      recipient: to,
      transferMethod: transferMethod,
      token: token,
      status: ConfirmationStatus.fromConfirmations(confirmations),
      input: Uint8List(0),
    );
  }
  throw UnsupportedError("Invalid JSON for EtherscanTransaction");
}