diff --git a/src/api/transactionSubmission/build.ts b/src/api/transactionSubmission/build.ts index 68a67b1dd..af7fc6799 100644 --- a/src/api/transactionSubmission/build.ts +++ b/src/api/transactionSubmission/build.ts @@ -132,7 +132,7 @@ export class Build { * builder: builder: async (builder) => { * const coin = await builder.addBatchedCalls({ * function: "0x1::coin::withdraw", - * functionArguments: [callArgument.new_signer(0), 1], + * functionArguments: [CallArgument.new_signer(0), 1], * typeArguments: ["0x1::aptos_coin::AptosCoin"], * }); * diff --git a/src/transactions/scriptComposer/index.ts b/src/transactions/scriptComposer/index.ts index b305f333b..b2fe08c90 100644 --- a/src/transactions/scriptComposer/index.ts +++ b/src/transactions/scriptComposer/index.ts @@ -5,8 +5,8 @@ import { AptosApiType } from "../../utils"; import { AptosConfig } from "../../api/aptosConfig"; import { InputBatchedFunctionData } from "../types"; import { fetchMoveFunctionAbi, getFunctionParts, standardizeTypeTags } from "../transactionBuilder"; -import { callArgument } from "../../types"; -import { convertcallArgument } from "../transactionBuilder/remoteAbi"; +import { CallArgument } from "../../types"; +import { convertCallArgument } from "../transactionBuilder/remoteAbi"; // A wrapper class around TransactionComposer, which is a WASM library compiled // from aptos-core/aptos-move/script-composer. @@ -15,7 +15,7 @@ import { convertcallArgument } from "../transactionBuilder/remoteAbi"; // and allow for arguments to be passed around. export class AptosScriptComposer { private config: AptosConfig; - + private builder?: any; private static transactionComposer?: any; @@ -31,20 +31,20 @@ export class AptosScriptComposer { if (!AptosScriptComposer.transactionComposer) { const module = await import("@aptos-labs/script-composer-pack"); const { TransactionComposer, initSync, wasm } = module; - initSync({module: wasm}); + initSync({ module: wasm }); AptosScriptComposer.transactionComposer = TransactionComposer; } this.builder = AptosScriptComposer.transactionComposer.single_signer(); } - + // Add a move function invocation to the TransactionComposer. // // Similar to how to create an entry function, the difference is that input arguments could - // either be a `callArgument` which represents an abstract value returned from a previous Move call + // either be a `CallArgument` which represents an abstract value returned from a previous Move call // or the regular entry function arguments. // - // The function would also return a list of `callArgument` that can be passed on to future calls. - async addBatchedCalls(input: InputBatchedFunctionData): Promise<callArgument[]> { + // The function would also return a list of `CallArgument` that can be passed on to future calls. + async addBatchedCalls(input: InputBatchedFunctionData): Promise<CallArgument[]> { const { moduleAddress, moduleName, functionName } = getFunctionParts(input.function); const nodeUrl = this.config.getRequestUrl(AptosApiType.FULLNODE); @@ -64,8 +64,8 @@ export class AptosScriptComposer { ); } - const functionArguments: callArgument[] = input.functionArguments.map((arg, i) => - convertcallArgument(arg, functionName, functionAbi, i, typeArguments), + const functionArguments: CallArgument[] = input.functionArguments.map((arg, i) => + convertCallArgument(arg, functionName, functionAbi, i, typeArguments), ); return this.builder.add_batched_call( diff --git a/src/transactions/transactionBuilder/remoteAbi.ts b/src/transactions/transactionBuilder/remoteAbi.ts index 2c9fdd8fb..bb067c961 100644 --- a/src/transactions/transactionBuilder/remoteAbi.ts +++ b/src/transactions/transactionBuilder/remoteAbi.ts @@ -45,7 +45,7 @@ import { throwTypeMismatch, convertNumber, } from "./helpers"; -import { callArgument, MoveFunction } from "../../types"; +import { CallArgument, MoveFunction } from "../../types"; const TEXT_ENCODER = new TextEncoder(); @@ -220,27 +220,27 @@ export async function fetchViewFunctionAbi( } /** - * Converts a entry function argument into callArgument, if necessary. + * Converts a entry function argument into CallArgument, if necessary. * This function checks the provided argument against the expected parameter type and converts it accordingly. * * @param functionName - The name of the function for which the argument is being converted. * @param functionAbi - The ABI (Application Binary Interface) of the function, which defines its parameters. * @param argument - The argument to be converted, which can be of various types. If the argument is already - * callArgument returned from TransactionComposer it would be returned immediately. + * CallArgument returned from TransactionComposer it would be returned immediately. * @param position - The index of the argument in the function's parameter list. * @param genericTypeParams - An array of type tags for any generic type parameters. */ -export function convertcallArgument( - argument: callArgument | EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes, +export function convertCallArgument( + argument: CallArgument | EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes, functionName: string, functionAbi: FunctionABI, position: number, genericTypeParams: Array<TypeTag>, -): callArgument { - if (argument instanceof callArgument) { +): CallArgument { + if (argument instanceof CallArgument) { return argument; } - return callArgument.new_bytes( + return CallArgument.new_bytes( convertArgument(functionName, functionAbi, argument, position, genericTypeParams).bcsToBytes(), ); } diff --git a/src/transactions/types.ts b/src/transactions/types.ts index 226f953b2..947528e66 100644 --- a/src/transactions/types.ts +++ b/src/transactions/types.ts @@ -1,7 +1,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -import { CallArgument as callArgument } from "@aptos-labs/script-composer-pack"; +import { CallArgument } from "@aptos-labs/script-composer-pack"; import { AptosConfig } from "../api/aptosConfig"; import { MoveOption, MoveString, MoveVector } from "../bcs/serializable/moveStructs"; import { Bool, U128, U16, U256, U32, U64, U8 } from "../bcs/serializable/movePrimitives"; @@ -200,7 +200,7 @@ export type InputEntryFunctionDataWithRemoteABI = InputEntryFunctionData & { apt export type InputBatchedFunctionData = { function: MoveFunctionId; typeArguments?: Array<TypeArgument>; - functionArguments: Array<EntryFunctionArgumentTypes | callArgument | SimpleEntryFunctionArgumentTypes>; + functionArguments: Array<EntryFunctionArgumentTypes | CallArgument | SimpleEntryFunctionArgumentTypes>; }; /** diff --git a/src/types/index.ts b/src/types/index.ts index e19c36d5d..fc4f15dc2 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,3 @@ export * from "./indexer"; export * from "./types"; -export { CallArgument as callArgument } from "@aptos-labs/script-composer-pack"; +export { CallArgument } from "@aptos-labs/script-composer-pack"; diff --git a/tests/e2e/transaction/transactionSubmission.test.ts b/tests/e2e/transaction/transactionSubmission.test.ts index 079b1ed7c..3fbbda9e3 100644 --- a/tests/e2e/transaction/transactionSubmission.test.ts +++ b/tests/e2e/transaction/transactionSubmission.test.ts @@ -12,7 +12,7 @@ import { TransactionPayloadEntryFunction, Bool, MoveString, - callArgument, + CallArgument, } from "../../../src"; import { MAX_U64_BIG_INT } from "../../../src/bcs/consts"; import { longTestTimeout } from "../../unit/helper"; @@ -64,16 +64,15 @@ describe("transaction submission", () => { expect(response.signature?.type).toBe("single_sender"); }); test("simple batch payload", async () => { - const transaction = await aptos.transaction.build.scriptComposer({ sender: singleSignerED25519SenderAccount.accountAddress, - builder: async(builder) => { + builder: async (builder) => { await builder.addBatchedCalls({ function: `${contractPublisherAccount.accountAddress}::transfer::transfer`, - functionArguments: [callArgument.new_signer(0), 1, receiverAccounts[0].accountAddress], + functionArguments: [CallArgument.new_signer(0), 1, receiverAccounts[0].accountAddress], }); return builder; - } + }, }); const response = await aptos.signAndSubmitTransaction({ @@ -93,7 +92,7 @@ describe("transaction submission", () => { builder: async (builder) => { const coin = await builder.addBatchedCalls({ function: "0x1::coin::withdraw", - functionArguments: [callArgument.new_signer(0), 1], + functionArguments: [CallArgument.new_signer(0), 1], typeArguments: ["0x1::aptos_coin::AptosCoin"], }); @@ -234,7 +233,7 @@ describe("transaction submission", () => { builder: async (builder) => { const coin = await builder.addBatchedCalls({ function: "0x1::coin::withdraw", - functionArguments: [callArgument.new_signer(0), 1], + functionArguments: [CallArgument.new_signer(0), 1], typeArguments: ["0x1::aptos_coin::AptosCoin"], });