BlockDetails.fromJson constructor

BlockDetails.fromJson(
  1. Map<String, dynamic> json, {
  2. bool hydrated = true,
})

Implementation

factory BlockDetails.fromJson(Map<String, dynamic> json,
    {bool hydrated = true}) {
  final List<Withdrawal> withdrawals = (json['withdrawals'] as List<dynamic>?)
          ?.map((withdrawal) => Withdrawal.fromJson(withdrawal))
          .toList() ??
      <Withdrawal>[];
  final List<dynamic> transactions = json["transactions"];

  final transactionsInfo = hydrated
      ? transactions.map((e) => TransactionInfo.fromJson(e)).toList()
      : <TransactionInfo>[];
  final List<String> ids = hydrated
      ? transactionsInfo.map((e) => e.hash).toList()
      : transactions.cast();

  return BlockDetails(
    transactionIds: ids,
    transactions: transactionsInfo,
    baseFeePerGas: PluginBigintUtils.tryHexToBigint(json['baseFeePerGas']),
    difficulty: PluginIntUtils.hexToInt(json['difficulty']),
    extraData: json['extraData'],
    gasLimit: PluginBigintUtils.hexToBigint(json['gasLimit']),
    gasUsed: PluginBigintUtils.hexToBigint(json['gasUsed']),
    hash: json['hash'],
    logsBloom: json['logsBloom'],
    miner: json['miner'],
    mixHash: json['mixHash'],
    nonce: PluginIntUtils.tryHexToInt(json['nonce']),
    number: PluginIntUtils.hexToInt(json['number']),
    parentHash: json['parentHash'],
    receiptsRoot: json['receiptsRoot'],
    sha3Uncles: json['sha3Uncles'],
    size: PluginIntUtils.hexToInt(json['size']),
    stateRoot: json['stateRoot'],
    timestamp: json['timestamp'],
    totalDifficulty: json['totalDifficulty'],
    transactionsRoot: json['transactionsRoot'],
    uncles: json['uncles'] ?? [],
    withdrawals: withdrawals,
    withdrawalsRoot: json['withdrawalsRoot'],
  );
}