Lite Bitcoin BunkrWallet致力于Bunkr机密之上
bunkrwallet的Python项目详细描述
双层钱包
bunkr钱包是一个简单的比特币钱包应用程序,建立在bunkr之上。在使用bunkr时,我们的钱包改变了加密货币钱包安全的模式:私钥被分发存储在bunkr中,并且安全地生成事务签名,而无需在any设备上重新构造私钥。钱包是一个简单的概念证明,可以通过python交互终端轻松控制。
免责声明:小心测试,这个钱包是在测试和快速发展。使用testnet coins演示钱包,在没有解码和查看它们的情况下永远不要发布生成的交易!
注意:
- 私钥被加密并作为bunkr机密存储在一组分布式机器上,永远不要触碰您的本地机器。
- 为了创建钱包或从钱包发送资金,bunkr rpc必须在后台运行。
- bunkr wallet不是hd(hierarchical deterministic)钱包,因为钱包地址与主种子没有任何关联或派生。您可以随时在电子钱包钥匙圈中添加更多地址。钱包会自动删除未用余额为0的已用地址,因此每次发票都会获得一个新的接收地址。
- 钱包将所有公共钱包信息存储在一个简单的json文件中。它存储地址、公钥和对bunkr机密的引用(用于与分布在远程服务器上的私钥通信)。虽然您的私钥仍然安全可靠,但丢失钱包文件可能会使您很难从钱包中取回资金。
安装
使用以下命令安装bunkr钱包(以及所有基本要求):
pip3 install bunkrwallet
用法
要开始使用bunkwallet python库,请运行:
>>> from bunkrwallet import BunkrWallet >>> bw = BunkrWallet()``` ## BunkrWallet class methods ```>>> bw = BunkrWallet()``` Creates an instance of the BunkrWallet. Optional parameters (don't change these unless you know what you are doing): - `directory` is the BunkrWallet directory (where all wallet files are stored) - `bunkr_address` is the tuple (ip, port) containing Bunkr RPC address information (how python communicates with Bunkr backend) #### create_wallet ```>>> w = bw.create_wallet("your-wallet-name")``` Creates Wallet object and the file `your-wallet-name.json` in the BunkrWallet directory. Optional parameter - `testnet` is a boolean flag for either bitcoin testnet or mainnet (defaults to False, i.e. mainnet) #### list_wallets ```>>> bw.list_wallets() ['your-wallet-name', 'your-other-wallet-name', ...]``` Lists all the wallet names in the BunkrWallet directory. #### get_wallet ```>>> w = bw.get_wallet("your-wallet-name")
从bunkwallet中获取名为“your wallet name”的钱包对象。
钱包类方法
显示余额
>>> w.show_balance()
打印钱包的总余额。
显示新鲜地址
>>> w.show_fresh_address()
显示钱包钥匙圈上未使用的地址。使用此方法获取接收比特币的地址。如果钱包中没有新地址,则会出现错误(要克服此错误,请参见添加地址)
发送
>>> w.send([{"address": <address 1>, "value": <satoshi amount to address 1}, {"address": <address 2>, "value": <satoshi amount to address 2>}, ...], <fee amount>)
返回新比特币交易的已签名交易十六进制。由用户发布事务。
添加地址
>>> w.add_addresses(<number of addresses>)
向电子钱包钥匙圈中添加一定数量的地址。
testnet演示
从这个目录打开python3交互终端:
$ python3
>>> from bunkrwallet import BunkrWallet
>>> bw = BunkrWallet()
>>> wallet = bw.create_wallet("testnetWallet", testnet=True)
'creating new wallet...'
>>> wallet.show_fresh_address()
<shows an unused address in your wallet, for receiving>
- 使用您选择的钱包名称创建新钱包。将testnet标志设置为true。
- 使用show_fresh_address()获取接收比特币的新地址
- 将testnet比特币发送到您的地址。testnet比特币可以在testnet水龙头上找到,例如:https://coinfaucet.eu/en/btc-testnet/
- 一旦您有了一些测试比特币,您就可以从您的钱包发送,如本例交易中所示:
>>> from bunkrwallet import BunkrWallet, COIN
>>> bw = BunkrWallet()
>>> wallet = bw.get_wallet("testnetWallet")
>>> wallet.show_balance()
<shows total wallet balance>
>>> outputs = [{"address":<some address>, "value":0.01*COIN}, ...]
>>> fee = 0.0001*COIN
>>> wallet.send(outputs, fee)
<prints transaction hex which can be pushed to the blockchain>