fetchEpochData function

Future<BeaconState> fetchEpochData(
  1. DeployedContract contract,
  2. Web3Client client, [
  3. int epochId = 0
])

Implementation

Future<BeaconState> fetchEpochData(DeployedContract contract, Web3Client client,
    [int epochId = 0]) async {
  final function = contract.function('fetchEpoch');
  final response = await client.call(
    contract: contract,
    function: function,
    params: [BigInt.from(epochId)],
  );

  if (response[0] == null) {
    logger.info('Invalid epoch ID: $epochId');
    throw Exception('Invalid epoch ID: $epochId');
  }

  final data = response[0];

  final epoch = data[0];
  final witnessesData = data[3];
  final witnessesRequiredForClaim = data[4];
  final nextEpochTimestampS = data[2];

  List<WitnessData> witnesses = witnessesData.map<WitnessData>((w) {
    return WitnessData(
      id: w[0]!.toString(),
      url: w[1]!,
    );
  }).toList();

  return BeaconState(
    epoch: epoch.toInt(),
    witnesses: witnesses,
    witnessesRequiredForClaim: witnessesRequiredForClaim.toInt(),
    nextEpochTimestampS: nextEpochTimestampS.toInt(),
  );
}