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

chore: allow passing custom tmpdir #107

Merged
merged 15 commits into from
Aug 26, 2024
5 changes: 5 additions & 0 deletions .changeset/fuzzy-mayflies-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': patch
---

remove tmp dependency and create directly manually at the same folder level to avoid error in docker container environment
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ First of all, as we mentioned before, for applications to 'validate' themselves
- The shared object has to have a field called `get_call_info_object_ids` that is a `vector<address>`.
- The module that defined the shared object type has to implement a function called `get_call_info`, which has no types, and takes the incoming call `payload` as the first argument, followed by a number of shared objects whose ids are specified by the `get_call_info_object_ids` mentioned above. This function has to return a `std::ascii::String` which is the JSON encoded call data to fullfill the contract call.
- This calldata has the following 3 fields:
- `target`: the target method, in the form of `packag_iId::module_name::function_name`.
- `target`: the target method, in the form of `package_id::module_name::function_name`.
- `arguments`: an array of arguments that can be:
- `contractCall`: the `ApprovedMessage` object (see below).
- `pure:${info}`: a pure argument specified by `$info`.
Expand Down
16 changes: 0 additions & 16 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@
"@mysten/sui": "^1.3.0",
"ethers": "^5.0.0",
"secp256k1": "^5.0.0",
"tmp": "^0.2.1",
"typescript": "^5.3.3"
},
"devDependencies": {
"@changesets/cli": "^2.27.6",
"@ianvs/prettier-plugin-sort-imports": "^4.2.1",
"@types/node": "^20.14.11",
"@types/tmp": "^0.2.6",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"chai": "^4.3.7",
Expand Down
26 changes: 21 additions & 5 deletions src/tx-builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { bcs, BcsType } from '@mysten/bcs';
import {
Expand All @@ -12,7 +13,6 @@ import {
import { Keypair } from '@mysten/sui/dist/cjs/cryptography';
import { Transaction, TransactionObjectInput, TransactionResult } from '@mysten/sui/transactions';
import { Bytes, utils as ethersUtils } from 'ethers';
import tmp from 'tmp';
import { updateMoveToml } from './utils';

const stdPackage = '0x1';
Expand Down Expand Up @@ -246,24 +246,40 @@ export class TxBuilder {
});
}

/**
* Prepare a move build by creating a temporary directory to store the compiled move code
* @returns {dir: string, rm: () => void}
* - dir is the path to the temporary directory
* - rm is a function to remove the temporary directory
*/
private prepareMoveBuild() {
const tmpdir = fs.mkdtempSync(`${__dirname}/.move-build-`);
const rm = () => fs.rmSync(tmpdir, { recursive: true });

return {
tmpdir,
rm,
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
};
}

async getContractBuild(
packageName: string,
moveDir: string = `${__dirname}/../move`,
): Promise<{ modules: string[]; dependencies: string[]; digest: Bytes }> {
const emptyPackageId = '0x0';
updateMoveToml(packageName, emptyPackageId, moveDir);

tmp.setGracefulCleanup();

const tmpobj = tmp.dirSync({ unsafeCleanup: true });
const { tmpdir, rm } = this.prepareMoveBuild();
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

const { modules, dependencies, digest } = JSON.parse(
execSync(`sui move build --dump-bytecode-as-base64 --path ${path.join(moveDir, packageName)} --install-dir ${tmpobj.name}`, {
execSync(`sui move build --dump-bytecode-as-base64 --path ${path.join(moveDir, packageName)} --install-dir ${tmpdir}`, {
encoding: 'utf-8',
stdio: 'pipe', // silent the output
}),
);

rm();
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

return { modules, dependencies, digest };
}

Expand Down
Loading