findFirstNonSignerArg function

int findFirstNonSignerArg(
  1. MoveFunction functionAbi
)

Finds the index of the first non-signer argument in the function ABI parameters.

A function is often defined with signer or &signer arguments at the start, which are filled in by signatures and not by the caller. This function helps identify the position of the first argument that can be provided by the caller.

Implementation

int findFirstNonSignerArg(MoveFunction functionAbi) {
  final index = functionAbi.params
      .indexWhere((param) => param != 'signer' && param != '&signer');
  if (index < 0) {
    return functionAbi.params.length;
  }
  return index;
}