OpenEuler RISC-V 上跑bitcoin(实战版)

  不久前刚在OpenEuler 24.09 RISC-V上部署了 bitcoin,不过还没跑起来,这次我打算在这个环境下面运行一些应用服务,体验一下 OERV 的开发感觉。

  编译出来的 bitcoin 主要有几个命令,bitcoin-cli、bitcoind、bitcoin-util、bitcoin-wallet、bitcoin-tx和test_bitcoin。

  bitcoind 是比特币核心软件的守护进程程序,用于在计算机上运行比特币全节点。它是比特币网络的基础组件,负责下载、验证和存储整个比特币区块链,并与其他节点进行通信。

  bitcoin-cli 是一个命令行工具,用于与运行中的 bitcoind 守护进程进行交互。通过它,用户可以方便地向 bitcoind 发送各种请求,执行各种操作,如查询区块链信息、管理钱包、发起交易等。

  bitcoind-util 包含了一系列比特币相关的实用工具函数和命令,主要用于处理比特币的基础数据,如地址编码、密钥生成、哈希计算等。

  bitcoin-wallet 主要用于管理比特币钱包,它提供了一系列与钱包操作相关的功能,帮助用户方便地存储、发送和接收比特币。

  bitcoin-tx 是一个用于处理比特币交易的工具,主要用于创建、编辑、签名和广播比特币交易。

  test_bitcoin 是比特币核心软件的测试工具,用于对 bitcoind 及相关组件进行单元测试和集成测试,确保代码的正确性和稳定性。

  用法有很多,我主要挑了 bitcoind 和 bitcoin-cli 进行测试,看看运行的时候有没有什么 bug。

 

  bitcoind,光执行这个命令,会输出一大堆服务器的信息

  不过我们也可以选择挂到后台,bitcoind -daemon

  这样就可以利用控制台继续做其它事情了。如果想停下来,可以用 bitcoin-cli stop对服务器进行终止。

  bitcoin-cli 获取到的信息大部分都是以 json 的形式返回,以下是测试结果。

  bitcoin-cli getnetworkinfo(获取区块链网络信息)

{
 "version": 299900,
 "subversion": "/Satoshi:29.99.0/",
 "protocolversion": 70016,
 "localservices": "0000000000000c09",
 "localservicesnames": [
 "NETWORK",
 "WITNESS",
 "NETWORK_LIMITED",
 "P2P_V2"
 ],
 "localrelay": true,
 "timeoffset": 0,
 "networkactive": true,
 "connections": 8,
 "connections_in": 0,
 "connections_out": 8,
 "networks": [
 {
 "name": "ipv4",
 "limited": false,
 "reachable": true,
 "proxy": "",
 "proxy_randomize_credentials": false
 },
 {
 "name": "ipv6",
 "limited": false,
 "reachable": true,
 "proxy": "",
 "proxy_randomize_credentials": false
 },
 {
 "name": "onion",
 "limited": true,
 "reachable": false,
 "proxy": "",
 "proxy_randomize_credentials": false
 },
 {
 "name": "i2p",
 "limited": true,
 "reachable": false,
 "proxy": "",
 "proxy_randomize_credentials": false
 },
 {
 "name": "cjdns",
 "limited": true,
 "reachable": false,
 "proxy": "",
 "proxy_randomize_credentials": false
 }
 ],
 "relayfee": 0.00001000,
 "incrementalfee": 0.00001000,
 "localaddresses": [
 ],
 "warnings": [
 "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
 ]
}

  bitcoin-cli getblockchaininfo(获取当前的区块链信息,每次输出可能不一样,因为区块链信息可能还没有同步完成到本地,另一方面,区块是不断生成的)

{
 "chain": "main",
 "blocks": 16848,
 "headers": 890116,
 "bestblockhash": "00000000e84734ddbfcae5a7a3438cbc69498fab0f3097c5f866f617d019ab60",
 "bits": "1d00ffff",
 "target": "00000000ffff0000000000000000000000000000000000000000000000000000",
 "difficulty": 1,
 "time": 1244664175,
 "mediantime": 1244660177,
 "verificationprogress": 1.44758331039791e-05,
 "initialblockdownload": true,
 "chainwork": "000000000000000000000000000000000000000000000000000041d141d141d1",
 "size_on_disk": 4791214,
 "pruned": false,
 "warnings": [
 "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
 ]
}

  bitcoin-cli getmininginfo(获取挖矿信息)

{
 "blocks": 37920,
 "bits": "1d00be71",
 "difficulty": 1.344224970771029,
 "target": "00000000be710000000000000000000000000000000000000000000000000000",
 "networkhashps": 16012268.79171674,
 "pooledtx": 0,
 "chain": "main",
 "next": {
 "height": 37921,
 "bits": "1d00be71",
 "difficulty": 1.344224970771029,
 "target": "00000000be710000000000000000000000000000000000000000000000000000"
 },
 "warnings": [
 "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
 ]
}

  另一方面,如果输出一个错误的命令,比如 bitcoin-cli abc,会有错误码机制。

error code: -32601
error message:
Method not found

  bitcoin-cli createwallet "my_wallet"(创建名字为"my_wallet"的钱包)

{
 "name": "my_wallet"
}

  bitcoin-cli -rpcwallet=my_wallet getnewaddress(会为刚刚创建的钱包创建一个地址)

  

  综上来看,bitcoin 应用测试看起来一切顺利,尽管我只测试了最基本的命令行,但这也是探索过程中好的开始。

作者:ChebyshevTST原文地址:https://www.cnblogs.com/ChebyshevTST/p/18801382

%s 个评论

要回复文章请先登录注册