diff --git a/src/api/account/abstraction.ts b/src/api/account/abstraction.ts index ac9a8aeb9..19847a9e7 100644 --- a/src/api/account/abstraction.ts +++ b/src/api/account/abstraction.ts @@ -5,8 +5,9 @@ import { removeDispatchableAuthenticatorTransaction, } from "../../internal/abstraction"; import { view } from "../../internal/view"; -import { getFunctionParts, InputGenerateTransactionOptions, TypeTagAddress } from "../../transactions"; +import { InputGenerateTransactionOptions, TypeTagAddress } from "../../transactions"; import { MoveFunctionId } from "../../types"; +import { getFunctionParts } from "../../utils/helpers"; import { AptosConfig } from "../aptosConfig"; export class AccountAbstraction { diff --git a/src/internal/abstraction.ts b/src/internal/abstraction.ts index b166c6913..66b494d53 100644 --- a/src/internal/abstraction.ts +++ b/src/internal/abstraction.ts @@ -4,12 +4,12 @@ import { TypeTagAddress, TypeTagStruct, stringStructTag, - getFunctionParts, } from "../transactions"; import { AccountAddressInput } from "../core"; import { generateTransaction } from "./transactionSubmission"; import { MoveFunctionId } from "../types"; import { AptosConfig } from "../api/aptosConfig"; +import { getFunctionParts } from "../utils/helpers"; export async function addDispatchableAuthenticationFunctionTransaction(args: { aptosConfig: AptosConfig; diff --git a/src/transactions/authenticator/account.ts b/src/transactions/authenticator/account.ts index 15299dfee..ba2f28a3b 100644 --- a/src/transactions/authenticator/account.ts +++ b/src/transactions/authenticator/account.ts @@ -11,7 +11,7 @@ import { MultiKey, MultiKeySignature } from "../../core/crypto/multiKey"; import { AccountAuthenticatorVariant, HexInput, MoveFunctionId } from "../../types"; import { AbstractionAuthDataVariant } from "../../types/abstraction"; import { AccountAddress, Hex } from "../../core"; -import { getFunctionParts, isValidFunctionInfo } from "../transactionBuilder/helpers"; +import { getFunctionParts, isValidFunctionInfo } from "../../utils/helpers"; /** * Represents an account authenticator that can handle multiple authentication variants. diff --git a/src/transactions/transactionBuilder/helpers.ts b/src/transactions/transactionBuilder/helpers.ts index 2388722da..6866f5df0 100644 --- a/src/transactions/transactionBuilder/helpers.ts +++ b/src/transactions/transactionBuilder/helpers.ts @@ -10,7 +10,7 @@ import { } from "../types"; import { Bool, FixedBytes, MoveOption, MoveString, MoveVector, U128, U16, U256, U32, U64, U8 } from "../../bcs"; import { AccountAddress } from "../../core"; -import { MoveFunction, MoveFunctionId } from "../../types"; +import { MoveFunction } from "../../types"; /** * Determines if the provided argument is of type boolean. @@ -317,29 +317,3 @@ export function findFirstNonSignerArg(functionAbi: MoveFunction): number { } return index; } - -/** - * Splits a function identifier into its constituent parts: module address, module name, and function name. - * This function helps in validating and extracting details from a function identifier string. - * - * @param functionArg - The function identifier string in the format "moduleAddress::moduleName::functionName". - * @returns An object containing the module address, module name, and function name. - * @throws Error if the function identifier does not contain exactly three parts. - * @group Implementation - * @category Transactions - */ -export function getFunctionParts(functionArg: MoveFunctionId) { - const funcNameParts = functionArg.split("::"); - if (funcNameParts.length !== 3) { - throw new Error(`Invalid function ${functionArg}`); - } - const moduleAddress = funcNameParts[0]; - const moduleName = funcNameParts[1]; - const functionName = funcNameParts[2]; - return { moduleAddress, moduleName, functionName }; -} - -export function isValidFunctionInfo(functionInfo: string): boolean { - const parts = functionInfo.split("::"); - return parts.length === 3 && AccountAddress.isValid({ input: parts[0] }).valid; -} diff --git a/src/transactions/transactionBuilder/transactionBuilder.ts b/src/transactions/transactionBuilder/transactionBuilder.ts index 5527302d2..ac0ea8488 100644 --- a/src/transactions/transactionBuilder/transactionBuilder.ts +++ b/src/transactions/transactionBuilder/transactionBuilder.ts @@ -77,9 +77,10 @@ import { } from "../types"; import { convertArgument, fetchEntryFunctionAbi, fetchViewFunctionAbi, standardizeTypeTags } from "./remoteAbi"; import { memoizeAsync } from "../../utils/memoize"; -import { getFunctionParts, isScriptDataInput } from "./helpers"; +import { isScriptDataInput } from "./helpers"; import { SimpleTransaction } from "../instances/simpleTransaction"; import { MultiAgentTransaction } from "../instances/multiAgentTransaction"; +import { getFunctionParts } from "../../utils/helpers"; /** * Builds a transaction payload based on the provided arguments and returns a transaction payload. diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index b012d777d..a48a8ae95 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -2,7 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { decode } from "js-base64"; -import { MoveStructId } from "../types"; +import { MoveFunctionId, MoveStructId } from "../types"; +import { AccountAddress } from "../core/accountAddress"; /** * Sleep for the specified amount of time in milliseconds. @@ -175,3 +176,29 @@ export const isEncodedStruct = ( typeof structObj.account_address === "string" && typeof structObj.module_name === "string" && typeof structObj.struct_name === "string"; + +/** + * Splits a function identifier into its constituent parts: module address, module name, and function name. + * This function helps in validating and extracting details from a function identifier string. + * + * @param functionArg - The function identifier string in the format "moduleAddress::moduleName::functionName". + * @returns An object containing the module address, module name, and function name. + * @throws Error if the function identifier does not contain exactly three parts. + * @group Implementation + * @category Transactions + */ +export function getFunctionParts(functionArg: MoveFunctionId) { + const funcNameParts = functionArg.split("::"); + if (funcNameParts.length !== 3) { + throw new Error(`Invalid function ${functionArg}`); + } + const moduleAddress = funcNameParts[0]; + const moduleName = funcNameParts[1]; + const functionName = funcNameParts[2]; + return { moduleAddress, moduleName, functionName }; +} + +export function isValidFunctionInfo(functionInfo: string): boolean { + const parts = functionInfo.split("::"); + return parts.length === 3 && AccountAddress.isValid({ input: parts[0] }).valid; +}