checkOrConvertArgument function
Checks if the provided argument is BCS encoded and converts it if necessary, ensuring type compatibility with the ABI. This is the synchronous version that works offline with pre-fetched ABIs. Does NOT support plain-object struct/enum arguments - use checkOrConvertArgumentWithABI for those.
Implementation
EntryFunctionArgument checkOrConvertArgument(
Object? arg,
TypeTag param,
int position,
List<TypeTag> genericTypeParams, {
MoveModule? moduleAbi,
bool allowUnknownStructs = false,
}) {
// If the argument is bcs encoded, we can just use it directly.
if (isEncodedEntryFunctionArgument(arg)) {
// If the expected type is Option but the arg is not already a
// MoveOption, wrap it after validating it matches the Option's inner
// type. This handles cases like Vector<Option<address>> where elements
// may be passed as AccountAddress instead of MoveOption<AccountAddress>.
if (param is TypeTagStruct && param.isOption() && arg is! MoveOption) {
return MoveOption<Serializable>(
checkOrConvertArgument(
arg,
param.value.typeArgs[0],
position,
genericTypeParams,
moduleAbi: moduleAbi,
allowUnknownStructs: allowUnknownStructs,
) as Serializable,
);
}
// Ensure the type matches the ABI.
_checkType(param, arg, position);
return arg as EntryFunctionArgument;
}
// If it is not BCS encoded, we will need to convert it with the ABI.
return _parseArgSync(
arg,
param,
position,
genericTypeParams,
moduleAbi: moduleAbi,
allowUnknownStructs: allowUnknownStructs,
);
}