项目作者: mkbeh

项目描述 :
Async Bitcoin/forks JSON-RPC library
高级语言: Python
项目地址: git://github.com/mkbeh/aiobitcoin.git
创建时间: 2019-05-06T16:36:30Z
项目社区:https://github.com/mkbeh/aiobitcoin

开源协议:MIT License

下载


aiobitcoin


Python 3.6GitHub license
Documentation Status
GitHub issues

This is a library that provides methods for working
with Bitcoin/forks daemon JSON-RPC.

Also there are tools for working with bip32 hierarchical
deterministic wallets in this library . These tools were taken
from three different libraries such as
bitcoinlib,
btclib and
pycoin ,
because I had problems while importing keys and addresses
to the Bitcoin Core when working with each of them separately.

Examples

Documentation

NOTE #0: this lib works successful with Bitcoin Core 0.17.1 , other wallet versions not tested.

NOTE #1: At the moment, not all available methods are implemented in the library , only the most common.

Donate me if you like it :)

  1. Bitshares account -> mkbehforever007
  2. bitcoin -> bc1qqkr72aemz59aawxf74gytrwuw4m9mj20t7e7df
  3. ethereum -> 0xB3e5b643cFB9e2565a3456eC7c7A73491A32e31F

Supports

  • Basic methods for asynchronous work with Bitcoin/forks
    JSON-RPC
  • Mnemonic key generation
  • BIP32 hierarchical deterministic wallets

Installation

  1. sudo apt install python-dev python3-dev
  2. sudo apt install libssl-dev
  3. pip3 install aiobitcoin

Quickstart

Simple usage:

  1. import asyncio
  2. from aiobitcoin.blockchain import Blockchain
  3. async def foo():
  4. blockchain = Blockchain(url='http://alice:bob@127.0.0.1:18332')
  5. difficulty = await blockchain.get_difficulty()
  6. block_count = await blockchain.get_block_count()
  7. print(difficulty)
  8. print(block_count)
  9. await blockchain.close_session()
  10. ioloop = asyncio.get_event_loop()
  11. ioloop.run_until_complete(foo())

or use the same with context manager:

  1. import asyncio
  2. from aiobitcoin.blockchain import Blockchain
  3. async def foo():
  4. async with Blockchain(url='http://alice:bob@127.0.0.1:18332') as blockchain:
  5. difficulty = await blockchain.get_difficulty()
  6. block_count = await blockchain.get_block_count()
  7. print(difficulty)
  8. print(block_count)
  9. ioloop = asyncio.get_event_loop()
  10. ioloop.run_until_complete(foo())

Working with bip32

All keys can be imported without problems to Bitcoin Core.

  1. from aiobitcoin.tools import bip32
  2. from aiobitcoin.tools.bip32 import MAINNET_PRV, TESTNET_PRV
  3. from aiobitcoin.tools.key.Key import Key
  4. from aiobitcoin.mnemonic import Mnemonic
  5. # -- Generate mnemonic phrase --
  6. ceed = Mnemonic().generate(encoding=False)
  7. # ... Output: rebel swear tomorrow burger cave giraffe ...
  8. # -- Generate master keys from ceed for BTC mainnet and testnet --
  9. testnet_mxpriv = bip32.xmprv_from_seed(ceed, TESTNET_PRV)
  10. # ... Output: tprv8ZgxMBicQKsPe6tqMpq6qyzFoFSr3cgh...
  11. mainnet_mxpriv = bip32.xmprv_from_seed(ceed, MAINNET_PRV)
  12. # ... Output: xprv9s21ZrQH143K4Q9MazKYy5Kuck31yFeT...
  13. # -- Generate master public keys from master private key --
  14. testnet_mxpub = bip32.xpub_from_xprv(testnet_mxpriv)
  15. mainnet_mxpub = bip32.xpub_from_xprv(mainnet_mxpriv)
  16. # ... Output: tpubD6NzVbkrYhZ4X5ghC8mzzsGuMQCxEmnh5Y...
  17. # ... Output: xpub661MyMwAqRbcFHVqjwnunwwY2H7JFPHdXv...
  18. # -- Transform master private key to WIF format and getting address of master key --
  19. key = Key.from_text(mainnet_mxpriv)
  20. wif = key.wif()
  21. # ... Output: L4PEssMfRgHvmpyEGxHJkFVcNWeQvZiySNMAa...
  22. addr = key.address()
  23. # ... Output: 1BGLari4SCxGXoJib27C8pAL6Ef3pFqswD
  24. # -- Create sub key by custom derive path --
  25. subkey = key.subkey_for_path('1/0/{}'.format(11))
  26. addr = subkey.address(use_uncompressed=False)
  27. wif = subkey.wif()

Roadmap

  • Add all available methods to work with Bitcoin/forks JSON-RPC
  • Rewrite to async Key tool
  • Add DASH, LTC supporting