Skip to content

Commit

Permalink
Add relay option for dispatch tx hash
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed May 4, 2024
1 parent baedddc commit be2407d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
9 changes: 7 additions & 2 deletions typescript/cli/src/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { checkMessageStatus } from '../status/message.js';
import { MessageOptionsArgTypes, messageOptions } from './send.js';

export const statusCommand: CommandModuleWithContext<
MessageOptionsArgTypes & { id?: string }
MessageOptionsArgTypes & { id?: string } & { dispatchTx?: string }
> = {
command: 'status',
describe: 'Check status of a message',
Expand All @@ -14,10 +14,15 @@ export const statusCommand: CommandModuleWithContext<
type: 'string',
description: 'Message ID',
},
dispatchTx: {
type: 'string',
description: 'Dispatch transaction hash',
},
},
handler: async ({ context, origin, destination, id, relay }) => {
handler: async ({ context, origin, destination, id, relay, dispatchTx }) => {
await checkMessageStatus({
context,
dispatchTx,
messageId: id,
destination,
origin,
Expand Down
24 changes: 19 additions & 5 deletions typescript/cli/src/status/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export async function checkMessageStatus({
destination,
origin,
selfRelay,
dispatchTx,
}: {
context: CommandContext;
dispatchTx?: string;
messageId?: string;
destination?: ChainName;
origin?: ChainName;
Expand Down Expand Up @@ -47,17 +49,29 @@ export async function checkMessageStatus({
logBlue(`Message ${messageId} was not yet delivered`);

if (selfRelay) {
// TODO: implement option for tx receipt input
if (!origin) {
origin = await runSingleChainSelectionStep(
context.chainMetadata,
'Select the origin chain',
);
}

const receipt = await core.getDispatchTx(origin, messageId);
const messages = core.getDispatchedMessages(receipt);
await core.relayMessage(messages[0], receipt);
logGreen(`Message ${messageId} was self-relayed!`);
if (!dispatchTx) {
dispatchTx = await input({
message: 'Provide the dispatch transaction hash',
});
}
const dispatchTxReceipt = await context.multiProvider
.getProvider(origin)
.getTransactionReceipt(dispatchTx);

const messages = core.getDispatchedMessages(dispatchTxReceipt);
const tx = await core.relayMessage(messages[0], dispatchTxReceipt);
logGreen(
`Message ${messageId} was relayed in ${context.multiProvider.getExplorerTxUrl(
destination,
{ hash: tx.transactionHash },
)}`,
);
}
}

0 comments on commit be2407d

Please sign in to comment.