Skip to content

Commit

Permalink
feat(txs-tracer-core): ✨ add end forward middleware tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSegullo committed Apr 20, 2023
1 parent e11cf2b commit 262393d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const initialContext: CrossSwapTraceContext = {
errorMessage: '',
srcChannel: '',
dstChannel: '',
startSrcChannel: undefined,
startDstChannel: undefined,
endSrcChannel: undefined,
endDstChannel: undefined,
query: '',
txHash: '',
};
Expand All @@ -53,6 +57,18 @@ export const crossSwapTraceMachine = createMachine(
dstChannel: (_, event) => {
return event.data.dstChannel;
},
startSrcChannel: (_, event) => {
return event.data.startSrcChannel;
},
startDstChannel: (_, event) => {
return event.data.startDstChannel;
},
endSrcChannel: (_, event) => {
return event.data.endSrcChannel;
},
endDstChannel: (_, event) => {
return event.data.endDstChannel;
},
websocketUrl: (_, event) => {
return event.data.websocketUrl;
},
Expand Down Expand Up @@ -254,10 +270,22 @@ export const crossSwapTraceMachine = createMachine(
const data = getCrossSwapPacketSequence(tx);

if (data.packetSequence) {
/**
* If endSrcChannel and endDstChannel are configured, it means
* we need to trace the transaction from Osmosis to
* the forwarder chain (For example Cosmos Hub)
*/
const srcChannel = ctx.endSrcChannel
? ctx.endSrcChannel
: ctx.dstChannel;
const dstChannel = ctx.endDstChannel
? ctx.endDstChannel
: ctx.srcChannel;

return {
type: 'TRACE',
data: {
query: `acknowledge_packet.packet_src_channel='${ctx.dstChannel}' and acknowledge_packet.packet_dst_channel='${ctx.srcChannel}' and acknowledge_packet.packet_sequence=${data.packetSequence}`,
query: `acknowledge_packet.packet_src_channel='${srcChannel}' and acknowledge_packet.packet_dst_channel='${dstChannel}' and acknowledge_packet.packet_sequence=${data.packetSequence}`,
websocketUrl: ctx.dstWebsocketUrl,
},
};
Expand Down
25 changes: 25 additions & 0 deletions packages/txs-tracer-core/src/lib/types/cross-swap-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ export type CrossSwapTraceContext = Omit<IBCTraceContext, 'ackTx' | 'txs'> & {
txHash: string;
errorMessage?: string;
totalSteps: number;
/**
* Data definitions for interchain swaps
*/
/**
* Channel related to token transfer using forward middleware on start.
* for example if I swap atom to osmo (And the swap is performed on Juno Chain),
* I'll set it to the channel between the Osmosis chain and the Cosmos Hub chain.
* endSrcChannel: channel-1
* endDstChannel: channel-207
*/
startSrcChannel?: string;
startDstChannel?: string;
/**
* Channel related to token transfer using forward middleware
* for example if I swap osmo to atom (And the swap is performed on Juno Chain),
* I'll set it to the channel between the Osmosis chain and the Cosmos Hub chain.
* endSrcChannel: channel-0
* endDstChannel: channel-141
*/
endSrcChannel?: string;
endDstChannel?: string;
};

export type CrossSwapMachineResultErrorPayload =
Expand All @@ -22,6 +43,10 @@ export type CrossSwapMachineResultErrorPayload =

export type CrossSwapTraceEventPayload = IBCTraceEventPayload & {
txHash: string;
startSrcChannel?: string;
startDstChannel?: string;
endSrcChannel?: string;
endDstChannel?: string;
};

export const CrossSwapTraceFinalState = {
Expand Down

0 comments on commit 262393d

Please sign in to comment.