Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
runtian-zhou committed Nov 7, 2024
1 parent a4ddb15 commit 0632cff
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions src/transactions/script-composer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,12 @@ import {
import { convertArgument, fetchMoveFunctionAbi, getFunctionParts, standardizeTypeTags } from "../transactionBuilder";
import { TypeTag } from "../typeTag";
import { CallArgument } from "../../types";
import { convertCallArgument } from "../transactionBuilder/remoteAbi"

(async () => {
initSync(await create_wasm());
})();

function convertCallArgument(
argument: CallArgument | EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes,
functionName: string,
functionAbi: FunctionABI,
position: number,
genericTypeParams: Array<TypeTag>,
): CallArgument {
if (argument instanceof CallArgument) {
return argument;
}
return CallArgument.new_bytes(
convertArgument(functionName, functionAbi, argument, position, genericTypeParams).bcsToBytes(),
);

}

// A wrapper class around TransactionComposer, which is a WASM library compiled
// from aptos-core/aptos-move/script-composer.
//
Expand Down
29 changes: 28 additions & 1 deletion 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 { MoveFunction } from "../../types";
import { CallArgument, MoveFunction } from "../../types";

const TEXT_ENCODER = new TextEncoder();

Expand Down Expand Up @@ -211,6 +211,33 @@ export async function fetchViewFunctionAbi(
};
}

/**
* 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.
* @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,
functionName: string,
functionAbi: FunctionABI,
position: number,
genericTypeParams: Array<TypeTag>,
): CallArgument {
if (argument instanceof CallArgument) {
return argument;
}
return CallArgument.new_bytes(
convertArgument(functionName, functionAbi, argument, position, genericTypeParams).bcsToBytes(),
);

}

/**
* Converts a non-BCS encoded argument into BCS encoded, if necessary.
* This function checks the provided argument against the expected parameter type and converts it accordingly.
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/transaction/transactionSubmission.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

//import { CallArgument } from "@wgb5445/aptos-intent-npm";
import {
Account,
U64,
Expand Down Expand Up @@ -109,7 +108,6 @@ describe("transaction submission", () => {
await builder.addBatchedCalls({
function: "0x1::primary_fungible_store::deposit",
functionArguments: [singleSignerED25519SenderAccount.accountAddress, fungibleAsset[0]],
typeArguments: [],
});
return builder;
},
Expand Down

0 comments on commit 0632cff

Please sign in to comment.