Browsed by
Category: python

Using ripple api to query network and address information

Using ripple api to query network and address information

Hey Everyone,

This will be a quick post.

It’s been awhile since I made a post on some of the interesting challenges I’ve faced on my side projects. This is a continuation of my blockchain restapi work first mentioned here: dash-node-error.

Not just limiting myself to running nodes, I wanted to experiment with using existing apis. I started off with the Ripple (XRP) api. The main two pieces of information I needed from the chain were a list of transactions and an address’ balance.

Perusing through the api, there appeared to be two existing apis that would suit my needs:

Get Account Balances - GET /v2/accounts/{:address}/balances
Get Account Transaction History - GET /v2/accounts/{:address}/transactions

The balances endpoint worked as expected. Below is an example url and response:

   URL: https://data.ripple.com/v2/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/balances?currency=USD

   {
      "result": "success",
      "ledger_index": ,
      "limit": 200,
      "balances": [
        {
          "currency": "XRP",
          "value": "200"
        },
      ]
   }

The transactions endpoint; however, had incomplete data. Example url:

https://data.ripple.com/v2/accounts//transactions?type=Payment

I noticed the transaction inputs did not add up to the account balance. After a bit of digging, the only thing I was able to find was that transactions were missing from exchanges that used sidechains. The solution for me was to merge data from the /payments endpoint. This allowed transaction data to mirror balances.

   URL: https://data.ripple.com/v2/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/payments?currency=USD

   {
      "result": "success",
      "count": 3,
      "marker": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn|20140910232220|000008803725|00001",
      "payments": [
       {
         "amount": "1.0",
         "delivered_amount": "1.0",
         "destination_balance_changes": [
          {
             "counterparty": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
             "currency": "USD",
             "value": "1"
           }
         ],
         "source_balance_changes": [
           {
             "counterparty": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX",
             "currency": "USD",
             "value": "-1"
           }
         ],
         "tx_index": 1,
         "currency": "USD",
         "destination": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX",
         "executed_time": "2014-06-02T22:47:50Z",
         "issuer": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
         "ledger_index": 6979192,
         "source": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
         "source_currency": "USD",
         "tx_hash": "7BF105CFE4EFE78ADB63FE4E03A851440551FE189FD4B51CAAD9279C9F534F0E",
         "transaction_cost": "1.0E-5"
       } 
      ]
   }