为教学和研究目的而创建的python库。

python-bitcoin-tools的Python项目详细描述


bitcoin_tools

Mentioned in Awesome

比特币工具是一个为教学和研究目的而创建的python库。它的主要目标是双重的。首先是 旨在通过使用有案可稽且易于理解的方法,简化对比特币交易创建的理解 python代码。其次,它旨在提供一个能够创建自定义transactions/scripts的工具。或者scriptSigscriptPubKey可以从使用Script语法创建的人类可读字符串构建。最后,访问和 本文还提供了分析utxo set等有趣数据的示例。

比特币工具允许您:

  • 比特币密钥的创建和管理。
  • 从头开始创建比特币交易。
  • 自定义事务的任何字段。
  • 事务序列化/反序列化。
  • 创建标准和自定义脚本(scriptSigscriptPubKey)。
  • 十六进制编码事务的事务分析。

此外,比特币工具还包含STATUSs t统计学a分析t工具用于utxoset下的^{}

依赖性

请参阅DEPENCENCIES.md

安装

请参阅INSTALL.md

开始回购有什么问题吗?

请参阅FAQ.md

仍然不工作?

请随意打开一个问题。

示例

下面您可以找到一些如何使用某些库函数的示例。更多的例子可以在 ^{}

密钥管理和比特币地址生成

frombitcoin_tools.core.keysimportgenerate_keys,store_keysfrombitcoin_tools.walletimportgenerate_wif,generate_btc_addr# First of all the ECDSA keys are generated.sk,pk=generate_keys()# Then, the Bitcoin address is derived from the public key created above.btc_addr=generate_btc_addr(pk)# Both the public and private key are stored in disk in pem format. The Bitcoin address is used as an identifier in the# name of the folder that contains both keys.store_keys(sk.to_pem(),pk.to_pem(),btc_addr)# Finally, the private key is encoded as WIF and also stored in disk, ready to be imported in a wallet.generate_wif(btc_addr,sk)

原始交易大楼
frombitcoin_tools.core.keysimportload_keysfrombitcoin_tools.core.transactionimportTX# Key loadingbtc_addr="miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t"sk,pk=load_keys(btc_addr)# Reference to the previous transaction output that will be used to redeem and spend the funds, consisting on an id and# an output index.prev_tx_id="7767a9eb2c8adda3ffce86c06689007a903b6f7e78dbc049ef0dbaf9eeebe075"prev_out_index=0# Amount to be spent, in Satoshis, and the fee to be deduced (should be calculated).value=6163910fee=230*240# Destination Bitcoin address where the value in bitcoins will be sent and locked until the owner redeems it.destination_btc_addr="miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t"# First, we  build our transaction from io (input/output) using the previous transaction references, the value, and the# destination.tx=TX.build_from_io(prev_tx_id,prev_out_index,value-fee,destination_btc_addr)# Finally, the transaction is signed using the private key associated with the Bitcoin address from each input.# Input 0 will be signed, since we have only created one.tx.sign(sk,0)# Once created we can display the serialized transaction. Transaction is now ready to be broadcast.print"hex: "+tx.serialize()# Finally, we can analyze each field of the transaction.tx.display()

原始TX分析
frombitcoin_tools.core.transactionimportTX# First a transaction object is created (through the deserialize constructor) by deserializing the hex transaction we# have selected.hex_tx="01000000013ca58d2f6fac36602d831ee0cf2bc80031c7472e80a322b57f614c5ce9142b71000000006b483045022100f0331d85cb7f7ec1bedc41f50c695d654489458e88aec0076fbad5d8aeda1673022009e8ca2dda1d6a16bfd7133b0008720145dacccb35c0d5c9fc567e52f26ca5f7012103a164209a7c23227fcd6a71c51efc5b6eb25407f4faf06890f57908425255e42bffffffff0241a20000000000001976a914e44839239ab36f5bc67b2079de00ecf587233ebe88ac74630000000000001976a914dc7016484646168d99e49f907c86c271299441c088ac00000000"tx=TX.deserialize(hex_tx)# Then, the transaction can be displayed using the display method to analyze how it's been constructed.tx.display()

使用status转储utxos leveldb
frombitcoin_tools.analysis.status.data_dumpimportutxo_dumpfrombitcoin_tools.analysis.status.utilsimportparse_ldb# Set the version of the Bitcoin Core you are using (which defines the chainstate format)# and the IO files.f_utxos="decoded_utxos.txt"f_parsed_utxos="parsed_utxos.txt"# Parse all the data in the chainstate.parse_ldb(f_utxos)# Parses transactions and utxos from the dumped data.utxo_dump(f_utxos,f_parsed_utxos)# Data is stored in f_utxos and f_parsed_utxos files respectively

支持

如果你觉得这个储存库有用,给我们一些爱,给我们一颗星星!

也欢迎向以下地址捐赠少量比特币:

1srgi8sqPkCKq7gsVfhUZB7dvoi72UsqP

免责声明

此库允许您根据需要修改任何事务字段。但是,一些修改可以使 交易不规范,甚至不可消费。如果 您不确定自己在做什么,特别是在处理非标准脚本时。图书馆使用不当 会导致你丢失一些比特币。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
具有类注册的java工厂方法模式生成nullpointer异常   java PSI和索引不匹配:在Android Studio上PSI和索引不匹配   JavaSpring使用一个应用程序。用于生产的属性和用于调试的属性   java在哪里被卡住了?   JMF中的java更大分辨率   java我如何在HashMap中只找到某些实体的最高值,而不是整个HashMap?   Android中偏好和共享偏好的java差异   swing Java:ScrollablePicture使其在给定坐标下滚动   java如何转换GMT?   使用PolicyFactory后,xss HtmlPolicyBuilder样式不会出现在<tr>和<table>标记中。java代码中的清理   java如何在pgAdmin3中显示使用Hibernate插入的文本值?   java我需要从视图类中的主要活动中获取上下文   java如何确保字符串没有数字   java合并特定逻辑的整数数组列表   eclipse java数据库与OOP的连接   java如何获得Div中的子元素的计数甚至文本列表