Skip to main content

No project description provided

Project description

The Xpring SDK for Python.

Build status: Linux and OSX Build status: Windows Documentation status Latest PyPI version Python versions supported

Install

pip install xpring[py]

API

Wallet

Construct

You can construct a Wallet from its seed. If you do not have your own wallet yet, you can generate one with some free XRP on the testnet.

import xpring

seed = 'sEdSKaCy2JT7JaM7v95H9SxkhP9wS2r'
wallet = xpring.Wallet.from_seed(seed)
print(wallet.private_key.hex())
# b4c4e046826bd26190d09715fc31f4e6a728204eadd112905b08b14b7f15c4f3
print(wallet.public_key.hex())
# ed01fa53fa5a7e77798f882ece20b1abc00bb358a9e55a202d0d0676bd0ce37a63
print(wallet.account_id.hex())
# d28b177e48d9a8d057e70f7e464b498367281b98
print(wallet.address)
# rLUEXYuLiQptky37CqLcm9USQpPiz5rkpD

Sign / Verify

A Wallet can sign and verify arbitrary bytes, but you’ll generally want to leave these low-level responsibilities to the Client.

message = bytes.fromhex('DEADBEEF')
signature = wallet.sign(message)
wallet.verify(message, signature)
# True

Client

Client is the gateway to the XRP Ledger. It is constructed with the URL of the gRPC service of a rippled server. If you are running the server yourself, you need to configure the [port_grpc] stanza in your configuration file. In the example configuration file, it is commented out.

url = 'localhost:50051'
client = xpring.Client.from_url(url)

Account

>>> client.get_account(wallet.address)
account_data {
  account {
    value {
      address: "rDuKotkyx18D5WqWCA4mVhRWK2YLqDFKaY"
    }
  }
  balance {
    value {
      xrp_amount {
        drops: 999999820
      }
    }
  }
  sequence: {
    value: 10
  }
  flags {
  }
  owner_count {
  }
  previous_transaction_id {
    value: b"..."
  }
  previous_transaction_ledger_sequence {
    value: 4845872
  }
}
ledger_index: 4869818

Fee

>>> client.get_fee()
current_ledger_size: 6
fee {
  base_fee {
    drops: 10
  }
  median_fee {
    drops: 5000
  }
  minimum_fee {
    drops: 10
  }
  open_ledger_fee {
    drops: 10
  }
}
expected_ledger_size: 25
ledger_current_index: 4869844
levels {
  median_level: 128000
  minimum_level: 256
  open_ledger_level: 256
  reference_level: 256
}
max_queue_size: 2000

Submit

>>> unsigned_transaction = {
...     'Account': 'rDuKotkyx18D5WqWCA4mVhRWK2YLqDFKaY',
...     'Amount': '10',
...     'Destination': 'rNJDvXkaBRwJYdeEcx9pchE2SecMkH3FLz',
...     'Fee': '10',
...     'Flags': 0x80000000,
...     'Sequence': 9,
...     'TransactionType': 'Payment'
... }
>>> signed_transaction = wallet.sign_transaction(unsigned_transaction)
>>> client.submit(signed_transaction)
engine_result {
  result_type: RESULT_TYPE_TES
  result: "tesSUCCESS"
}
engine_result_message: "The transaction was applied. Only final in a validated ledger."
hash: b"..."
>>> client.submit(signed_transaction)
engine_result {
  result_type: RESULT_TYPE_TEF
  result: "tefPAST_SEQ"
}
engine_result_code: -190
engine_result_message: "This sequence number has already passed."
hash: b"..."

Transaction

>>> txid = bytes.fromhex(signed_transaction['hash'])
>>> client.get_transaction(txid)
transaction {
  account {
    value {
      address: "rDuKotkyx18D5WqWCA4mVhRWK2YLqDFKaY"
    }
  }
  fee {
    drops: 10
  }
  sequence {
    value: 10
  }
  payment {
    amount {
      value {
        xrp_amount {
          drops: 10
        }
      }
    }
    destination {
      value {
        address: "rNJDvXkaBRwJYdeEcx9pchE2SecMkH3FLz"
      }
    }
  }
  signing_public_key {
    value: b"..."
  }
  transaction_signature {
    value: b"..."
  }
  flags {
    value: 2147483648
  }
}
ledger_index: 5124377
hash: b"..."
validated: true
meta {
  transaction_index: 1
  transaction_result {
    result_type: RESULT_TYPE_TES
    result: "tesSUCCESS"
  }
  affected_nodes {
    ledger_entry_type: LEDGER_ENTRY_TYPE_ACCOUNT_ROOT
    ledger_index: b"..."
    modified_node {
      final_fields {
        account_root {
          account {
            value {
              address: "rNJDvXkaBRwJYdeEcx9pchE2SecMkH3FLz"
            }
          }
          balance {
            value {
              xrp_amount {
                drops: 1000000100
              }
            }
          }
          sequence {
            value: 1
          }
          flags {
          }
          owner_count {
          }
        }
      }
      previous_fields {
        account_root {
          balance {
            value {
              xrp_amount {
                drops: 1000000090
              }
            }
          }
        }
      }
      previous_transaction_id {
        value: b"..."
      }
      previous_transaction_ledger_sequence {
        value: 4845872
      }
    }
  }
  affected_nodes {
    ledger_entry_type: LEDGER_ENTRY_TYPE_ACCOUNT_ROOT
    ledger_index: b"..."
    modified_node {
      final_fields {
        account_root {
          account {
            value {
              address: "rDuKotkyx18D5WqWCA4mVhRWK2YLqDFKaY"
            }
          }
          balance {
            value {
              xrp_amount {
                drops: 999999800
              }
            }
          }
          sequence {
            value: 11
          }
          flags {
          }
          owner_count {
          }
        }
      }
      previous_fields {
        account_root {
          balance {
            value {
              xrp_amount {
                drops: 999999820
              }
            }
          }
          sequence {
            value: 10
          }
        }
      }
      previous_transaction_id {
        value: b"..."
      }
      previous_transaction_ledger_sequence {
        value: 4845872
      }
    }
  }
  delivered_amount {
    value {
      xrp_amount {
        drops: 10
      }
    }
  }
}
date {
  value: 636581642
}

Develop

Dependencies

The protocol buffers and definitions file are in submodules:

git submodule update --init

Use Poetry to install dependencies, build the protocol buffers, and copy the definitions file:

poetry install
poetry run invoke prebuild

Tasks

There are several Invoke tasks:

poetry run invoke ${task}
  • test: Pytest with coverage and doctests.

  • lint: Mypy, Pylint, and Pydocstyle.

  • serve: Serve the docs locally and rebuild them on file changes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xpring-0.4.1.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

xpring-0.4.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file xpring-0.4.1.tar.gz.

File metadata

  • Download URL: xpring-0.4.1.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.7.1 Linux/5.3.0-40-generic

File hashes

Hashes for xpring-0.4.1.tar.gz
Algorithm Hash digest
SHA256 1616e6b03317ff92a0290327db875977ce36557025350d268b8eb1eddd200cc6
MD5 90ad7157c7ae64b6bacca8c73edc46e1
BLAKE2b-256 38ed6031d58051cb9f5237c0b696700d5c6a87eaf85255029ed122a0ab8eecc1

See more details on using hashes here.

File details

Details for the file xpring-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: xpring-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.7.1 Linux/5.3.0-40-generic

File hashes

Hashes for xpring-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4368c77d12ecf56b84d918a69594a1053a9f2bc1dd8d29906f29c78bb71ae426
MD5 51fa8fed64b6e528156507075684b3d0
BLAKE2b-256 4e2728ca30e9916750e0eab99b9eed84d9524d31d605f886866fdcfbbe742251

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page