Skip to main content

Bitcoincash Module for XChainPy Clients

Project description

xchainpy/xchain-bitcoincash

Bitcoin-Cash Module for XChainPy Clients

Modules

  • client - Custom client for communicating with bitcash , haskoin api
  • models - Model wrapper for bitcoin-cash and haskoin required types
  • util - Utitilies for using bitcash and haskoin

Following dependencies have to be installed into your project

bitcash - cashaddress - mnemonic - bip_utils

Service Providers

This package uses the following service providers:

Function Service Notes
Balances Haskoin https://api.haskoin.com/#/Address/getBalance
Transaction history Haskoin https://api.haskoin.com/#/Address/getAddressTxsFull
Transaction details by hash Haskoin https://api.haskoin.com/#/Transaction/Transaction
Transaction fees Bitgo https://app.bitgo.com/docs/#operation/v2.tx.getfeeestimate
Transaction broadcast bitcore.io https://api.bitcore.io
Explorer Blockchain.com https://www.blockchain.com

Haskoin API rate limits: No

Bitgo API rate limits: https://app.bitgo.com/docs/#section/Rate-Limiting (10 requests/second)

Installation

pip install xchainpy_bitcoincash

Before install the package on M1 Mac, execute these commands:

brew install gmp openblas openssl autoconf automake libffi libtool pkg-config

CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib pip3 install fastecdsa

CFLAGS=-I$(brew --prefix openssl)/include LDFLAGS=-L$(brew --prefix openssl)/lib pip3 install scrypt

export OPENBLAS="$(brew --prefix openblas) $OPENBLAS"

Bitcoincash Client module

Initialize a client

from xchainpy_client.models.types import Network
from xchainpy_bitcoincash.client import Client
from xchainpy_bitcoincash.models.client_types import BitcoincashClientParams

# Note: This phrase is created by https://iancoleman.io/bip39/ and will never been used in a real-world
phrase = 'atom green various power must another rent imitate gadget creek fat then'
client = Client(BitcoincashClientParams(phrase=phrase, network=Network.Testnet))

# if you want to change phrase after initialize the client
client.set_phrase('caution pear excite vicious exotic slow elite marble attend science strategy rude')

# if you want to change network after initialize the client
client.purge_client()
client.set_network(Network.Mainnet)

# when you are done with the client, call this
client.purge_client()

Address methods

from xchainpy_client.models.types import Network
from xchainpy_bitcoincash.client import Client
from xchainpy_bitcoincash.models.client_types import BitcoincashClientParams

phrase = 'atom green various power must another rent imitate gadget creek fat then'
client = Client(BitcoincashClientParams(phrase=phrase, network=Network.Testnet))

address = client.get_address()
is_valid = client.validate_address(address) # bool
print(address)
print(is_valid)

# change index
address = client.get_address(1)
is_valid = client.validate_address(address) # bool
print(address)
print(is_valid)

Fees

from xchainpy_bitcoincash.client import Client
from xchainpy_bitcoincash.models.client_types import BitcoincashClientParams

client = Client(BitcoincashClientParams())

# Get feeRate estimations
fee_rates = await client.get_fee_rates()

# Get fee estimations
fees = await client.get_fees()

# Get fee estimations with memo
memo = 'SWAP:THOR.RUNE'
fees_with_memo = await client.get_fees(memo)


print(f'''fee rates: 
average: {fee_rates.average}
fast: {fee_rates.fast}
fastest: {fee_rates.fastest}\n''')

print(f'''fees: 
average: {fees.average}
fast: {fees.fast}
fastest: {fees.fastest}\n''')

print(f'''fees with memo: 
average: {fees_with_memo.average}
fast: {fees_with_memo.fast}
fastest: {fees_with_memo.fastest}\n''')

Balance

from xchainpy_client.models.types import Network
from xchainpy_bitcoincash.client import Client
from xchainpy_bitcoincash.models.client_types import BitcoincashClientParams

phrase = 'atom green various power must another rent imitate gadget creek fat then'
client = Client(BitcoincashClientParams(phrase=phrase, network=Network.Testnet))

address = client.get_address()

balance = await client.get_balance(address=address)
balance = balance[0]

print(f'asset: {balance.asset}, amount: {balance.amount}')

Transactions and Transaction_data

from xchainpy_client.models.tx_types import TxHistoryParams
from xchainpy_client.models.types import Network
from xchainpy_bitcoincash.client import Client
from xchainpy_bitcoincash.models.client_types import BitcoincashClientParams

phrase = 'atom green various power must another rent imitate gadget creek fat then'
client = Client(BitcoincashClientParams(phrase=phrase, network=Network.Testnet))

address = client.get_address()

params = TxHistoryParams(address=address, limit=1)
transactions = await client.get_transactions(params)
# type of transactions is xchainpy_client.models.tx_types.TxPage

t = transactions.txs[0]
print(t.asset)
print(t.tx_from[0].amount)
print(t.tx_from[0].address)
print(t.tx_to[0].amount)
print(t.tx_to[0].address)
print(t.tx_date)
print(t.tx_type)
print(t.tx_hash)

transaction = await client.get_transaction_data(t.tx_hash)
# transaction object is equal by t object

Transfer

from xchainpy_client.models.types import Network
from xchainpy_bitcoincash.client import Client
from xchainpy_bitcoincash.models.client_types import BitcoincashClientParams, BitcoincashTxParams

phrase = 'atom green various power must another rent imitate gadget creek fat then'
client = Client(BitcoincashClientParams(phrase=phrase, network=Network.Testnet))

address = client.get_address()

params = BitcoincashTxParams(amount=0.0000001, recipient=address, memo='memo')
tx_hash = await client.transfer(params)

print(tx_hash)

Explorer url

from xchainpy_client.models.types import Network
from xchainpy_bitcoincash.client import Client
from xchainpy_bitcoincash.models.client_types import BitcoincashClientParams

client = Client(BitcoincashClientParams())

print(client.get_explorer_url())
print(client.get_explorer_address_url('testAddressHere'))
print(client.get_explorer_tx_url('testTxHere'))

client.purge_client()
client.set_network(Network.Mainnet)

print(client.get_explorer_url())
print(client.get_explorer_address_url('testAddressHere'))
print(client.get_explorer_tx_url('testTxHere'))

Tests

These packages needed to run tests:

  • pytest pip install pytest
  • pytest-asyncio pip install pytest-asyncio

How to run test ?

$ python -m pytest xchainpy/xchainpy_bitcoincash/tests

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

xchainpy_bitcoincash-0.2.3.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

xchainpy_bitcoincash-0.2.3-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file xchainpy_bitcoincash-0.2.3.tar.gz.

File metadata

  • Download URL: xchainpy_bitcoincash-0.2.3.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

File hashes

Hashes for xchainpy_bitcoincash-0.2.3.tar.gz
Algorithm Hash digest
SHA256 a1519182464eda60d9e4289739da8005d6b8dfa085b8c07e627ce8d0d05043e2
MD5 74dd6979d1cb834e04d7667dcbd1a5fc
BLAKE2b-256 e30cced173043535d535e36d55bcab5aa8765912f886ef7ece81efd0afe61511

See more details on using hashes here.

File details

Details for the file xchainpy_bitcoincash-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: xchainpy_bitcoincash-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

File hashes

Hashes for xchainpy_bitcoincash-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5826b7b1f3de3c3f9eb0ece34ba5971703e28c15147ebf95c9aa605a1c7cc935
MD5 c3cf32433433b77cf939e849cebb5311
BLAKE2b-256 53522ce3baab7324c3ad34c6a99bd7b9e633bf789bb39a3d0c764b6f198cbcf7

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