Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #78: Decode warp route messages. #144

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/features/messages/cards/ContentDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function ContentDetailsCard({
recipient,
body,
decodedBody,
warpRouteDetails,
},
blur,
}: Props) {
Expand Down Expand Up @@ -106,6 +107,39 @@ export function ContentDetailsCard({
blurValue={blur}
/>
</div>
{warpRouteDetails && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this in its own card like the Interchain Gas Payments card

<>
<div className="mt-2 border-t border-gray-200 pt-4">
<h4 className="mb-3 text-sm font-medium text-gray-500">Warp Route Details:</h4>
<div className="flex flex-wrap gap-x-6 gap-y-4">
<KeyValueRow
label="Token:"
labelWidth="w-16"
display={warpRouteDetails.token}
displayWidth="w-64 sm:w-80"
showCopy={true}
blurValue={blur}
/>
<KeyValueRow
label="Amount:"
labelWidth="w-16"
display={warpRouteDetails.amount}
displayWidth="w-64 sm:w-80"
showCopy={true}
blurValue={blur}
/>
<KeyValueRow
label="Fee Paid:"
labelWidth="w-16"
display={warpRouteDetails.totalPayment}
displayWidth="w-64 sm:w-80"
showCopy={true}
blurValue={blur}
/>
</div>
</div>
</>
)}
<div>
<div className="flex items-center">
<label className="text-sm text-gray-500">Message Content:</label>
Expand Down
9 changes: 9 additions & 0 deletions src/features/messages/queries/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
MessagesStubQueryResult,
} from './fragments';

import { parseWarpRouteDetails } from '../../../utils/token';

/**
* ========================
* RESULT PARSING UTILITIES
Expand Down Expand Up @@ -111,6 +113,12 @@ function parseMessage(

const body = postgresByteaToString(m.message_body ?? '');
const decodedBody = tryUtf8DecodeBytes(body);
const warpRouteDetails = parseWarpRouteDetails(
body,
{ to: m.origin_tx_recipient, from: m.origin_tx_sender },
{ totalPayment: m.total_payment },
originMetadata
);

return {
...stub,
Expand Down Expand Up @@ -151,6 +159,7 @@ function parseMessage(
totalGasAmount: m.total_gas_amount.toString(),
totalPayment: m.total_payment.toString(),
numPayments: m.num_payments,
warpRouteDetails: warpRouteDetails ?? undefined,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ?? undefined doesn't do anything right?

};
} catch (error) {
logger.error('Error parsing message', error);
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ export interface Message extends MessageStub {
totalGasAmount?: string;
totalPayment?: string;
numPayments?: number;
warpRouteDetails?: WarpRouteDetails;
}

export interface ExtendedLog extends providers.Log {
timestamp?: number;
from?: Address;
to?: Address;
}

export interface WarpRouteDetails {
token: string;
amount: string;
totalPayment: string;
}
26 changes: 26 additions & 0 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { parseWarpRouteMessage } from '@hyperlane-xyz/utils';
import { utils } from 'ethers';
import { postgresByteaToAddress } from '../features/messages/queries/encoding';
import { WarpRouteDetails } from '../types';

export function parseWarpRouteDetails(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to src/features/messages/queries/parse.ts as that's the only place it's used.
I'm not a big fan of accumulating business logic in the utils folders

messageBody: string,
originTx: { to?: string; from?: string } = {},
gasInfo: { totalPayment: any },
metadata?: any
): WarpRouteDetails | undefined {
try {
if (!messageBody?.trim()) throw new Error('Invalid message body');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessarily an invalid body. Just return undefined


const parsedMessage = parseWarpRouteMessage(messageBody);

return {
token: originTx?.to ? postgresByteaToAddress(originTx.to, metadata) : 'Unknown Token',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal but reorder things in the calling function so we don't have to decode this to value twice

amount: utils.formatEther(parsedMessage.amount.toString()),
totalPayment: utils.formatEther(gasInfo.totalPayment.toString())
Comment on lines +19 to +20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};
} catch (error) {
console.error('Failed to parse token details:', error, 'Message body:', messageBody);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no console, use logger. Did the lint not raise this?

return undefined;
}
}