比特币Bitcoin Core RPC命令实践

环境搭建参照 利用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
    ]
  ]
]

(14)查询未花费的交易

y@ubuntu:~$ bitcoin-cli listunspent 6 9999999 
[
  {
    "txid": "8e2260c7f6502304cdcdbe50dbe84014430b1d199d959a4d736dc71b027fd600",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 149,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "449db59ac400a8e0df8be5050f0524de09710f26f6638a93349a1dd088c5e10b",
    "vout": 0,
    "address": "1D1tve4zD2VQRNPFQG9XBYyGFgVhEkZwvF",
    "scriptPubKey": "2103894400f6b29e2d1ca857026bc96c2b15198f938a5e26ea2701055259df28d2aaac",
    "amount": 50.00000000,
    "confirmations": 160,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "2243560ecfe49794d7d495f23397fef581e93d7b11a876b0f450621c08eba619",
    "vout": 0,
    "address": "1AuL7GvTqsbjUXj6zupbtuoBWp7hJqoZfF",
    "scriptPubKey": "21023c8ab66b1cec7f1eb620da5e45a3241ccc001a4e80332f20383ead2d33a2c422ac",
    "amount": 50.00000000,
    "confirmations": 158,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "39b8aa5ceb9cf4756dc4af2dab9a7bba6378535391402223deac2d257684051c",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 148,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "c797258e463f1a207f634bfa8b4e531bf897a86d98c977d02a03583f4d6c0b2d",
    "vout": 0,
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "scriptPubKey": "210350d75c16cf15ea8009e5b160e2178398dfd0bee013a2fc4d37ec4b55078936c8ac",
    "amount": 50.00000000,
    "confirmations": 110,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "792835f8bc9a378fb5a57f4db66785420c160bab2a67e6d462f08f3600402439",
    "vout": 0,
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "scriptPubKey": "210350d75c16cf15ea8009e5b160e2178398dfd0bee013a2fc4d37ec4b55078936c8ac",
    "amount": 50.00000000,
    "confirmations": 108,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "8239c9f04cbd8071e98309b5d5d286a10983db9844eb4226871e68a5c6842844",
    "vout": 0,
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "scriptPubKey": "210350d75c16cf15ea8009e5b160e2178398dfd0bee013a2fc4d37ec4b55078936c8ac",
    "amount": 50.00000000,
    "confirmations": 113,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "96207343f63d9fd714cbbfcdbe33e084f7ae3314ac1dab7a8d74758a9c193c49",
    "vout": 0,
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "scriptPubKey": "210350d75c16cf15ea8009e5b160e2178398dfd0bee013a2fc4d37ec4b55078936c8ac",
    "amount": 50.00000000,
    "confirmations": 111,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "f6d7e79a2ca77d1500a455998ba3b5da36e6c3e7e070796ba31ea2bd532bd855",
    "vout": 0,
    "address": "1D1tve4zD2VQRNPFQG9XBYyGFgVhEkZwvF",
    "scriptPubKey": "2103894400f6b29e2d1ca857026bc96c2b15198f938a5e26ea2701055259df28d2aaac",
    "amount": 50.00000000,
    "confirmations": 162,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "b5f4bf5083f5540e64148129da1bc3a8e7aab8dfba8ee4a9e0ea2dee9c114763",
    "vout": 0,
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "scriptPubKey": "210350d75c16cf15ea8009e5b160e2178398dfd0bee013a2fc4d37ec4b55078936c8ac",
    "amount": 50.00000000,
    "confirmations": 109,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "f66be06e0bb58737493b467fd4059f41c9574bac426312abc35f7782221cfb7c",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 153,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "acd1ce087d5c64cfd2fa69c0908b81d622c706af40d03f02de97037bf1848490",
    "vout": 0,
    "address": "1Lzpip8ViPESqN5PXS3CB7RJRAJdAQJnNk",
    "scriptPubKey": "210350d75c16cf15ea8009e5b160e2178398dfd0bee013a2fc4d37ec4b55078936c8ac",
    "amount": 50.00000000,
    "confirmations": 103,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "64e06b72aa51e66eb3d1a74f1f85b18b1535f87b2d7ad59f5e23aac57241c992",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 152,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "5d0a1d64b2bd8930a14f967a047efeaa0e7d9de1e868f391db098e1ea2868799",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 150,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "c6cc2a7c6e18e7a95b5a2313cd0e8bda9535e64d0c1ede3c93b26a48791e1eac",
    "vout": 0,
    "address": "1D1tve4zD2VQRNPFQG9XBYyGFgVhEkZwvF",
    "scriptPubKey": "2103894400f6b29e2d1ca857026bc96c2b15198f938a5e26ea2701055259df28d2aaac",
    "amount": 50.00000000,
    "confirmations": 163,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "7fa8b4250b9d87e76d1e4f994f1b2fb6abe645bc9766afef7bdfcec6ddba4cad",
    "vout": 0,
    "address": "1D1tve4zD2VQRNPFQG9XBYyGFgVhEkZwvF",
    "scriptPubKey": "2103894400f6b29e2d1ca857026bc96c2b15198f938a5e26ea2701055259df28d2aaac",
    "amount": 50.00000000,
    "confirmations": 159,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "ef634e4e177d806ac49a7ae34283473d16e930a41c17879353222fac41e319bf",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 146,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "6c147d344fe3abe2ec3cca0d8e90be5f6d1ab27ebde9873fe6355f1be59916e2",
    "vout": 0,
    "address": "1AuL7GvTqsbjUXj6zupbtuoBWp7hJqoZfF",
    "scriptPubKey": "21023c8ab66b1cec7f1eb620da5e45a3241ccc001a4e80332f20383ead2d33a2c422ac",
    "amount": 50.00000000,
    "confirmations": 157,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "f4ee6482d74a3749533a6be2ab391587772ec17c584f013c5347b763a78a7dff",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 151,
    "spendable": true,
    "solvable": true,
    "safe": true
  }
]

(15) 查询指定地址的未花费的交易

y@ubuntu:~$ bitcoin-cli listunspent 6 9999999 "[\"1AuL7GvTqsbjUXj6zupbtuoBWp7hJqoZfF\",\"15tAe7624QhKip6kWnDRu65mLQsVcWBmne\"]"
[
  {
    "txid": "8e2260c7f6502304cdcdbe50dbe84014430b1d199d959a4d736dc71b027fd600",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 149,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "2243560ecfe49794d7d495f23397fef581e93d7b11a876b0f450621c08eba619",
    "vout": 0,
    "address": "1AuL7GvTqsbjUXj6zupbtuoBWp7hJqoZfF",
    "scriptPubKey": "21023c8ab66b1cec7f1eb620da5e45a3241ccc001a4e80332f20383ead2d33a2c422ac",
    "amount": 50.00000000,
    "confirmations": 158,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "39b8aa5ceb9cf4756dc4af2dab9a7bba6378535391402223deac2d257684051c",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 148,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "f66be06e0bb58737493b467fd4059f41c9574bac426312abc35f7782221cfb7c",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 153,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "64e06b72aa51e66eb3d1a74f1f85b18b1535f87b2d7ad59f5e23aac57241c992",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 152,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "5d0a1d64b2bd8930a14f967a047efeaa0e7d9de1e868f391db098e1ea2868799",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 150,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "ef634e4e177d806ac49a7ae34283473d16e930a41c17879353222fac41e319bf",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 146,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "6c147d344fe3abe2ec3cca0d8e90be5f6d1ab27ebde9873fe6355f1be59916e2",
    "vout": 0,
    "address": "1AuL7GvTqsbjUXj6zupbtuoBWp7hJqoZfF",
    "scriptPubKey": "21023c8ab66b1cec7f1eb620da5e45a3241ccc001a4e80332f20383ead2d33a2c422ac",
    "amount": 50.00000000,
    "confirmations": 157,
    "spendable": true,
    "solvable": true,
    "safe": true
  },
  {
    "txid": "f4ee6482d74a3749533a6be2ab391587772ec17c584f013c5347b763a78a7dff",
    "vout": 0,
    "address": "15tAe7624QhKip6kWnDRu65mLQsVcWBmne",
    "scriptPubKey": "2102039cee04be0cabe4733437d9f9c2b22c10a575eec0e52058c70632575889df50ac",
    "amount": 50.00000000,
    "confirmations": 151,
    "spendable": true,
    "solvable": true,
    "safe": true
  }
]

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

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

你可能感兴趣的:(区块链)