Skip to content

Commit

Permalink
fixup! fixup! Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
runtian-zhou committed Jan 31, 2025
1 parent 61d0ac5 commit 2d0c38b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/api/transactionSubmission/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
* });
*
Expand Down
20 changes: 10 additions & 10 deletions src/transactions/scriptComposer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions src/transactions/transactionBuilder/remoteAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
throwTypeMismatch,
convertNumber,
} from "./helpers";
import { callArgument, MoveFunction } from "../../types";
import { CallArgument, MoveFunction } from "../../types";

const TEXT_ENCODER = new TextEncoder();

Expand Down Expand Up @@ -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(),
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/transactions/types.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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>;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -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";
13 changes: 6 additions & 7 deletions tests/e2e/transaction/transactionSubmission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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({
Expand All @@ -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"],
});

Expand Down Expand Up @@ -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"],
});

Expand Down

0 comments on commit 2d0c38b

Please sign in to comment.