Skip to content

Commit

Permalink
chore: use channelId instead of given destinationId
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Jul 16, 2024
1 parent d0d9af4 commit 924f3ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
29 changes: 19 additions & 10 deletions sui/gmp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { saveConfig, printInfo } = require('../evm/utils');
const { Command } = require('commander');
const { TransactionBlock } = require('@mysten/sui.js/transactions');
const { approvedMessageStruct } = require('./types-utils');
const { approvedMessageStruct, singletonStruct } = require('./types-utils');
const { bcs } = require('@mysten/sui.js/bcs');
const { loadSuiConfig } = require('./utils');
const { loadSuiConfig, getBcsBytesByObjectId } = require('./utils');
const { ethers } = require('hardhat');
const {
utils: { arrayify },
Expand Down Expand Up @@ -43,20 +43,29 @@ async function execute(chain, args, options) {

await printWalletInfo(keypair, client, chain, options);

const [sourceChain, messageId, sourceAddress, destinationId, payload] = args;
const singletonObjectId = chain.contracts.test.objects.singleton;

const bcsBytes = await getBcsBytesByObjectId(client, singletonObjectId);

const data = singletonStruct.parse(bcsBytes);

const channelId = '0x' + data.channel.id;

printInfo('Channel ID', channelId);

const [sourceChain, messageId, sourceAddress, payload] = args;

const encodedMessage = approvedMessageStruct
.serialize({
source_chain: sourceChain,
message_id: messageId,
source_address: sourceAddress,
destination_id: destinationId,
payload,
destination_id: channelId,
payload: arrayify(payload),
})
.toBytes();

const testConfig = chain.contracts.test;
const singletonObjectId = testConfig.objects.singleton;
console.log('Encoded message', encodedMessage);

const tx = new TransactionBlock();
tx.moveCall({
Expand Down Expand Up @@ -100,7 +109,7 @@ if (require.main === module) {
const executeCommand = new Command()
.name('execute')
.description('Execute gmp contract call')
.command('execute <sourceChain> <messageId> <sourceAddress> <destinationId> <payload>');
.command('execute <sourceChain> <messageId> <sourceAddress> <payload>');

addBaseOptions(sendCallProgram);
addBaseOptions(executeCommand);
Expand All @@ -109,8 +118,8 @@ if (require.main === module) {
mainProcessor('send-call', options, [destChain, destContractAddress, payload], processCommand);
});

executeCommand.action((sourceChain, messageId, sourceAddress, destinationId, payload, options) => {
mainProcessor('execute', options, [sourceChain, messageId, sourceAddress, destinationId, payload], processCommand);
executeCommand.action((sourceChain, messageId, sourceAddress, payload, options) => {
mainProcessor('execute', options, [sourceChain, messageId, sourceAddress, payload], processCommand);
});

program.addCommand(sendCallProgram);
Expand Down
11 changes: 11 additions & 0 deletions sui/types-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ const gasServiceStruct = bcs.struct('GasService', {
balance: bcs.u64(),
});

const channelStruct = bcs.struct('Channel', {
id: UID,
});

const singletonStruct = bcs.struct('Singleton', {
id: UID,
channel: channelStruct,
});

module.exports = {
addressStruct,
signerStruct,
Expand All @@ -75,4 +84,6 @@ module.exports = {
approvedMessageStruct,
proofStruct,
gasServiceStruct,
channelStruct,
singletonStruct,
};

0 comments on commit 924f3ab

Please sign in to comment.