XCBAmount.fromUnitAndValue constructor
XCBAmount.fromUnitAndValue(
- XCBUnit unit,
- dynamic amount
Constructs an amount of Core by a unit and its amount. amount can
either be a base10 string, an int, or a BigInt.
Implementation
factory XCBAmount.fromUnitAndValue(XCBUnit unit, dynamic amount) {
BigInt parsedAmount;
if (amount is BigInt) {
parsedAmount = amount;
} else if (amount is int) {
parsedAmount = BigInt.from(amount);
} else if (amount is String) {
parsedAmount = BigInt.parse(amount);
} else {
throw ArgumentError('Invalid type, must be BigInt, string or int');
}
return XCBAmount.inOre(parsedAmount * _factors[unit]!);
}