balance method
Reads canonical and calculated balances at the same block reference.
Implementation
Future<CustomUnitBalance> balance(
XCBAddress account, {
String? unit,
BlockNum? atBlock,
}) async {
final resolvedUnit =
unit?.trim().isNotEmpty == true
? unit!.trim()
: await preferredUnit(atBlock: atBlock);
if (resolvedUnit.isEmpty) {
throw StateError('The token contract did not provide a preferred unit');
}
final values = await Future.wait<BigInt>([
canonicalBalance(account, atBlock: atBlock),
balanceOfUnit(account, resolvedUnit, atBlock: atBlock),
]);
return CustomUnitBalance(
canonicalAmount: values[0],
unitAmount: values[1],
unit: resolvedUnit,
);
}