Skip to content

Commit

Permalink
Fix dependency cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostWalker562 committed Jan 28, 2025
1 parent 43412e7 commit 65d541a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/api/account/abstraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/abstraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/transactions/authenticator/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 1 addition & 27 deletions src/transactions/transactionBuilder/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion src/transactions/transactionBuilder/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 28 additions & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

0 comments on commit 65d541a

Please sign in to comment.