XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 510 forks source link

Memo not included in FormattedTransactionType #1353

Closed wujood closed 3 years ago

wujood commented 3 years ago

It seems that the transaction object is missing the memo data. When i request a transaction with includeRawTransaction it is however included inside the rawTransaction Object.

{
  type: 'order',
  address: 'rfrCsX1gzVLvXzmgDxTYUWp96Ri6m61qtH',
  sequence: 61349002,
  id: '995570FE1E40F42DF56BFC80503BA9E3C1229619C61A1C279A76BC0805036D73',
  specification: {
    direction: 'buy',
    quantity: {
      currency: 'NRD',
      value: '0.1',
      counterparty: 'rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R'
    },
    totalPrice: { currency: 'XRP', value: '1' }
  },
  outcome: {
    result: 'tesSUCCESS',
    timestamp: '2021-02-05T04:22:41.000Z',
    fee: '0.000012',
    balanceChanges: {
      rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R: [Array],
      rfrCsX1gzVLvXzmgDxTYUWp96Ri6m61qtH: [Array]
    },
    orderbookChanges: { rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R: [Array] },
    ledgerVersion: 61369884,
    indexInLedger: 0
  },
  rawTransaction: '{"Account":"rfrCsX1gzVLvXzmgDxTYUWp96Ri6m61qtH","Fee":"12","Flags":2147483648,"LastLedgerSequence":61369885,"Memos":[{"Memo":{"MemoData":"3732363536653734","MemoType":"3638373437343730336132663266363537383631366437303663363532653633366636643266366436353664366632663637363536653635373236393633"}}],"Sequence":61349002,"SigningPubKey":"0328B3B4516379D13340C12D303EB89EB27301B6EB59F37BE23046845E00880BFE","TakerGets":"1000000","TakerPays":{"currency":"NRD","issuer":"rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R","value":"0.1"},"TransactionType":"OfferCreate","TxnSignature":"304402206F1CF60223113DE36479736EE0AB9165734F98D6A2DB4B0B2BFCFC02ACAABE1902202E52A62BEE554E5988F79CEE1EEF83D8B66374B9EC539328A132207D927BDDFC","date":665814161,"hash":"995570FE1E40F42DF56BFC80503BA9E3C1229619C61A1C279A76BC0805036D73","inLedger":61369884,"ledger_index":61369884,"meta":{"AffectedNodes":[{"ModifiedNode":{"FinalFields":{"Account":"rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R","Balance":"53527227","Flags":0,"OwnerCount":1,"Sequence":61350142},"LedgerEntryType":"AccountRoot","LedgerIndex":"17D5C0493F006ECB3748EE5BC72D0FDFB4747DE23B57C3735E281B2DDCBEEEFF","PreviousFields":{"Balance":"53517227"},"PreviousTxnID":"BA34BA8650E5BD681B6BD28A5E366084FDCA2919FD734E9BAF5FE636465EB246","PreviousTxnLgrSeq":61369855}},{"ModifiedNode":{"FinalFields":{"Balance":{"currency":"NRD","issuer":"rrrrrrrrrrrrrrrrrrrrBZbvji","value":"0.40001"},"Flags":3211264,"HighLimit":{"currency":"NRD","issuer":"rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R","value":"0"},"HighNode":"0000000000000000","LowLimit":{"currency":"NRD","issuer":"rfrCsX1gzVLvXzmgDxTYUWp96Ri6m61qtH","value":"0"},"LowNode":"0000000000000000"},"LedgerEntryType":"RippleState","LedgerIndex":"29A9FBE62D9080A572B2D48DBCC5BEE8657F9ACBAFDE2ADC44C34C67F6321717","PreviousFields":{"Balance":{"currency":"NRD","issuer":"rrrrrrrrrrrrrrrrrrrrBZbvji","value":"0.30001"}},"PreviousTxnID":"BA34BA8650E5BD681B6BD28A5E366084FDCA2919FD734E9BAF5FE636465EB246","PreviousTxnLgrSeq":61369855}},{"ModifiedNode":{"FinalFields":{"Account":"rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R","BookDirectory":"11DD28D0009D3C92445F21E79CAD5E9AD0B5FDB9000B3D4B5A038D7EA4C68000","BookNode":"0000000000000000","Flags":131072,"OwnerNode":"0000000000000000","Sequence":61350140,"TakerGets":{"currency":"NRD","issuer":"rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R","value":"99999.6"},"TakerPays":"9999960000"},"LedgerEntryType":"Offer","LedgerIndex":"48B893DA593D08FCDE5B1307D3798C505A2F6DB1494F59BCDF25232E72E26BB8","PreviousFields":{"TakerGets":{"currency":"NRD","issuer":"rGaZKAxMDhsSHvB51toY3YxGoPLhaX6Y5R","value":"99999.7"},"TakerPays":"9999970000"},"PreviousTxnID":"BA34BA8650E5BD681B6BD28A5E366084FDCA2919FD734E9BAF5FE636465EB246","PreviousTxnLgrSeq":61369855}},{"ModifiedNode":{"FinalFields":{"Account":"rfrCsX1gzVLvXzmgDxTYUWp96Ri6m61qtH","Balance":"25709939","Flags":0,"OwnerCount":1,"Sequence":61349003},"LedgerEntryType":"AccountRoot","LedgerIndex":"C3EBF1D11573A550EF5660C9A3AF00B1BC7EE7D9F9CDE3351539DDEC1A43F2A1","PreviousFields":{"Balance":"25719951","Sequence":61349002},"PreviousTxnID":"BA34BA8650E5BD681B6BD28A5E366084FDCA2919FD734E9BAF5FE636465EB246","PreviousTxnLgrSeq":61369855}}],"TransactionIndex":0,"TransactionResult":"tesSUCCESS"},"validated":true}'
}

Minimalistic code to reproduce:

const api = new RippleAPI({
  server: 'wss://s2.ripple.com' // Public rippled server
});
api.connect().then( async () => {
    const transaction = await api.getTransaction("995570FE1E40F42DF56BFC80503BA9E3C1229619C61A1C279A76BC0805036D73", {includeRawTransaction: true});
    console.log(transaction);
    api.disconnect();
}).catch(console.error);
wujood commented 3 years ago

For now i worked around this issue by parsing the rawTransaction myself and access the Memos from there.

const api = new RippleAPI({
  server: 'wss://s2.ripple.com' // Public rippled server
});
api.connect().then( async () => {
    const transaction = await api.getTransaction("995570FE1E40F42DF56BFC80503BA9E3C1229619C61A1C279A76BC0805036D73", {includeRawTransaction: true});
    const parsedRawTransaction = JSON.parse(transaction.rawTransaction);
    const memosFromTransaction = parsedRawTransaction .Memos;
    console.log("==== Memos ====")
    console.log(memosFromTransaction);
    api.disconnect();
}).catch(console.error);

This is of course a very expensive procedure especially in the case where you want to parse all transactions that a wallet made to scan for memos... Am i missing something here? Relativly new to this sdk.

wujood commented 3 years ago

Upon further inspection the object that is used to represent a transaction is the FormattedTransactionType in src/transaction/types.ts. https://github.com/ripple/ripple-lib/blob/c9689ec2a8ab8765c3407d144225119e42ce921b/src/transaction/types.ts#L158-L163 https://github.com/ripple/ripple-lib/blob/c9689ec2a8ab8765c3407d144225119e42ce921b/src/transaction/types.ts#L113-L120 Since i am new to the ripple sdk i would guess it is not enough to just add the memo object to these types.

ghost commented 3 years ago

Well since I'm mostly used to a bit of HTML 4 sadly I'm just copying a few projects to see how much I can manage to understand. But if you think you can undo the damage Ive done be my guest