parseArguments static method

List<AptosEntryFunctionArguments> parseArguments({
  1. required AptosApiMoveFunction function,
  2. required List<Object?> values,
  3. List<AptosTypeTag> genericTypeArgs = const [],
})

Parses the provided dynamic values into a list of AptosEntryFunctionArguments that match the expected argument types of the given function.

  • function: The Aptos Move function definition containing metadata about expected argument types.
  • values: The actual argument values to be parsed and converted.
  • genericTypeArgs: Optional list of generic type arguments (type tags) to handle generic Move functions.

Returns a list of AptosEntryFunctionArguments ready for transaction execution.

Implementation

static List<AptosEntryFunctionArguments> parseArguments(
    {required AptosApiMoveFunction function,
    required List<Object?> values,
    List<AptosTypeTag> genericTypeArgs = const []}) {
  int signerIndex =
      function.params.indexWhere((e) => e != "&signer" && e != "signer");
  List<String> paramsString = function.params;
  if (signerIndex >= 0) {
    paramsString = paramsString.sublist(signerIndex);
  }
  final tags = paramsString
      .map((e) => AptosFunctionEntryArgumentUtils.parseTag(e))
      .toList();
  if (tags.length != values.length) {
    throw DartAptosPluginException(
        "Mismatch between parameters and values: expected ${tags.length} parameters, but got ${values.length} values.");
  }

  return List.generate(tags.length, (index) {
    final type = tags[index];
    final value = values[index];
    try {
      return type.toEntryFunctionArguments(
          value: value, genericTypeArgs: genericTypeArgs);
    } catch (e) {
      throw DartAptosPluginException(
          "Parsing argument failed at index $index.",
          details: {"message": e.toString(), "type": type, "value": value});
    }
  });
}