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

[ts-sdk] Update Instructions for using CLI to get compiled modules #4537

Merged
merged 1 commit into from
Sep 13, 2022

Conversation

666lcz
Copy link
Contributor

@666lcz 666lcz commented Sep 9, 2022

Today we provided a publish API in the TS SDK that requires the caller to pass in compiled modules in the right topological order. However, we did not provide any toolings on the TS side for developers to compute the correct topological ordering. We have evaluated a few options to solve this problem:

  • Write a TS library to parse Move module bytecode into structured format so we can do the topological sorting
  • Work on compiling key Sui/Move libraries to WASM so we can call them from TS Investigate porting Rust to WASM #2250
  • provide a TS util function that calls the sui client cli to get the compiled modules

We've agreed that the first two options have too much engineering overhead, and thus this PR takes the third approach by leveraging the existing sui move build --dump-bytecode-as-base64

Testing

In nodejs repl

> const {JsonRpcProvider, Ed25519Keypair, PublicKey, RawSigner} = require('@mysten/sui.js')
> const { execSync } = require('child_process');
> const signer = new RawSigner( keypair, new JsonRpcProvider("http://127.0.0.1:5001") );
> const cliPath = '/Users/cl/ml/fastnft/sui_programmability/examples/defi';
> const packagePath = ' '/Users/cl/ml/fastnft/target/debug/sui';
> const compiledModules = JSON.parse(execSync(`${cliPath} move build --dump-bytecode-as-base64 --path ${packagePath}`, { encoding: 'utf-8' }));
> const publishTxn = await signer.publish({compiledModules: modules, gasBudget: 10000 });

> publishTxn
{
  certificate: {
    transactionDigest: 'c0VTlivzvqgooNCUuvrMGxdMoU9p9YU6HPXtV953lGY=',
    data: {
      transactions: [Array],
      sender: '0x36096be6a0314052931babed39f53c0666a6b0df',
      gasPayment: [Object],
      gasBudget: 10000
    },
    txSignature: 'ACPqXrlGMkZD+EEMBRJViSfz2HyQ8iSW6B8OkS1xT5bnoe9rtKeVulRzJ9EMoUKmnbckcqr4Ek2yc9ZZ4zO8DQkrudsznMOIMh0hzeFTt3oOJ0djl2h/4OKjyozuHKXHqg==',
    authSignInfo: { epoch: 0, signature: [Array], signers_map: [Array] }
  },
  effects: {
    status: { status: 'success' },
    gasUsed: { computationCost: 1332, storageCost: 715, storageRebate: 16 },
    transactionDigest: 'c0VTlivzvqgooNCUuvrMGxdMoU9p9YU6HPXtV953lGY=',
    created: [ [Object] ],
    mutated: [ [Object] ],
    gasObject: { owner: [Object], reference: [Object] },
    events: [ [Object] ],
    dependencies: [ 'GSGuFxNEIFe119fM86kJ4i0Yauvwo7G9JXmnPqbiqhU=' ]
  },
  timestamp_ms: null,
  parsed_data: {
    Publish: { package: [Object], createdObjects: [], updatedGas: [Object] }
  }
}

@patrickkuo
Copy link
Contributor

does sui move build --dump-bytecode-as-base64 output the same compiled module data?

@gegaowp
Copy link
Contributor

gegaowp commented Sep 9, 2022

no-execute flag to sui client publish

this looks like essentially dry_run publish tx? in that sense, maybe we can use this endpoint and save the necessary change on CLI side? #4514

not blocking at all and I can change the CLI to extend no-execute to all commands later.

sdk/typescript/src/utils/publish.ts Outdated Show resolved Hide resolved
sdk/typescript/src/utils/publish.ts Outdated Show resolved Hide resolved
@MystenLabs MystenLabs deleted a comment from kesne Sep 10, 2022
@MystenLabs MystenLabs deleted a comment from kesne Sep 10, 2022
@666lcz
Copy link
Contributor Author

666lcz commented Sep 13, 2022

does sui move build --dump-bytecode-as-base64 output the same compiled module data?

Good catch! They are the same thing and I've reverted the Rust changes on this PR

@666lcz
Copy link
Contributor Author

666lcz commented Sep 13, 2022

this looks like essentially dry_run publish tx? in that sense, maybe we can use this endpoint and save the necessary change on CLI side? #4514

It's a bit different than dry_run publish tx. This needs to output the compiled modules while the dry_run needs signatures and outputs transaction effects

@666lcz 666lcz changed the title [ts-sdk] Add util functions for using CLI to get compiled modules [ts-sdk] Update Instructions for using CLI to get compiled modules Sep 13, 2022
@666lcz 666lcz merged commit 7485592 into main Sep 13, 2022
@666lcz 666lcz deleted the chris-ts-publish-01 branch September 13, 2022 15:52
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.

6 participants