{ "info": { "author": "Sergi Delgado-Segura and Cristina P\u00e9rez-Sol\u00e0", "author_email": "sdelgado@deic.uab.cat, cperez@deic.uab.cat", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2 :: Only" ], "description": "![bitcoin_tools](https://srgi.me/assets/images/bitcoin_tools_logo.png)\n\n\n[![Mentioned in Awesome](https://awesome.re/mentioned-badge.svg)](https://github.com/igorbarinov/awesome-bitcoin)\n\nbitcoin_tools is a Python library created for teaching and researching purposes. It's main objective is twofold. First it \naims to ease the understanding of Bitcoin transaction creation, by using well-documented and easy to understand\npython code. Second, it aims to provide a tool able to create custom `transactions` / `scripts`. Either `scriptSig` and \n`scriptPubKey` can be built from human readable strings created using `Script` syntax. Finally, tools for accessing and \nanalysing interesting data such as the `utxo set` are also provided, along with several examples.\n\nbitcoin_tools allows you to:\n\n* Bitcoin keys creation and management.\n* Creation of Bitcoin transactions from scratch.\n* Customize any field of your transaction.\n* Transaction serialization / deserialization.\n* Creation of standard and custom scripts (`scriptSig` and `scriptPubKey`).\n* Transaction analysis from hex encoded transactions.\n\nAdditionally, bitcoin_tools contains ``STATUS`` an\n**ST**atistical **A**nalysis **T**ool for **U**txo **S**et under [`analysis/status`](bitcoin_tools/analysis/status)\n\n### Dependencies\n\nRefer to [DEPENCENCIES.md](DEPENDENCIES.md)\n\n### Installation\n\nRefer to [INSTALL.md](INSTALL.md)\n\n### Some trouble getting started with the repo?\n\nRefer to [FAQ.md](FAQ.md)\n\n### Still not working?\n\nFeel free to open an issue.\n\n### Examples\n\nDown below you can find some examples of how to use some of the library functions. More examples can be found in \n[`examples/`](examples/)\n\n#### Key management and Bitcoin address generation\n```python\nfrom bitcoin_tools.core.keys import generate_keys, store_keys\nfrom bitcoin_tools.wallet import generate_wif, generate_btc_addr\n\n# First of all the ECDSA keys are generated.\nsk, pk = generate_keys()\n# Then, the Bitcoin address is derived from the public key created above.\nbtc_addr = generate_btc_addr(pk)\n# Both the public and private key are stored in disk in pem format. The Bitcoin address is used as an identifier in the\n# name of the folder that contains both keys.\nstore_keys(sk.to_pem(), pk.to_pem(), btc_addr)\n# Finally, the private key is encoded as WIF and also stored in disk, ready to be imported in a wallet.\ngenerate_wif(btc_addr, sk)\n```\n\n#### Raw transaction building \n```python\nfrom bitcoin_tools.core.keys import load_keys\nfrom bitcoin_tools.core.transaction import TX\n\n# Key loading\nbtc_addr = \"miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t\"\nsk, pk = load_keys(btc_addr)\n\n# Reference to the previous transaction output that will be used to redeem and spend the funds, consisting on an id and\n# an output index.\nprev_tx_id = \"7767a9eb2c8adda3ffce86c06689007a903b6f7e78dbc049ef0dbaf9eeebe075\"\nprev_out_index = 0\n\n# Amount to be spent, in Satoshis, and the fee to be deduced (should be calculated).\nvalue = 6163910\nfee = 230 * 240\n\n# Destination Bitcoin address where the value in bitcoins will be sent and locked until the owner redeems it.\ndestination_btc_addr = \"miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t\"\n\n# First, we build our transaction from io (input/output) using the previous transaction references, the value, and the\n# destination.\ntx = TX.build_from_io(prev_tx_id, prev_out_index, value - fee, destination_btc_addr)\n# Finally, the transaction is signed using the private key associated with the Bitcoin address from each input.\n# Input 0 will be signed, since we have only created one.\ntx.sign(sk, 0)\n\n# Once created we can display the serialized transaction. Transaction is now ready to be broadcast.\nprint \"hex: \" + tx.serialize()\n\n# Finally, we can analyze each field of the transaction.\ntx.display()\n```\n#### Raw tx analysis\n\n```python\nfrom bitcoin_tools.core.transaction import TX\n\n# First a transaction object is created (through the deserialize constructor) by deserializing the hex transaction we\n# have selected.\nhex_tx = \"01000000013ca58d2f6fac36602d831ee0cf2bc80031c7472e80a322b57f614c5ce9142b71000000006b483045022100f0331d85cb7f7ec1bedc41f50c695d654489458e88aec0076fbad5d8aeda1673022009e8ca2dda1d6a16bfd7133b0008720145dacccb35c0d5c9fc567e52f26ca5f7012103a164209a7c23227fcd6a71c51efc5b6eb25407f4faf06890f57908425255e42bffffffff0241a20000000000001976a914e44839239ab36f5bc67b2079de00ecf587233ebe88ac74630000000000001976a914dc7016484646168d99e49f907c86c271299441c088ac00000000\"\ntx = TX.deserialize(hex_tx)\n\n# Then, the transaction can be displayed using the display method to analyze how it's been constructed.\ntx.display()\n``` \n\n#### Using STATUS to dump the UTXOs LevelDB\n```python\nfrom bitcoin_tools.analysis.status.data_dump import utxo_dump\nfrom bitcoin_tools.analysis.status.utils import parse_ldb\n\n# Set the version of the Bitcoin Core you are using (which defines the chainstate format)\n# and the IO files.\n\nf_utxos = \"decoded_utxos.txt\"\nf_parsed_utxos = \"parsed_utxos.txt\"\n\n# Parse all the data in the chainstate.\nparse_ldb(f_utxos)\n# Parses transactions and utxos from the dumped data.\nutxo_dump(f_utxos, f_parsed_utxos)\n\n# Data is stored in f_utxos and f_parsed_utxos files respectively\n```\n\n### Support\n\nIf you find this repository useful, show us some love, give us a star!\n\nSmall Bitcoin donations to the following address are also welcome:\n\n[1srgi8sqPkCKq7gsVfhUZB7dvoi72UsqP](https://blockchain.info/address/1srgi8sqPkCKq7gsVfhUZB7dvoi72UsqP)\n\n### Disclaimer\n\nThis library allow you to modify any transaction field as you pleased. However, some modifications can make your \ntransactions non-standard, or even non-spendable. We totally discourage the use of the library outside the testnet if \nyou are not sure about what you are doing, specially when dealing with non-standard scripts. A bad use of the library \ncan lead you to lose some of your bitcoins.\n\n\n\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sr-gi/bitcoin_tools", "keywords": "bitcoin,transaction builder,key management,chainstate analysis", "license": "BSD 3", "maintainer": "", "maintainer_email": "", "name": "python-bitcoin-tools", "package_url": "https://pypi.org/project/python-bitcoin-tools/", "platform": "", "project_url": "https://pypi.org/project/python-bitcoin-tools/", "project_urls": { "Homepage": "https://github.com/sr-gi/bitcoin_tools" }, "release_url": "https://pypi.org/project/python-bitcoin-tools/0.2.3/", "requires_dist": [ "ecdsa", "python-bitcoinlib", "base58", "qrcode", "Pillow", "plyvel", "matplotlib", "numpy", "ujson" ], "requires_python": "", "summary": "Python library created for teaching and researching purposes.", "version": "0.2.3" }, "last_serial": 4497223, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "da9b3b27bcae5b06b22cea2fb2030b30", "sha256": "41e76dcaf7cc99799637c91bc211f5b3568fe704222073b89ccf089b27538b35" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.0-py2-none-any.whl", "has_sig": false, "md5_digest": "da9b3b27bcae5b06b22cea2fb2030b30", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 49630, "upload_time": "2018-06-21T17:45:31", "url": "https://files.pythonhosted.org/packages/b0/40/cb00f27c46c27d04476f9f372ddb5531eba7f9d5433a720a16b86d4ee245/python_bitcoin_tools-0.2.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cfe3d70e87fa19867a7c52420f1b9f13", "sha256": "b6d5de7422d1475e42d66804a8db18d3887e99eb0643fc5b9cac30885ccb7168" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.0.tar.gz", "has_sig": false, "md5_digest": "cfe3d70e87fa19867a7c52420f1b9f13", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42718, "upload_time": "2018-06-21T17:45:32", "url": "https://files.pythonhosted.org/packages/5c/ba/c5f681fcf40f82b57ca32f1f58a6daeb657f5b4aa348347d3096ff8856c2/python_bitcoin_tools-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "e923ab4f81325c935ff8b44dc25a20c9", "sha256": "1f07efa8fe7f7b85156d62286f22e8de016a5d88df688ecae888abb091683fb2" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.1-py2-none-any.whl", "has_sig": false, "md5_digest": "e923ab4f81325c935ff8b44dc25a20c9", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 49447, "upload_time": "2018-06-25T14:45:13", "url": "https://files.pythonhosted.org/packages/3e/4f/8cb99e7ec7231b6501bb01f921f4f0a022856b49267c4d0eba4ece1af2f2/python_bitcoin_tools-0.2.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e6cb6d41fc7e48f738ba067be4eb0ba3", "sha256": "1dd8c78c64079a491135a43f7ba75789421c43fedd6f85bf57824f18be9345a9" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.1.tar.gz", "has_sig": false, "md5_digest": "e6cb6d41fc7e48f738ba067be4eb0ba3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42509, "upload_time": "2018-06-25T14:45:14", "url": "https://files.pythonhosted.org/packages/cb/4a/3d20d71258b7689507a6968e2846b09460a521cb9c8562517c92c72971cf/python_bitcoin_tools-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "071e596868a50cdb3ffd271e9144709f", "sha256": "71909d8acb10d694149095c6b05c96efb9e76b8433b803c6c2de0844a1416270" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.2-py2-none-any.whl", "has_sig": false, "md5_digest": "071e596868a50cdb3ffd271e9144709f", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 54972, "upload_time": "2018-11-17T10:30:22", "url": "https://files.pythonhosted.org/packages/ad/1b/ed4411f1f12ba9de617a9e890f77bb93570b13f55cdad66d757b90100407/python_bitcoin_tools-0.2.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "467c9741aa7c338da1d905c6712768c7", "sha256": "a2016ecb667bbe55dcfaf14dd971bd38d7eaab6944b6c13874204b3f54fd0e79" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.2.tar.gz", "has_sig": false, "md5_digest": "467c9741aa7c338da1d905c6712768c7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44415, "upload_time": "2018-11-17T10:30:26", "url": "https://files.pythonhosted.org/packages/64/6e/226b7e5881503498ba220e590441aea68fe37e4e47fd5a5ff1b6918cce5d/python_bitcoin_tools-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "d322802d8433db4eff0cf7a6397eb129", "sha256": "c78bc5c0380f565b6c3a7a0c2b9174029159ad86ad335101c88f6679e1d0e504" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.3-py2-none-any.whl", "has_sig": false, "md5_digest": "d322802d8433db4eff0cf7a6397eb129", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 54977, "upload_time": "2018-11-17T14:14:29", "url": "https://files.pythonhosted.org/packages/14/8d/7691f016f88847d609ac383a5f986660ea303fc81dd52619d53291025914/python_bitcoin_tools-0.2.3-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "18d1b8f604cfa4af872d9acc4c5abc0c", "sha256": "c11d8250d4916dae77affb7a72f655903865817b65e7c3731357fdecb31307e5" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.3.tar.gz", "has_sig": false, "md5_digest": "18d1b8f604cfa4af872d9acc4c5abc0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44409, "upload_time": "2018-11-17T14:14:31", "url": "https://files.pythonhosted.org/packages/25/db/afc529ec76931bff1ee240c2faa11ea0bd9a6c481e95b2f6a47bc89a94e6/python_bitcoin_tools-0.2.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d322802d8433db4eff0cf7a6397eb129", "sha256": "c78bc5c0380f565b6c3a7a0c2b9174029159ad86ad335101c88f6679e1d0e504" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.3-py2-none-any.whl", "has_sig": false, "md5_digest": "d322802d8433db4eff0cf7a6397eb129", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 54977, "upload_time": "2018-11-17T14:14:29", "url": "https://files.pythonhosted.org/packages/14/8d/7691f016f88847d609ac383a5f986660ea303fc81dd52619d53291025914/python_bitcoin_tools-0.2.3-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "18d1b8f604cfa4af872d9acc4c5abc0c", "sha256": "c11d8250d4916dae77affb7a72f655903865817b65e7c3731357fdecb31307e5" }, "downloads": -1, "filename": "python_bitcoin_tools-0.2.3.tar.gz", "has_sig": false, "md5_digest": "18d1b8f604cfa4af872d9acc4c5abc0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44409, "upload_time": "2018-11-17T14:14:31", "url": "https://files.pythonhosted.org/packages/25/db/afc529ec76931bff1ee240c2faa11ea0bd9a6c481e95b2f6a47bc89a94e6/python_bitcoin_tools-0.2.3.tar.gz" } ] }