argToTransactionArgument function
Implementation
TransactionArgument argToTransactionArgument(dynamic argVal, TypeTag argType) {
if (argType is TypeTagBool) {
return TransactionArgumentBool(ensureBoolean(argVal));
}
if (argType is TypeTagU8) {
return TransactionArgumentU8(ensureNumber(argVal));
}
if (argType is TypeTagU16) {
return TransactionArgumentU16(ensureNumber(argVal));
}
if (argType is TypeTagU32) {
return TransactionArgumentU32(ensureNumber(argVal));
}
if (argType is TypeTagU64) {
return TransactionArgumentU64(ensureBigInt(argVal));
}
if (argType is TypeTagU128) {
return TransactionArgumentU128(ensureBigInt(argVal));
}
if (argType is TypeTagU256) {
return TransactionArgumentU256(ensureBigInt(argVal));
}
if (argType is TypeTagAddress) {
AccountAddress addr;
if (argVal is String || argVal is HexString) {
addr = AccountAddress.fromHex(argVal);
} else if (argVal is AccountAddress) {
addr = argVal;
} else {
throw ArgumentError("Invalid account address.");
}
return TransactionArgumentAddress(addr);
}
if (argType is TypeTagVector && argType.value is TypeTagU8) {
if (argVal is! Iterable<int>) {
throw ArgumentError("$argVal should be an instance of Uint8Array");
}
return TransactionArgumentU8Vector(Uint8List.fromList(argVal.toList()));
}
throw ArgumentError("Unknown type for TransactionArgument.");
}