比特币Bitcoin Core RPC命令实践

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yzpbright/article/details/82591731

环境搭建参照 利用VMware组建两个节点的比特币网络
在此环境基础上进行相关命令操作。

(1)生成一个新地址,label是”EvidenceProofPlatform”

y@ubuntu:~/blockchain/EvidenceProof$ ./src/bitcoin-cli getnewaddress "EvidenceProofPlatform"
35j26ynUxcEfnvrFozJTuEw6HakNgPCnoK

再生成2个用户账户的地址:

y@ubuntu:~/blockchain/EvidenceProof$ ./src/bitcoin-cli getnewaddress "user1"
3PAW3fRVQLmiPNA3DfNBGZR2TkMPiF4kEA
y@ubuntu:~/blockchain/EvidenceProof$ ./src/bitcoin-cli getnewaddress "user2"
34pDmHtu4Emhyi32PGWx9GHAKLxnQQRK71

现在有3个账户,每个账户各有一个地址,总共是3个地址

(2)列出所有标签

y@ubuntu:~/blockchain/EvidenceProof$  ./src/bitcoin-cli listlabels
[
  "EvidenceProofPlatform",
  "user1",
  "user2"
]

(3)根据标签查询地址

y@ubuntu:~/blockchain/EvidenceProof$ ./src/bitcoin-cli getaddressesbylabel "EvidenceProofPlatform"
{
  "35j26ynUxcEfnvrFozJTuEw6HakNgPCnoK": {
    "purpose": "receive"
  }
}

(4)查询余额

y@ubuntu:~$ bitcoin-cli getbalance "EvidenceProofPlatform"
error code: -32
error message:
dummy first argument must be excluded or set to "*".
y@ubuntu:~$ bitcoin-cli getbalance "user1"
error code: -32
error message:
dummy first argument must be excluded or set to "*".
y@ubuntu:~$ bitcoin-cli getbalance "user2"
error code: -32
error message:
dummy first argument must be excluded or set to "*".
y@ubuntu:~$ bitcoin-cli getbalance "*"
0.00000000
y@ubuntu:~$ bitcoin-cli getbalance
0.00000000

(5)显示所有地址、账户及余额

y@ubuntu:~$ bitcoin-cli listaddressgroupings
[
]

(6)挖矿前先查询下当前的区块信息

y@ubuntu:~$ bitcoin-cli getblockchaininfo
{
  "chain": "main",
  "blocks": 0,
  "headers": 0,
  "bestblockhash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
  "difficulty": 1,
  "mediantime": 1231006505,
  "verificationprogress": 2.960049178257048e-09,
  "initialblockdownload": true,
  "chainwork": "0000000000000000000000000000000000000000000000000000000100010001",
  "size_on_disk": 293,
  "pruned": false,
  "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": false
      }
    },
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": false
      }
    },
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": false
      }
    }
  ],
  "bip9_softforks": {
    "csv": {
      "status": "defined",
      "startTime": 1462060800,
      "timeout": 1493596800,
      "since": 0
    },
    "segwit": {
      "status": "defined",
      "startTime": 1479168000,
      "timeout": 1510704000,
      "since": 0
    }
  },
  "warnings": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
}

可以看到区块数是0

(7)开始挖矿
先挖一个区块,用”EvidenceProofPlatform”账户下的346enqtFfNvwNAbfKWo1Ym3RPHNMZ8Gswu这个地址,maxtries填1000000

y@ubuntu:~$ bitcoin-cli generatetoaddress 1 "346enqtFfNvwNAbfKWo1Ym3RPHNMZ8Gswu"  1000000
[
]

数组是空的,说明遍历完了1000000次后也没有挖出区块,这是什么原因?
查看了https://github.com/bitcoin/bitcoin/blob/0.17/src/rpc/mining.cpp源码中的generateBlocks()方法的挖矿相关代码后,梳理逻辑,找到原因,即尝试maxtries(这里就是1000000)次后,如果没有挖出区块,那么就中止挖矿了,what???
这显然不符合正常的挖矿流程啊!再度陷入深深的思考…
结合之前学习的挖矿相关的知识,其实Bitcoin Core从0.13.0版本开始都不支持CPU挖矿了(详见https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.13.0.md),已经把挖矿线程去除了,而保留的generate接口以及新增的一个generatetoaddress接口,只是为了给用户提供测试挖矿的功能,并不是正常的挖矿流程!如果想要实现CPU挖矿,即实现启动挖矿后后台一直在挖矿,那么只能修改代码,把挖矿相关的代码改回到0.12(0.12版本中最后一个版本应该是0.12.1)的版本了。

分析挖矿:

在挖矿方法BitcoinMiner()的这部分源码中加上了log,方便查看挖矿情况


            //
            // Search
            //
            int64_t nStart = GetTime();
            arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
            uint256 hash;
            uint32_t nNonce = 0;
            while (true) {
                // Check if something found
                LogPrintf("ScanHash()...\n");
                if (ScanHash(pblock, nNonce, &hash))
                {
                    LogPrintf("nNonce=%s, hash=%s, UintToArith256(hash)=%s, hashTarget=%s\n", nNonce,hash.ToString(), UintToArith256(hash).ToString(), hashTarget.ToString());
                    if (UintToArith256(hash) <= hashTarget)
                    {
                        // Found a solution
                        pblock->nNonce = nNonce;
                        assert(hash == pblock->GetHash());

                        SetThreadPriority(THREAD_PRIORITY_NORMAL);
                        LogPrintf("BitcoinMiner:\n");
                        LogPrintf("proof-of-work found  \n  hash: %s  \ntarget: %s\n", hash.GetHex(), hashTarget.GetHex());
                        ProcessBlockFound(pblock, chainparams);
                        SetThreadPriority(THREAD_PRIORITY_LOWEST);
                        coinbaseScript->KeepScript();

                        // In regression test mode, stop mining after a block is found.
                        if (chainparams.MineBlocksOnDemand())
                            throw boost::thread_interrupted();

                        break;
                    }
                }

启动bitcoind,等待一段时间后查看debug.log

...........

2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z nNonce=472646302, hash=0000cd5573301abdfda804233cb2345fb35505ae34dc4d73fd0fa6b214859a45, UintToArith256(hash)=0000cd5573301abdfda804233cb2345fb35505ae34dc4d73fd0fa6b214859a45, hashTarget=00000000ffff0000000000000000000000000000000000000000000000000000
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:52Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z nNonce=472819670, hash=00004a85fc5079605bdc7312e3217f7db0a168fa43e55d0005211eeef8d632eb, UintToArith256(hash)=00004a85fc5079605bdc7312e3217f7db0a168fa43e55d0005211eeef8d632eb, hashTarget=00000000ffff0000000000000000000000000000000000000000000000000000
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z nNonce=472826365, hash=000000002fde7811d477f76676016f12069a8e81b948c04cd4b3357806a6205d, UintToArith256(hash)=000000002fde7811d477f76676016f12069a8e81b948c04cd4b3357806a6205d, hashTarget=00000000ffff0000000000000000000000000000000000000000000000000000
2018-09-02T07:45:53Z BitcoinMiner:
2018-09-02T07:45:53Z proof-of-work found  
  hash: 000000002fde7811d477f76676016f12069a8e81b948c04cd4b3357806a6205d  
target: 00000000ffff0000000000000000000000000000000000000000000000000000
2018-09-02T07:45:53Z CBlock(hash=000000002fde7811d477f76676016f12069a8e81b948c04cd4b3357806a6205d, ver=0x20000000, hashPrevBlock=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f, hashMerkleRoot=3d9cb109fb36e7abdc0e0784738e1cb9c76d2861a71faa97592d79b00a285c22, nTime=1535874353, nBits=1d00ffff, nNonce=472826365, vtx=1)
  CTransaction(hash=3d9cb109fb, ver=2, vin.size=1, vout.size=2, nLockTime=0)
    CTxIn(COutPoint(0000000000, 4294967295), coinbase 510101)
    CScriptWitness()
    CTxOut(nValue=50.00000000, scriptPubKey=2103950874a69a46492a53800aa72e)
    CTxOut(nValue=0.00000000, scriptPubKey=6a24aa21a9ede2f61c3f71d1defd3f)


2018-09-02T07:45:53Z Pre-allocating up to position 0x100000 in rev00000.dat
2018-09-02T07:45:53Z UpdateTip: new best=000000002fde7811d477f76676016f12069a8e81b948c04cd4b3357806a6205d height=1 version=0x20000000 log2_work=33.000022 tx=2 date='2018-09-02T07:45:53Z' progress=0.000000 cache=0.0MiB(1txo)
2018-09-02T07:45:53Z [default wallet] AddToWallet 3d9cb109fb36e7abdc0e0784738e1cb9c76d2861a71faa97592d79b00a285c22  new
2018-09-02T07:45:53Z [default wallet] keypool keep 1
2018-09-02T07:45:53Z CreateNewBlock(): block weight: 900 txs: 0 fees: 0 sigops 400
2018-09-02T07:45:53Z Running BitcoinMiner with 1 transactions in block (226 bytes)
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z ScanHash()...

......

来看下挖出第一个区块用了多久,
开始挖矿的那部分log:

2018-09-02T07:38:08Z DNS seeding disabled
2018-09-02T07:38:08Z init message: Done loading
2018-09-02T07:38:08Z BitcoinMiner started
2018-09-02T07:38:08Z msghand thread start
2018-09-02T07:38:08Z [default wallet] keypool reserve 1
2018-09-02T07:38:08Z CreateNewBlock(): block weight: 900 txs: 0 fees: 0 sigops 400
2018-09-02T07:38:08Z Running BitcoinMiner with 1 transactions in block (226 bytes)
2018-09-02T07:38:08Z ScanHash()...
2018-09-02T07:38:08Z ScanHash()...
2018-09-02T07:38:08Z opencon thread start
2018-09-02T07:38:08Z addcon thread start
2018-09-02T07:38:08Z net thread start
2018-09-02T07:38:08Z ScanHash()...
2018-09-02T07:38:08Z ScanHash()...

挖到第一个区块的那部分log:

2018-09-02T07:45:53Z ScanHash()...
2018-09-02T07:45:53Z nNonce=472826365, hash=000000002fde7811d477f76676016f12069a8e81b948c04cd4b3357806a6205d, UintToArith256(hash)=000000002fde7811d477f76676016f12069a8e81b948c04cd4b3357806a6205d, hashTarget=00000000ffff0000000000000000000000000000000000000000000000000000
2018-09-02T07:45:53Z BitcoinMiner:
2018-09-02T07:45:53Z proof-of-work found  

即:
开始时间是:07:38:08
挖到时间是:07:45:53
也就是大概8分钟左右。

(8)创建交易
格式:bitcoin-cli createrawtransaction ‘[{ “txid” :”<之前交易id>”, “vout”: <之前输出的索引> }]’ ‘{“本次输出的地址”: 金额}’
返回结果:交易id
例如 :
用txid为13ffd47d35308547eb24624b051f8686fb530aefe453e9aeb24b446cf6af828e的0号的输出作为本次交易输入,转给地址3QEiMn2te4aPgvusRmrNhpmdEjus78GAJ7,金额为9.9999

yzp@ubuntu:~$ bitcoin-cli createrawtransaction '[{ "txid":"13ffd47d35308547eb24624b051f8686fb530aefe453e9aeb24b446cf6af828e", "vout" :0 }]'   '{ "3QEiMn2te4aPgvusRmrNhpmdEjus78GAJ7": 9.9999}'
02000000018e82aff66c444bb2aee953e4ef0a53fb86861f054b6224eb478530357dd4ff130000000000ffffffff01f0a29a3b0000000017a914f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb8700000000

返回的:

02000000018e82aff66c444bb2aee953e4ef0a53fb86861f054b6224eb478530357dd4ff130000000000ffffffff01f0a29a3b0000000017a914f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb8700000000

就是创建的交易的id

(9)解码交易
bitcoin-cli decoderawtransaction txid

yzp@ubuntu:~$ bitcoin-cli decoderawtransaction 02000000018e82aff66c444bb2aee953e4ef0a53fb86861f054b6224eb478530357dd4ff130000000000ffffffff01f0a29a3b0000000017a914f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb8700000000
{
  "txid": "ec79dec1468972f929d675df8314f8f544053aa618077e4b9b58ab38001a478e",
  "hash": "ec79dec1468972f929d675df8314f8f544053aa618077e4b9b58ab38001a478e",
  "version": 2,
  "size": 83,
  "vsize": 83,
  "locktime": 0,
  "vin": [
    {
      "txid": "13ffd47d35308547eb24624b051f8686fb530aefe453e9aeb24b446cf6af828e",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 9.99990000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb OP_EQUAL",
        "hex": "a914f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "3QEiMn2te4aPgvusRmrNhpmdEjus78GAJ7"
        ]
      }
    }
  ]
}

(10)签名交易

bitcoin-cli signrawtransaction txid

yzp@ubuntu:~$ bitcoin-cli signrawtransaction 02000000018e82aff66c444bb2aee953e4ef0a53fb86861f054b6224eb478530357dd4ff130000000000ffffffff01f0a29a3b0000000017a914f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb8700000000
{
  "hex": "02000000018e82aff66c444bb2aee953e4ef0a53fb86861f054b6224eb478530357dd4ff130000000000ffffffff01f0a29a3b0000000017a914f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb8700000000",
  "complete": false,
  "errors": [
    {
      "txid": "13ffd47d35308547eb24624b051f8686fb530aefe453e9aeb24b446cf6af828e",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Input not found or already spent"
    }
  ]
}

(11)广播交易
bitcoin-cli sendrawtransaction txid

yzp@ubuntu:~$ bitcoin-cli sendrawtransaction 02000000018e82aff66c444bb2aee953e4ef0a53fb86861f054b6224eb478530357dd4ff130000000000ffffffff01f0a29a3b0000000017a914f7516a6148e7a315d58fb1d1c6abd7d1caa93aeb8700000000
error code: -25
error message:
Missing inputs

(12)查询整个钱包接收到的交易
bitcoin-cli listtransactions

y@ubuntu:~$ bitcoin-cli listtransactions
[
  {
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 41,
    "generated": true,
    "blockhash": "00000000f546820ae637bd07969fa96c1860a3ed1fd872c8ee0904ac8f1dfa35",
    "blockindex": 0,
    "blocktime": 1536741618,
    "txid": "c797258e463f1a207f634bfa8b4e531bf897a86d98c977d02a03583f4d6c0b2d",
    "walletconflicts": [
    ],
    "time": 1536741618,
    "timereceived": 1536741618,
    "bip125-replaceable": "no"
  },
  {
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 40,
    "generated": true,
    "blockhash": "00000000819fc6ddc1808a0905b90a6f2e296619bb8bb780d97cc09c3fd72889",
    "blockindex": 0,
    "blocktime": 1536742381,
    "txid": "b5f4bf5083f5540e64148129da1bc3a8e7aab8dfba8ee4a9e0ea2dee9c114763",
    "walletconflicts": [
    ],
    "time": 1536742381,
    "timereceived": 1536742381,
    "bip125-replaceable": "no"
  },
  {
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 39,
    "generated": true,
    "blockhash": "00000000703a5f122e0f7791fa01ee2ba120d9eb6dac122a2860b040628d06d8",
    "blockindex": 0,
    "blocktime": 1536742977,
    "txid": "792835f8bc9a378fb5a57f4db66785420c160bab2a67e6d462f08f3600402439",
    "walletconflicts": [
    ],
    "time": 1536742977,
    "timereceived": 1536742977,
    "bip125-replaceable": "no"
  },
  {
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 34,
    "generated": true,
    "blockhash": "000000008f291d9f76df823fb0a168be08b71ce3cef2eb182458101544a8ad48",
    "blockindex": 0,
    "blocktime": 1536750231,
    "txid": "acd1ce087d5c64cfd2fa69c0908b81d622c706af40d03f02de97037bf1848490",
    "walletconflicts": [
    ],
    "time": 1536750231,
    "timereceived": 1536750231,
    "bip125-replaceable": "no"
  },
  {
    "address": "1CNfWowt3jHGGaKF7bbhFKD7hUnSptd6Ds",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 31,
    "generated": true,
    "blockhash": "000000005e85ed0bae58a094e3fcd1103fe6b4c70c6d32670b887920b8c73ddf",
    "blockindex": 0,
    "blocktime": 1536753729,
    "txid": "47e75dae579a43cd62096842d1bf89896eeed2460b62142143efa29708409a04",
    "walletconflicts": [
    ],
    "time": 1536753729,
    "timereceived": 1536753729,
    "bip125-replaceable": "no"
  },
  {
    "address": "1CNfWowt3jHGGaKF7bbhFKD7hUnSptd6Ds",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 13,
    "generated": true,
    "blockhash": "00000000583e42e2d76fa2f95537999043c442ef9f0a9380a2808fbb486707c1",
    "blockindex": 0,
    "blocktime": 1536799135,
    "txid": "c775205bc39ea2f43cbcb4a32a2101ebb839e791281d60b5ccae29a4e5b82929",
    "walletconflicts": [
    ],
    "time": 1536799135,
    "timereceived": 1536799135,
    "bip125-replaceable": "no"
  },
  {
    "address": "1CNfWowt3jHGGaKF7bbhFKD7hUnSptd6Ds",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 11,
    "generated": true,
    "blockhash": "0000000030ed4d43d98689f78403cc81d8d490e607332c1c991ad27c2bd1f0ac",
    "blockindex": 0,
    "blocktime": 1536800030,
    "txid": "e36bd088a86be5b26d20b3aba405c3127fcc01b7f828e936a1a2f211b5572fcc",
    "walletconflicts": [
    ],
    "time": 1536800030,
    "timereceived": 1536800030,
    "bip125-replaceable": "no"
  },
  {
    "address": "1CNfWowt3jHGGaKF7bbhFKD7hUnSptd6Ds",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 10,
    "generated": true,
    "blockhash": "0000000070308f0c440e96e785cdad6cf3f05d2153dcee585e7881fb9e39d515",
    "blockindex": 0,
    "blocktime": 1536800089,
    "txid": "92a440f31def6e158c20de783fb1dee7c9aab4de55e4d48060ba35c567da0246",
    "walletconflicts": [
    ],
    "time": 1536800089,
    "timereceived": 1536800089,
    "bip125-replaceable": "no"
  },
  {
    "address": "1CNfWowt3jHGGaKF7bbhFKD7hUnSptd6Ds",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 8,
    "generated": true,
    "blockhash": "000000000a61102056e78e65b5a331a3205de58057920480bc04d98a0e5f8f25",
    "blockindex": 0,
    "blocktime": 1536800380,
    "txid": "28b9e041b1e05d70f0954d53b055f99e78c7028fcec932b8adc8f03bfc8342a6",
    "walletconflicts": [
    ],
    "time": 1536800380,
    "timereceived": 1536800380,
    "bip125-replaceable": "no"
  },
  {
    "address": "1CNfWowt3jHGGaKF7bbhFKD7hUnSptd6Ds",
    "category": "immature",
    "amount": 50.00000000,
    "vout": 0,
    "confirmations": 6,
    "generated": true,
    "blockhash": "00000000bb6e2c2ad3492727c6a5e7f95635a3b6ffc3e9126a00f4ca553cd34a",
    "blockindex": 0,
    "blocktime": 1536800689,
    "txid": "cd2392e42e700d2b104988b725db87ee72b71a2c0498184ac44c258cf61a2358",
    "walletconflicts": [
    ],
    "time": 1536800689,
    "timereceived": 1536800689,
    "bip125-replaceable": "no"
  }
]

(13) 查询所有的地址及对应的余额

y@ubuntu:~$ bitcoin-cli listaddressgroupings
[
  [
    [
      "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
      0.00000000
    ]
  ],
  [
    [
      "1AuL7GvTqsbjUXj6zupbtuoBWp7hJqoZfF",
      100.00000000
    ]
  ],
  [
    [
      "1CNfWowt3jHGGaKF7bbhFKD7hUnSptd6Ds",
      0.00000000
    ]
  ],
  [
    [
      "1D1tve4zD2VQRNPFQG9XBYyGFgVhEkZwvF",
      200.00000000
    ]
  ],
  [
    [
      "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
      0.00000000
    ]
  ]
]

参考:
官方文档:https://bitcoin.org/en/developer-reference#rpcs

bitcoin rpc command
《精通比特币》笔记~比特币客户端

猜你喜欢

转载自blog.csdn.net/yzpbright/article/details/82591731