@@ -15,8 +15,16 @@ import {
1515 walletFromSeed ,
1616 withXrplClient ,
1717} from "../../xrpl/helpers" ;
18- import { DEFAULT_EXECUTOR_API , fetchQuote , submitStatusTx } from "../../xrpl/executor" ;
19- import { CHAIN_ID_XRPL , DEFAULT_GUARDIAN_API , pollSignedVaa } from "../../xrpl/guardian" ;
18+ import {
19+ DEFAULT_EXECUTOR_API ,
20+ fetchQuote ,
21+ submitStatusTx ,
22+ } from "../../xrpl/executor" ;
23+ import {
24+ CHAIN_ID_XRPL ,
25+ DEFAULT_GUARDIAN_API ,
26+ pollSignedVaa ,
27+ } from "../../xrpl/guardian" ;
2028import {
2129 RequestPrefix ,
2230 buildGasInstructionHex ,
@@ -83,7 +91,10 @@ function buildRequest(opts: {
8391 request : {
8492 prefix : RequestPrefix . ERN1 ,
8593 srcChain : CHAIN_ID_XRPL ,
86- srcManager : ethers . zeroPadValue ( srcManager as `0x${string } `, 32 ) as `0x${string } `,
94+ srcManager : ethers . zeroPadValue (
95+ srcManager as `0x${string } `,
96+ 32
97+ ) as `0x${string } `,
8798 messageId : opts . messageId ,
8899 } ,
89100 } ;
@@ -231,55 +242,65 @@ async function runRelay(
231242 // export.ts): a core VAA (erv1: onboarding / admin / register-peer) uses the
232243 // left-padded SENDER account, while an NTT transfer (ern1) uses the keccak
233244 // transceiver emitter keccak256("ntt" || custody || token).
234- const { emitterHex, sequence } = await withXrplClient ( endpoint , async ( client ) => {
235- const resp = await client . request ( { command : "tx" , transaction : txHash } ) ;
236- const tx : any = resp . result ;
237- const ledgerIndex = tx . ledger_index ;
238- if ( ! ledgerIndex ) throw new Error ( "Transaction not validated (no ledger_index)" ) ;
239- const meta = tx . meta ?? tx . metaData ;
240- if ( typeof meta !== "object" || meta === null || ! ( "TransactionIndex" in meta ) ) {
241- throw new Error ( "Transaction metadata missing TransactionIndex" ) ;
242- }
243- const txIndex = ( meta as any ) . TransactionIndex as number ;
244- const sequence = ( BigInt ( ledgerIndex ) << 32n ) | BigInt ( txIndex ) ;
245-
246- let emitterHex : string ;
247- if ( requestType === "erv1" ) {
248- // Core VAA: emitter = the publishing (SENDER) account, left-padded to 32B.
249- const sender : string | undefined = tx . Account ?? tx . tx_json ?. Account ;
250- if ( ! sender ) {
251- throw new Error ( "Could not determine the publishing account (tx.Account)" ) ;
252- }
253- emitterHex = xrplAccountToEmitter ( Buffer . from ( decodeAccountID ( sender ) ) ) ;
254- } else {
255- // NTT transfer: emitter = keccak256("ntt" || custody || token), where the
256- // custody account is the tx destination and the token is the delivered asset.
257- const destination : string | undefined =
258- tx . Destination ?? tx . tx_json ?. Destination ;
259- if ( ! destination ) {
260- throw new Error ( "Could not determine destination/custody address" ) ;
245+ const { emitterHex, sequence } = await withXrplClient (
246+ endpoint ,
247+ async ( client ) => {
248+ const resp = await client . request ( { command : "tx" , transaction : txHash } ) ;
249+ const tx : any = resp . result ;
250+ const ledgerIndex = tx . ledger_index ;
251+ if ( ! ledgerIndex )
252+ throw new Error ( "Transaction not validated (no ledger_index)" ) ;
253+ const meta = tx . meta ?? tx . metaData ;
254+ if (
255+ typeof meta !== "object" ||
256+ meta === null ||
257+ ! ( "TransactionIndex" in meta )
258+ ) {
259+ throw new Error ( "Transaction metadata missing TransactionIndex" ) ;
261260 }
262- const deliveredAmount = ( meta as any ) . delivered_amount ;
263- let token : TokenId ;
264- if ( argv . token ) {
265- token = tokenIdFromFlags ( {
266- type : argv . token ,
267- currency : argv . currency ,
268- issuer : argv . issuer ,
269- mptId : argv [ "mpt-id" ] ,
270- } ) ;
271- } else if ( deliveredAmount ) {
272- token = tokenIdFromXrplAmount ( deliveredAmount ) ;
261+ const txIndex = ( meta as any ) . TransactionIndex as number ;
262+ const sequence = ( BigInt ( ledgerIndex ) << 32n ) | BigInt ( txIndex ) ;
263+
264+ let emitterHex : string ;
265+ if ( requestType === "erv1" ) {
266+ // Core VAA: emitter = the publishing (SENDER) account, left-padded to 32B.
267+ const sender : string | undefined = tx . Account ?? tx . tx_json ?. Account ;
268+ if ( ! sender ) {
269+ throw new Error (
270+ "Could not determine the publishing account (tx.Account)"
271+ ) ;
272+ }
273+ emitterHex = xrplAccountToEmitter ( Buffer . from ( decodeAccountID ( sender ) ) ) ;
273274 } else {
274- token = { type : "XRP" } ;
275+ // NTT transfer: emitter = keccak256("ntt" || custody || token), where the
276+ // custody account is the tx destination and the token is the delivered asset.
277+ const destination : string | undefined =
278+ tx . Destination ?? tx . tx_json ?. Destination ;
279+ if ( ! destination ) {
280+ throw new Error ( "Could not determine destination/custody address" ) ;
281+ }
282+ const deliveredAmount = ( meta as any ) . delivered_amount ;
283+ let token : TokenId ;
284+ if ( argv . token ) {
285+ token = tokenIdFromFlags ( {
286+ type : argv . token ,
287+ currency : argv . currency ,
288+ issuer : argv . issuer ,
289+ mptId : argv [ "mpt-id" ] ,
290+ } ) ;
291+ } else if ( deliveredAmount ) {
292+ token = tokenIdFromXrplAmount ( deliveredAmount ) ;
293+ } else {
294+ token = { type : "XRP" } ;
295+ }
296+ emitterHex = computeEmitterAddress (
297+ Buffer . from ( decodeAccountID ( destination ) ) ,
298+ token
299+ ) . toString ( "hex" ) ;
275300 }
276- emitterHex = computeEmitterAddress (
277- Buffer . from ( decodeAccountID ( destination ) ) ,
278- token
279- ) . toString ( "hex" ) ;
301+ return { emitterHex, sequence } ;
280302 }
281- return { emitterHex, sequence } ;
282- } ) ;
303+ ) ;
283304
284305 const messageId = ethers . toBeHex ( sequence , 32 ) as `0x${string } `;
285306 console . log ( ` emitter: ${ colors . gray ( emitterHex ) } ` ) ;
@@ -353,7 +374,9 @@ async function runRelay(
353374 console . log ( ` dst addr: ${ colors . gray ( dstAddr ) } ` ) ;
354375 console . log ( ` refund addr: ${ colors . gray ( refundAddr ) } ` ) ;
355376 console . log ( ` relay instructions: ${ colors . gray ( relayInstructions ) } ` ) ;
356- console . log ( ` request (${ requestType } ): ${ colors . gray ( serializeRequest ( request ) ) } ` ) ;
377+ console . log (
378+ ` request (${ requestType } ): ${ colors . gray ( serializeRequest ( request ) ) } `
379+ ) ;
357380 console . log ( ` RequestForExecution: ${ colors . gray ( serialized ) } ` ) ;
358381
359382 // ── 5. Submit the XRPL Payment carrying the executor-request memo ──
0 commit comments