File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -104,10 +104,19 @@ type RosettaRevokeDelegateContractArgs = {
104104} ;
105105
106106export function parseTransactionMemo ( tx : BaseTx ) : string | null {
107- if ( tx . token_transfer_memo && tx . token_transfer_memo != '' ) {
107+ const memoHex = tx . token_transfer_memo ;
108+ if ( memoHex ) {
108109 // Memos are a fixed-length 34 byte array. Any memo representing a string that is
109110 // less than 34 bytes long will have right-side padded null-bytes.
110- return tx . token_transfer_memo . replace ( / \0 .* $ / g, '' ) ;
111+ let memoBuffer = hexToBuffer ( memoHex ) ;
112+ while ( memoBuffer . length > 0 && memoBuffer [ memoBuffer . length - 1 ] === 0 ) {
113+ memoBuffer = memoBuffer . slice ( 0 , memoBuffer . length - 1 ) ;
114+ }
115+ if ( memoBuffer . length === 0 ) {
116+ return null ;
117+ }
118+ const memoDecoded = memoBuffer . toString ( 'utf8' ) ;
119+ return memoDecoded ;
111120 }
112121 return null ;
113122}
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import { TestBlockBuilder } from '../test-utils/test-builders';
2828import { PgWriteStore } from '../datastore/pg-write-store' ;
2929import { cycleMigrations , runMigrations } from '../datastore/migrations' ;
3030import { PgSqlClient } from '../datastore/connection' ;
31+ import { bufferToHexPrefixString } from '../helpers' ;
3132
3233describe ( 'Rosetta API' , ( ) => {
3334 let db : PgWriteStore ;
@@ -346,7 +347,7 @@ describe('Rosetta API', () => {
346347 abi : undefined ,
347348 token_transfer_recipient_address : 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP' ,
348349 token_transfer_amount : 3852n ,
349- token_transfer_memo : '0x25463526' ,
350+ token_transfer_memo : bufferToHexPrefixString ( Buffer . from ( 'test1234' ) ) . padEnd ( 70 , '0' ) ,
350351 }
351352 const data = new TestBlockBuilder ( block ) . addTx ( tx ) . build ( ) ;
352353 await db . update ( data ) ;
@@ -364,7 +365,7 @@ describe('Rosetta API', () => {
364365 hash : tx . tx_id ,
365366 } ,
366367 metadata : {
367- memo : '0x25463526 ' ,
368+ memo : 'test1234 ' ,
368369 } ,
369370 operations : [
370371 {
You can’t perform that action at this time.
0 commit comments