Django: Ripple API app.

42 Coffee Cups have published an application that helps to work with API of Ripple in Django. We use it on production but it's still beta or even alpha so feel free to create issues on github.

Main developers are jetmind and Kostya Shish. And I just ripped it from our project to make standalone reusable app.

Install it as usual Django app:
  1. Install it into your environment (e.g. with pip):

    pip install django-ripple_api==0.0.2
  2. Add app to
    settings.INSTALLED_APPS:


    INSTALLED_APPS = (
        # ...
        'ripple_api',
        # ...
    )
    
  3. Add API auth info to settings:

    RIPPLE_API_URL = 'http://s_west.ripple.com:51234' 
    
    RIPPLE_API_USER = 'api_user'  # some api servers require additional auth. Set username if server needs it
    
    RIPPLE_API_PASSWORD = 'api_password'  # some api servers require additional auth. Set password if server needs it
    
    RIPPLE_ACCOUNT = 'rnAoa45cMnBQb85mUnPep2yeJAvUtToCiL'
    
    RIPPLE_SECRET = 'some_secret_of_RIPPLE_ACCOUNT'
    
Now you can use it:
  1. Now you can send transactions and get info about existing transactions:

    from ripple_api.ripple_api import sign, submit, account_tx, tx
    
    import pprint 
    
    
    pp = pprint.PrettyPrinter(indent=1)
    pp.pprint(tx_info)
    
    
    # get info on account transactions:
    account_tx('rNMW2mJHowD6d4KUvm2XXXXXXXXXXXXX')
    
    # {u'status': u'success', u'ledger_index_max': 5841226, u'account': rNMW2mJHowD6d4KUvm2XXXXXXXXXXXXX', u'transactions': [], u'ledger_index_min': 5841221}
    
    
    # get info about specific transaction:
    tx_info = tx('41C03F1A6CD2B7B11118C85A964AEA0364EDC10E1990FBD8A17946XXXXXXXX')
    pp.pprint(tx_info)
    # {u'Account': rNMW2mJHowD6d4KUvm2XXXXXXXXXXXXX',
    #  u'Amount': {u'currency': u'XXX',
    #              u'issuer': u'rBeToNo4AwHaNbXXXXXXXXXXXXXXXX',
    #              u'value': u'0.2'},
    #  u'Destination': u'rBeToNo4AXXXXXXXXXXXXXXXXXX',
    #  u'DestinationTag': 4060,
    #  ...
    #  u'meta': {u'AffectedNodes': [{u'ModifiedNode': {u'FinalFields': {u'Balance': {u'currency': u'XXX',
    # ...
    #            u'TransactionIndex': 0,
    #            u'TransactionResult': u'tesSUCCESS'},
    #  u'status': u'success',
    #  u'validated': True}
    
    
    # to send transaction you need to sign it first:
    sign_response = sign(
        'rNMW2mJHowD6d4KUvm23v3XkkDnatt5F1q', 'my_top_secret', 
        destination='some_other_ripple_account',
        amount={
            "currency" : currency,
            "value" : string,
            "issuer" : account_id,
        }
    )
    
    
    # Now you can submit it:
    submit_response = submit(sign_response['tx_blob'])
    
    if submit_response['engine_result'] in ["tesSUCCESS",  "tefPAST_SEQ"]:
        print('Congrats! Transaction is being processed by rippled! Check it later')
    
    
    # later you need to check this transaction:
    tx_info = tx(submit_response['tx_json']['hash'])
    
    if response.get('meta', {}).get('TransactionResult') == 'tesSUCCESS':
        print('You transaction was processed!')
    
  2. There is a model to save transaction information in DB:
    from ripple_api.models import Transaction
    
    amount = tx_info.get('Amount', {})
    
    destination_tag = tx_info.get('DestinationTag')
    
    source_tag = tx_info.get('SourceTag')
    
    transaction_object = Transaction.objects.create(
        account=tx_info['Account'], hash=tx_info['hash'],
        destination=settings.RIPPLE_ACCOUNT,
        ledger_index=tx_info['ledger_index'],
        destination_tag=destination_tag,
        source_tag=source_tag, status=Transaction.RECEIVED,
        currency=amount['currency'],
        issuer=amount['issuer'], value=amount['value']
    )
    
    If you have some transactions with status Transaction.SUBMITTED or Transaction.FAILED, than you can run manage command `process_transactions` that will try to resend failed transaction and check status of submited ones.
  3. There are also celery tasks to work with ripple_api.models.Transaction:
    1. ripple_api.tasks.sign_task(transaction, secret)
    2. ripple_api.tasks.submit_task(transaction)

    Example usage:
    sign_task.apply((transaction, settings.RIPPLE_SECRET), link=submit_task.s())

What's planned:
  • Support to work multiple API servers in case of connection errors.
  • Support to work without Django.
  • Class method for
    Transaction
    model to create instances from results of
    tx(transaction_id='xxxx')
    .
  • ???