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

feat: added a transaction builder for better argument input. #52

Merged
merged 15 commits into from
Jul 8, 2024
6 changes: 3 additions & 3 deletions move/abi/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "7DED727D47EB51E5059409B19CC373C6D9AF249D837E9153E7368F3898025E41"
manifest_digest = "89B38FFD4D0D8B2DCFE440924446CCF3A347EA904B2657C9CA229BD7BB881131"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
edition = "2024.beta"
compiler-version = "1.22.0"
edition = "legacy"
Foivos marked this conversation as resolved.
Show resolved Hide resolved
flavor = "sui"
3 changes: 2 additions & 1 deletion move/abi/Move.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "Abi"
version = "0.1.0"
published-at = "0x41fb7e9c9d8851ecbfd4b89c910c0465de0cd0cf757c4bb261a8a6019ea33390"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }

[addresses]
abi = "0x103"
abi = "0x0"
6 changes: 3 additions & 3 deletions move/axelar_gateway/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "11FAF5CFE0A4A2EBCD5E370FAD144FFF14243A85492B718A2B26A15CF7F0B571"
manifest_digest = "10303CE6C59BAA2CE814E3D11BACC8CB24BE0F8D66753B02190E291CA40F0D39"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
edition = "2024.beta"
compiler-version = "1.22.0"
edition = "legacy"
flavor = "sui"
3 changes: 2 additions & 1 deletion move/axelar_gateway/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "AxelarGateway"
version = "0.1.0"
published-at = "0x571841ce66dce70e51a123299ed140d6509566c97eb905331b5f28732c707c56"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }

[addresses]
axelar_gateway = "0x100"
axelar_gateway = "0x571841ce66dce70e51a123299ed140d6509566c97eb905331b5f28732c707c56"
Foivos marked this conversation as resolved.
Show resolved Hide resolved
clock = "0x6"
1 change: 0 additions & 1 deletion move/axelar_gateway/info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"singletons": [
"gateway::Gateway",
Foivos marked this conversation as resolved.
Show resolved Hide resolved
"discovery::RelayerDiscovery"
]
}
6 changes: 3 additions & 3 deletions move/test/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "CF736E0717CB61683E6D638E781AA77454AE00BCA196A7FD23E4ACDBD78C0A5A"
manifest_digest = "6DF02196C888A850522C2336E4F8FF37DA00BCBB2240DEBF2500B46D2358E034"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ name = "AxelarGateway" },
Expand Down Expand Up @@ -30,6 +30,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
edition = "2024.beta"
compiler-version = "1.22.0"
edition = "legacy"
flavor = "sui"
3 changes: 2 additions & 1 deletion move/test/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "Test"
version = "0.1.0"
published-at = "0x5de4d52cd17c6e0483598bebb3243a886edefeb216e5ecc7c578edfeb8a7b4a9"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }
AxelarGateway = { local = "../axelar_gateway" }

[addresses]
test = "0x200"
test = "0x5de4d52cd17c6e0483598bebb3243a886edefeb216e5ecc7c578edfeb8a7b4a9"
62 changes: 3 additions & 59 deletions scripts/publish-package.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
require('dotenv').config();
const { setConfig, getFullObject, requestSuiFromFaucet } = require('./utils');
const { requestSuiFromFaucet, updateMoveToml } = require('./utils');
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
const { TransactionBlock } = require('@mysten/sui.js/transactions');
const { SuiClient } = require('@mysten/sui.js/client');
const { execSync } = require('child_process');
const { parseEnv } = require('./utils');
const tmp = require('tmp');
const fs = require('fs');
const path = require('path');

async function publishPackage(packageName, client, keypair) {
const toml = fs.readFileSync(`${__dirname}/../move/${packageName}/Move.toml`, 'utf8');
fs.writeFileSync(`${__dirname}/../move/${packageName}/Move.toml`, fillAddresses(toml, '0x0', packageName));
updateMoveToml(packageName, '0x0');

// remove all controlled temporary objects on process exit
const address = keypair.getPublicKey().toSuiAddress();
Expand Down Expand Up @@ -48,74 +46,20 @@ async function publishPackage(packageName, client, keypair) {
showObjectChanges: true,
showContent: true,
},
requestType: 'WaitForLocalExecution',
});
if (publishTxn.effects?.status.status !== 'success') throw new Error('Publish Tx failed');

const packageId = (publishTxn.objectChanges?.filter((a) => a.type === 'published') ?? [])[0].packageId;

console.info(`Published package ${packageId} from address ${address}}`);

return { packageId, publishTxn };
}

function updateMoveToml(packageName, packageId) {
const path = `${__dirname}/../move/${packageName}/Move.toml`;
const toml = fs.readFileSync(path, 'utf8');
fs.writeFileSync(path, fillAddresses(insertPublishedAt(toml, packageId), packageId, packageName));
}

function insertPublishedAt(toml, packageId) {
const lines = toml.split('\n');
const versionLineIndex = lines.findIndex((line) => line.slice(0, 7) === 'version');

if (!(lines[versionLineIndex + 1].slice(0, 12) === 'published-at')) {
lines.splice(versionLineIndex + 1, 0, '');
}

lines[versionLineIndex + 1] = `published-at = "${packageId}"`;
return lines.join('\n');
}

function fillAddresses(toml, address, packageName) {
const lines = toml.split('\n');
const addressesIndex = lines.findIndex((line) => line.slice(0, 11) === '[addresses]');

for (let i = addressesIndex + 1; i < lines.length; i++) {
const line = lines[i];
const eqIndex = line.indexOf('=');

if (eqIndex < 0 || line.slice(0, eqIndex - 1) !== packageName) {
continue;
}

lines[i] = line.slice(0, eqIndex + 1) + ` "${address}"`;
}

return lines.join('\n');
}

async function publishPackageFull(packageName, client, keypair, env) {
const { packageId, publishTxn } = await publishPackage(packageName, client, keypair);
const info = require(`${__dirname}/../move/${packageName}/info.json`);
const config = {};
config.packageId = packageId;

for (const singleton of info.singletons) {
const object = publishTxn.objectChanges.find((object) => object.objectType === `${packageId}::${singleton}`);
config[singleton] = await getFullObject(object, client);
}

setConfig(packageName, env.alias, config);
updateMoveToml(packageName, packageId);

return { packageId, publishTxn };
}

module.exports = {
publishPackage,
updateMoveToml,
publishPackageFull,
};

if (require.main === module) {
Expand All @@ -134,6 +78,6 @@ if (require.main === module) {
await requestSuiFromFaucet(env, address);
}

await publishPackageFull(packageName, client, keypair, env);
await publishPackage(packageName, client, keypair, env);
})();
}
Loading
Loading