XRPLF / xrpl.js

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

getTransaction of CheckCreate should report Check ID #876

Closed mDuo13 closed 5 years ago

mDuo13 commented 6 years ago

One of the most important things to know about a CheckCreate transaction is the ID of the Check object created in the ledger data as a result of the transaction. In fact, you need this value to cash or redeem the check. It appears there is not currently a documented way to get the checkID using RippleAPI.

The getTransaction() method of RippleAPI does not expose this information in a useful way when looking up a Check. For example, logging the response from a getTransaction() request (for a CheckCreate transaction with hash C0B27D20669BAB837B3CDF4B8148B988F17CE1EF8EDF48C806AE9BF69E16F441 on the Test Net) returns this (with v0.19.0):

{ type: 'checkCreate',
  address: 'rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za',
  sequence: 2,
  id: 'C0B27D20669BAB837B3CDF4B8148B988F17CE1EF8EDF48C806AE9BF69E16F441',
  specification: 
   { destination: 'rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis',
     sendMax: { currency: 'XRP', value: '100' } },
  outcome: 
   { result: 'tesSUCCESS',
     timestamp: '2018-03-27T20:47:40.000Z',
     fee: '0.000012',
     balanceChanges: { rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za: [Array] },
     orderbookChanges: {},
     ledgerVersion: 7835887,
     indexInLedger: 0 } }

I suggest the outcome object in the getTransaction response should add an optional field, checkID with the ID of the created Check object if the transaction created one.

To find this value, you'll have to page through the AffectedNodes to find a CreatedNode element with "LedgerEntryType": "Check" and pull out the LedgerIndex value from that element. Here's an example from the metadata of that same transaction:

{
  "CreatedNode": {
    "LedgerEntryType": "Check",
    "LedgerIndex": "84C61BE9B39B2C4A2267F67504404F1EC76678806C1B901EA781D1E3B4CE0CD9",
    "NewFields": {
      "Account": "rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za",
      "Destination": "rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis",
      "DestinationTag": 1,
      "InvoiceID": "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
      "SendMax": "100000000",
      "Sequence": 4
    }
  }
},
mDuo13 commented 6 years ago

I believe that Payment Channels have the same problem. The response for PaymentChannelCreate could include a similar field. (The RippleAPI paymentChannelClaim and paymentChannelFund objects require the ID in the channel field.)

intelliot commented 6 years ago

Thank you for bringing this up!

The way I've been doing it so far is by sending the raw account_objects command (mentioned by Fred here). Adding first-class support for account_objects is in progress.

I've also been able to calculate the CheckID "offline" according to the documented format. For the example you posted:

> hashes.addressToHex('rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za').toUpperCase()
'735FF88E5269C80CD7F7AF10530DAB840BBF6FDF'
> hashes.hash('0043735FF88E5269C80CD7F7AF10530DAB840BBF6FDF00000004')
'84C61BE9B39B2C4A2267F67504404F1EC76678806C1B901EA781D1E3B4CE0CD9'

I like the idea of also returning the value with getTransaction.

intelliot commented 6 years ago

0.21.0 (2018-04-11) added getAccountObjects which includes Check IDs.

We can keep this issue open until I look into adding a method for generating CheckIDs offline.

intelliot commented 5 years ago

There's not much demand for generating CheckIDs offline, but it's something that could be added fairly easily if anyone wants it (create a new issue if that's the case). Closing.