Skip to content

Commit

Permalink
fixed some issues after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Jun 14, 2024
1 parent 8ba2aa9 commit 17600af
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 59 deletions.
4 changes: 2 additions & 2 deletions move/axelar_gateway/Move.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "AxelarGateway"
version = "0.1.0"
published-at = "0x8f0ff604b968c87932c2fb8defbe5ad9f5af095d7df12d687f4b25321800faa8"
published-at = "0xdd3b165835ec3d510016f8492519feb74a631f235f0126f44fec079c8aa81186"
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 = "0x8f0ff604b968c87932c2fb8defbe5ad9f5af095d7df12d687f4b25321800faa8"
axelar_gateway = "0xdd3b165835ec3d510016f8492519feb74a631f235f0126f44fec079c8aa81186"
clock = "0x6"
2 changes: 1 addition & 1 deletion 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 = "E39FD071E9EFD0729A4D15C389E9E5EF831FB1E0DB9B2A6E35AFD0DC302863A1"
manifest_digest = "6DF02196C888A850522C2336E4F8FF37DA00BCBB2240DEBF2500B46D2358E034"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ name = "AxelarGateway" },
Expand Down
4 changes: 2 additions & 2 deletions move/test/Move.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "Test"
version = "0.1.0"
published-at = "0x5de4d52cd17c6e0483598bebb3243a886edefeb216e5ecc7c578edfeb8a7b4a9"
published-at = "0x3416821971d670acd3a1b8556d2df99bda3cd35c49d581c7ece89aca0137af4d"
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 = "0x5de4d52cd17c6e0483598bebb3243a886edefeb216e5ecc7c578edfeb8a7b4a9"
test = "0x3416821971d670acd3a1b8556d2df99bda3cd35c49d581c7ece89aca0137af4d"
8 changes: 2 additions & 6 deletions scripts/bcs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { bcs } = require('@mysten/sui.js/bcs');

function getAxelarStructs() {
const Bytes32 = bcs.struct('Bytes32', {
bytes: bcs.Address,
});
const Bytes32 = bcs.Address;

const Message = bcs.struct('Message', {
source_chain: bcs.String,
Expand All @@ -24,9 +22,7 @@ function getAxelarStructs() {
nonce: Bytes32,
});

const Signature = bcs.struct('Signature', {
bytes: bcs.vector(bcs.U8),
});
const Signature = bcs.vector(bcs.U8);

const Proof = bcs.struct('Proof', {
signers: WeightedSigners,
Expand Down
95 changes: 47 additions & 48 deletions scripts/tx-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const {
} = require('ethers');
const tmp = require('tmp');
const path = require('path');
const { updateMoveToml } = require('./utils');
const { execSync } = require('child_process');

const objectCache = {};

Expand All @@ -24,7 +26,9 @@ function getObject(tx, object) {
const cached = objectCache[object];

if (cached) {
return tx.object(cached);
// TODO: figure out how to load the object version/digest into the TransactionBlock because it seems impossible for non gas payment objects
const txObject = tx.object(object);
return txObject;
}

return tx.object(object);
Expand Down Expand Up @@ -134,10 +138,15 @@ function serialize(tx, type, arg) {
}

function isTxContext(parameter) {
parameter = parameter.MutableReference;
if (!parameter) return false;
parameter = parameter.Struct;
if (!parameter) return false;
if(parameter.MutableReference) {
parameter = parameter.MutableReference.Struct;
if (!parameter) return false;
} else if (parameter.Reference) {
parameter = parameter.Reference.Struct;
if (!parameter) return false;
} else {
return false;
}
return parameter.address === '0x2' && parameter.module === 'tx_context' && parameter.name === 'TxContext';
}

Expand All @@ -157,7 +166,8 @@ class TxBuilder {
this.tx = new TransactionBlock();
}

async moveCall({target, args, typeArguments = []}) {
async moveCall(moveCallInfo) {
let target = moveCallInfo.target;
// If target is string, convert to object that `getNormalizedMoveFunction` accepts.
if (typeof target === 'string') {
const first = target.indexOf(':');
Expand All @@ -176,17 +186,17 @@ class TxBuilder {

let length = moveFn.parameters.length;
if (isTxContext(moveFn.parameters[length - 1])) length = length - 1;
if (length !== args.length)
if (length !== moveCallInfo.arguments.length)
throw new Error(
`Function ${target.package}::${target.module}::${target.function} takes ${moveFn.parameters.length} arguments but given ${args.length}`,
`Function ${target.package}::${target.module}::${target.function} takes ${moveFn.parameters.length} arguments but given ${moveCallInfo.arguments.length}`,
);

const convertedArgs = args.map((arg, index) => serialize(this.tx, moveFn.parameters[index], arg));
const convertedArgs = moveCallInfo.arguments.map((arg, index) => serialize(this.tx, moveFn.parameters[index], arg));

return this.tx.moveCall({
target: `${target.package}::${target.module}::${target.function}`,
arguments: convertedArgs,
typeArguments,
typeArguments: moveCallInfo.typeArguments,
});
}

Expand All @@ -198,56 +208,26 @@ class TxBuilder {
const tmpobj = tmp.dirSync({ unsafeCleanup: true });

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


const tx = new TransactionBlock();
return tx.publish({
return this.tx.publish({
modules,
dependencies,
});
}

async publishPackageAndTransferCap(packageName, to, moveDir = `${__dirname}/../move`) {
updateMoveToml(packageName, '0x0', moveDir);

tmp.setGracefulCleanup();

const tmpobj = tmp.dirSync({ unsafeCleanup: true });
const cap = await this.publishPackage(packageName, moveDir);

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


const tx = new TransactionBlock();
const cap = tx.publish({
modules,
dependencies,
});

tx.transferObjects([cap], to);
this.tx.transferObjects([cap], to);
}

async signAndExecute(keypair, options) {
const result = await this.client.signAndExecuteTransactionBlock({
let result = await this.client.signAndExecuteTransactionBlock({
transactionBlock: this.tx,
signer: keypair,
options: {
Expand All @@ -257,6 +237,25 @@ class TxBuilder {
...options,
},
});
if(!result.confirmedLocalExecution) {
while(true) {
try {
result = await this.client.getTransactionBlock({
digest: result.digest,
options: {
showEffects: true,
showObjectChanges: true,
showContent: true,
...options,
}
});
break;
} catch(e) {
console.log(e);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
}
updateCache(result.objectChanges);
return result;
}
Expand Down

0 comments on commit 17600af

Please sign in to comment.