Skip to content

Commit

Permalink
Introduce a buildPublishPayload function (#466)
Browse files Browse the repository at this point in the history
introduce buildPublishPayload function
  • Loading branch information
0xmaayan authored Jul 16, 2024
1 parent e136049 commit 09b3671
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T
# Unreleased

- Change the `stop()` function on `LocalNode` to return a `Promise` so we can wait for the processes to be killed
- Introduce `buildPublishPayload` CLI function to build a publication transaction payload and store it in a JSON output file

# 1.24.0 (2024-07-12)

Expand Down
27 changes: 13 additions & 14 deletions examples/typescript/local_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const cli = require("@aptos-labs/ts-sdk/dist/common/cli/index.js");

let localNode: any;
const move = new cli.Move();

// Run local node
async function runLocalNode() {
Expand All @@ -18,8 +19,6 @@ async function runLocalNode() {

// initialize current directory for Aptos
async function init() {
const move = new cli.Move();

await move.init({
network: "local",
profile: "default",
Expand All @@ -28,8 +27,6 @@ async function init() {

// compile a package
async function compile() {
const move = new cli.Move();

await move.compile({
packageDirectoryPath: "move/moonCoin",
namedAddresses: {
Expand All @@ -40,8 +37,6 @@ async function compile() {

// run Move unit tests for a package
async function tests() {
const move = new cli.Move();

await move.test({
packageDirectoryPath: "move/moonCoin",
namedAddresses: {
Expand All @@ -52,8 +47,6 @@ async function tests() {

// publish the Move package to the publisher's account
async function publish() {
const move = new cli.Move();

await move.publish({
packageDirectoryPath: "move/moonCoin",
namedAddresses: {
Expand All @@ -65,8 +58,6 @@ async function publish() {

// create a new object and publish a Move package to it
async function createObjectAndPublishPackage() {
const move = new cli.Move();

await move.createObjectAndPublishPackage({
packageDirectoryPath: "move/moonCoin",
addressName: "MoonCoin",
Expand All @@ -79,8 +70,6 @@ async function createObjectAndPublishPackage() {

// upgrade a Move packaged published to an object
async function upgradeObjectPackage() {
const move = new cli.Move();

await move.upgradeObjectPackage({
packageDirectoryPath: "move/moonCoin",
// please replace the address with the actual address of object that the package was published to
Expand All @@ -94,13 +83,22 @@ async function upgradeObjectPackage() {

// run a Move script
async function runScript() {
const move = new cli.Move();

await move.runScript({
compiledScriptPath: "move/moonCoin/build/MoonCoin/bytecode_scripts/register.mv",
});
}

// build a publication transaction payload and store it in a JSON output file
async function buildPublishPayload() {
await move.buildPublishPayload({
outputFile: "move/moonCoin/test-package.json",
packageDirectoryPath: "move/moonCoin",
namedAddresses: {
MoonCoin: "0x123",
},
});
}

// Stop local node
async function stopLocalNode() {
await localNode.stop();
Expand All @@ -123,6 +121,7 @@ async function run() {
await createObjectAndPublishPackage();
await upgradeObjectPackage();
await runScript();
await buildPublishPayload();

// stop the localnet
await stopLocalNode();
Expand Down
36 changes: 36 additions & 0 deletions src/cli/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,42 @@ export class Move {
return this.runCommand(cliArgs);
}

/**
* Build a publication transaction payload and store it in a JSON output file
*
* @param args.packageDirectoryPath Path to a move package (the folder with a Move.toml file)
* @param args.outputFile Output file to write publication transaction to
* @param args.namedAddresses Named addresses for the move binary
* @example
* {
* alice:0x1234, bob:0x5678
* }
*
* @returns stdout
*/
async buildPublishPayload(args: {
packageDirectoryPath: string;
outputFile: string;
namedAddresses: Record<string, AccountAddress>;
}) {
const { outputFile, packageDirectoryPath, namedAddresses } = args;
const cliArgs = [
"aptos",
"move",
"build-publish-payload",
"--json-output-file",
outputFile,
"--package-dir",
packageDirectoryPath,
];

const addressesMap = this.parseNamedAddresses(namedAddresses);

cliArgs.push(...this.prepareNamedAddresses(addressesMap));

return this.runCommand(cliArgs);
}

/**
* Function to run a Move script, please run compile before running this
*
Expand Down

0 comments on commit 09b3671

Please sign in to comment.