Skip to content

Commit

Permalink
feat(txs-tracer-core): ✨ improve ibc trace using channels
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSegullo committed Apr 12, 2023
1 parent a0f7995 commit f4b8acc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const ibcTraceMachine = createMachine(
TRACE: {
target: 'send_packet',
actions: assign({
srcChannel: (_, event) => {
return event.data.srcChannel;
},
dstChannel: (_, event) => {
return event.data.dstChannel;
},
websocketUrl: (_, event) => {
return event.data.websocketUrl;
},
Expand Down Expand Up @@ -146,12 +152,14 @@ export const ibcTraceMachine = createMachine(
event.data.txs[0].code === 0
);
},
actions: raise((_, event) => ({
type: 'TRACE_COMPLETED',
data: {
tx: event.data.txs ? event.data.txs[0] : undefined,
},
})),
actions: raise((ctx, event) => {
return {
type: 'TRACE_COMPLETED',
data: {
tx: event.data.txs ? event.data.txs[0] : undefined,
},
};
}),
},
{
actions: raise((_, event) => ({
Expand Down Expand Up @@ -180,8 +188,6 @@ export const ibcTraceMachine = createMachine(
e => e.type === 'send_packet',
);

console.log(sendPacket);

if (sendPacket) {
const packetSequence: Attribute | undefined =
sendPacket.attributes.find(e => e.key === 'packet_sequence');
Expand All @@ -190,7 +196,7 @@ export const ibcTraceMachine = createMachine(
return {
type: 'TRACE',
data: {
query: `acknowledge_packet.packet_sequence=${packetSequence.value}`,
query: `acknowledge_packet.packet_src_channel='${ctx.srcChannel}' and acknowledge_packet.packet_dst_channel='${ctx.dstChannel}' and acknowledge_packet.packet_sequence=${packetSequence.value}`,
websocketUrl: ctx.websocketUrl,
},
};
Expand Down Expand Up @@ -251,6 +257,8 @@ export const ibcTraceMachine = createMachine(
currentStep: 0,
errorCode: 0,
query: '',
srcChannel: '', // ex: channel-140
dstChannel: '', // ex: channel-3316
},
predictableActionArguments: true,
preserveActionOrder: true,
Expand Down
7 changes: 6 additions & 1 deletion packages/txs-tracer-core/src/lib/types/ibc-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ export type IBCTraceContext = Omit<
> & {
loading: boolean;
currentStep: number;
srcChannel: string;
dstChannel: string;
errorCode?: number;
txs?: IndexedTx;
ackTx?: IndexedTx;
};

export type IBCTraceEventPayload = TxTraceEventPayload;
export type IBCTraceEventPayload = TxTraceEventPayload & {
srcChannel: string;
dstChannel: string;
};

export type IBCMachineResultErrorPayload = {
type: TxTraceFinalStates;
Expand Down

0 comments on commit f4b8acc

Please sign in to comment.