forked from hyperlane-xyz/hyperlane-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hyperlane-xyz#78: Decode warp route messages.
- Loading branch information
1 parent
4103c31
commit ef05c9d
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
messageBody: string, | ||
originTx: { to?: string; from?: string } = {}, | ||
gasInfo: { totalPayment: any }, | ||
metadata?: any | ||
): WarpRouteDetails | undefined { | ||
try { | ||
if (!messageBody?.trim()) throw new Error('Invalid message body'); | ||
|
||
const parsedMessage = parseWarpRouteMessage(messageBody); | ||
|
||
return { | ||
token: originTx?.to ? postgresByteaToAddress(originTx.to, metadata) : 'Unknown Token', | ||
amount: utils.formatEther(parsedMessage.amount.toString()), | ||
totalPayment: utils.formatEther(gasInfo.totalPayment.toString()) | ||
}; | ||
} catch (error) { | ||
console.error('Failed to parse token details:', error, 'Message body:', messageBody); | ||
return undefined; | ||
} | ||
} |