Skip to main content

The Swiss Army Knife of the Litecoin protocol.

Project description

python-litecoinlib

This Python3 library provides an easy interface to the litecoin data structures and protocol. The approach is low-level and "ground up", with a focus on providing tools to manipulate the internals of how litecoin works.

Requirements

sudo apt-get install libssl-dev

The RPC interface, litecoin.rpc, is designed to work with Litecoin Core v0.18. Older versions may work but there do exist some incompatibilities.

Structure

Everything consensus critical is found in the modules under litecoin.core. This rule is followed pretty strictly, for instance chain parameters are split into consensus critical and non-consensus-critical.

litecoin.core            - Basic core definitions, datastructures, and
                          (context-independent) validation
litecoin.core.key        - ECC pubkeys
litecoin.core.script     - Scripts and opcodes
litecoin.core.scripteval - Script evaluation/verification
litecoin.core.serialize  - Serialization

In the future the litecoin.core may use the Satoshi sourcecode directly as a library. Non-consensus critical modules include the following:

litecoin          - Chain selection
litecoin.base58   - Base58 encoding
litecoin.bloom    - Bloom filters (incomplete)
litecoin.net      - Network communication (in flux)
litecoin.messages - Network messages (in flux)
litecoin.rpc      - Litecoin Core RPC interface support
litecoin.wallet   - Wallet-related code, currently Litecoin address and
                   private key support

Effort has been made to follow the Satoshi source relatively closely, for instance Python code and classes that duplicate the functionality of corresponding Satoshi C++ code uses the same naming conventions: CTransaction, CBlockHeader, nValue etc. Otherwise Python naming conventions are followed.

Mutable vs. Immutable objects

Like the Litecoin Core codebase CTransaction is immutable and CMutableTransaction is mutable; unlike the Litecoin Core codebase this distinction also applies to COutPoint, CTxIn, CTxOut, and CBlock.

Endianness Gotchas

Rather confusingly Litecoin Core shows transaction and block hashes as little-endian hex rather than the big-endian the rest of the world uses for SHA256. python-litecoinlib provides the convenience functions x() and lx() in litecoin.core to convert from big-endian and little-endian hex to raw bytes to accommodate this. In addition see b2x() and b2lx() for conversion from bytes to big/little-endian hex.

Module import style

While not always good style, it's often convenient for quick scripts if import * can be used. To support that all the modules have __all__ defined appropriately.

Selecting the chain to use

Do the following:

import litecoin
litecoin.SelectParams(NAME)

Where NAME is one of 'testnet', 'mainnet', 'signet', or 'regtest'. The chain currently selected is a global variable that changes behavior everywhere, just like in the Satoshi codebase.

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

python-litecoinlib-0.12.0.dev0.tar.gz (58.5 kB view hashes)

Uploaded Source

Built Distribution

python_litecoinlib-0.12.0.dev0-py3-none-any.whl (65.9 kB view hashes)

Uploaded Python 3

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