Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a new api for building script payload #565

Merged
merged 9 commits into from
Nov 7, 2024

Conversation

runtian-zhou
Copy link
Contributor

@runtian-zhou runtian-zhou commented Nov 4, 2024

Description

Add a new scriptComposer api in the transactionSubmission api to allow for SDK callers to dynamically invoke multiple Move functions in one transaction and compose the call sequences arbitrarily.

Test Plan

New case added.

Related Links

https://github.com/runtian-zhou/AIPs/blob/ab7301a9ccfa5447661256539bab8d9338048dee/aips/aip-102.md

Checklist

  • Have you ran pnpm fmt?
  • Have you updated the CHANGELOG.md?

expect(response.signature?.type).toBe("single_sender");
});
test.only("with batch withdraw payload", async () => {
let _aptos = getAptosClient({ network: Network.CUSTOM ,fullnode : "http://127.0.0.1:8080/v1",faucet: "http://127.0.0.1:8081",indexer: "http://127.0.0.1:8090"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let _aptos = getAptosClient({ network: Network.CUSTOM ,fullnode : "http://127.0.0.1:8080/v1",faucet: "http://127.0.0.1:8081",indexer: "http://127.0.0.1:8090"})
let _aptos = getAptosClient({ network: Network.LOCAL })

@runtian-zhou runtian-zhou force-pushed the runtianz/intent_sdk branch 4 times, most recently from 8609dc9 to bef04fa Compare November 5, 2024 07:20
Copy link
Collaborator

@0xmaayan 0xmaayan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a first review -

  1. Please update the PR description with details on what the PR is for, etc
  2. Throughout the SDK we use lowerCamelCase syntax, please use it when feasible
  3. I'd like us to find a better name than transaction.build.scriptComposer, something resemble to transaction.build.simple or transaction.build.multiAgent

src/api/transactionSubmission/build.ts Outdated Show resolved Hide resolved
withFeePayer?: boolean;
}): Promise<SimpleTransaction> {
let builder = new AptosScriptComposer(this.config);
builder = await args.builder(builder);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we assign on line 110 and then reassign on line 111?

src/api/transactionSubmission/build.ts Outdated Show resolved Hide resolved
wasm = initSync(await create_wasm());
})();

function convert_batch_argument(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should live in ../transactionBuilder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should live here? Because it's a helper function only used in this module?

src/transactions/script-composer/index.ts Show resolved Hide resolved
src/transactions/transactionBuilder/remoteAbi.ts Outdated Show resolved Hide resolved
tests/e2e/transaction/transactionSubmission.test.ts Outdated Show resolved Hide resolved
@@ -93,6 +101,23 @@ export class Build {
return generateTransaction({ aptosConfig: this.config, ...args });
}

async script_composer(args: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we find a more meaningful name than scriptComposer? imo, when developers do aptos.transaction.build.scriptComposer it is not that meaningful like aptos.transaction.build.simple/multiAgent

Suggested change
async script_composer(args: {
async scriptComposer(args: {

@@ -61,6 +67,67 @@ describe("transaction submission", () => {

expect(response.signature?.type).toBe("single_sender");
});
test("with batch payload", async () => {
let _aptos = getAptosClient({ network: Network.CUSTOM ,fullnode : "http://127.0.0.1:8080/v1",faucet: "http://127.0.0.1:8081",indexer: "http://127.0.0.1:8090"})
const builder = new AptosScriptComposer(_aptos.config);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the same transaction flow as in this file (and in the other test you have here) with aptos.transaction.build.script_composer
https://github.com/aptos-labs/aptos-ts-sdk/pull/565/files#diff-f1a843f6e05220a54a794964cbcb789ee9cfd6671ef77518e3a4a75d891f30d7R52-R66

Copy link
Collaborator

@0xmaayan 0xmaayan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please update CHANGELOG
  2. This feature needs to live in a section on aptos.dev also

tests/e2e/transaction/transactionSubmission.test.ts Outdated Show resolved Hide resolved
@runtian-zhou
Copy link
Contributor Author

Docs added in aptos-labs/developer-docs#696

@runtian-zhou runtian-zhou marked this pull request as ready for review November 5, 2024 23:33
@runtian-zhou runtian-zhou requested a review from a team as a code owner November 5, 2024 23:33
src/transactions/script-composer/index.ts Outdated Show resolved Hide resolved
tests/e2e/transaction/transactionSubmission.test.ts Outdated Show resolved Hide resolved
await this.builder.load_type_tag(nodeUrl, typeTag.toString());
}
}
const typeArguments = standardizeTypeTags(input.typeArguments);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep the format same as the other transaction generation logic in the SDK and move the whole function generator part to the transactionBuilder.ts file and have it use the memoize logic - same as we do for any other payload https://github.com/aptos-labs/aptos-ts-sdk/blob/main/src/transactions/transactionBuilder/transactionBuilder.ts#L124

tests/e2e/transaction/transactionSubmission.test.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@0xmaayan 0xmaayan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. need to fix lint issue and tests

@runtian-zhou runtian-zhou enabled auto-merge (squash) November 7, 2024 19:25
@runtian-zhou runtian-zhou merged commit a301268 into main Nov 7, 2024
13 of 14 checks passed
@runtian-zhou runtian-zhou deleted the runtianz/intent_sdk branch November 7, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants