-
Notifications
You must be signed in to change notification settings - Fork 76
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ import { | |
MessagesStubQueryResult, | ||
} from './fragments'; | ||
|
||
import { parseWarpRouteDetails } from '../../../utils/token'; | ||
|
||
/** | ||
* ======================== | ||
* RESULT PARSING UTILITIES | ||
|
@@ -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, | ||
|
@@ -151,6 +159,7 @@ function parseMessage( | |
totalGasAmount: m.total_gas_amount.toString(), | ||
totalPayment: m.total_payment.toString(), | ||
numPayments: m.num_payments, | ||
warpRouteDetails: warpRouteDetails ?? undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
}; | ||
} catch (error) { | ||
logger.error('Error parsing message', error); | ||
|
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this to |
||
messageBody: string, | ||
originTx: { to?: string; from?: string } = {}, | ||
gasInfo: { totalPayment: any }, | ||
metadata?: any | ||
): WarpRouteDetails | undefined { | ||
try { | ||
if (!messageBody?.trim()) throw new Error('Invalid message body'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
amount: utils.formatEther(parsedMessage.amount.toString()), | ||
totalPayment: utils.formatEther(gasInfo.totalPayment.toString()) | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the hyp utils here: https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/utils/src/amount.ts#L13 |
||
}; | ||
} catch (error) { | ||
console.error('Failed to parse token details:', error, 'Message body:', messageBody); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no console, use logger. Did the lint not raise this? |
||
return undefined; | ||
} | ||
} |
There was a problem hiding this comment.
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