-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts-sdk][cli] add util functions in ts-sdk for using CLI to get compi…
…ledModules
- Loading branch information
Showing
8 changed files
with
166 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Base64DataBuffer } from '../serialization/base64'; | ||
|
||
/** | ||
* Use the sui Command line tool to verify, compile and compute | ||
* the topological ordering of the module dependencies within | ||
* the package. This method is only available in NodeJS environment. | ||
* | ||
* Use this method with the local-txn-data-serializer. | ||
* | ||
* @param packagePath path to the Move package to be published | ||
* @param cliPath path to the sui CLI executable. Follow | ||
* {@link https://docs.sui.io/devnet/build/install} to install | ||
* @returns an array of compiled modules in bytes | ||
*/ | ||
export function getCompiledModules( | ||
packagePath: String, | ||
cliPath: String = 'sui' | ||
): number[][] { | ||
const { execSync } = require('child_process'); | ||
const modules = execSync( | ||
// gas-budget is a placeholder since there's no on-chain execution and thus no gas cost | ||
`${cliPath} client publish --path ${packagePath} --gas-budget 30000 --no-execute`, | ||
{ encoding: 'utf-8' } | ||
); | ||
return JSON.parse(modules); | ||
} | ||
|
||
/** | ||
* Same as getCompiledModules except the result is transformed to | ||
* an array of base64 strings. Use this method with the rpc-txn-data-serializer. | ||
* | ||
* @param packagePath path to the package to be published | ||
* @param cliPath path to the sui CLI executable. Follow | ||
* https://docs.sui.io/devnet/build/install to install | ||
* @returns an array of compiled modules in bytes | ||
*/ | ||
export function getCompiledModulesInBase64( | ||
packagePath: String, | ||
cliPath: String = 'sui' | ||
): String[] { | ||
const modules = getCompiledModules(packagePath, cliPath); | ||
return modules.map((m) => | ||
new Base64DataBuffer(Uint8Array.from(m)).toString() | ||
); | ||
} |