Skip to content

节点接口文档

OuYun edited this page Nov 4, 2019 · 6 revisions

节点接口文档

bigbang使用RPC(Remote Procedure Call)远程过程调用为各种客户端提供服务:

查询区块高度

getforkheight - 取得分支上(缺省不带参数表示主链)的区块高度(0-based)

Usage:
        getforkheight (-f="fork")

Return the number of height in the given fork.

Arguments:
 -f="fork"                              (string, optional) fork hash

Request:
 "param" :
 {
   "fork": ""                           (string, optional) fork hash
 }

Response:
 "result": height                       (int, required) fork height

Examples:
>> bigbang-cli getforkheight
<< 32081

>> curl -d '{"id":4,"method":"getforkheight","jsonrpc":"2.0","params":{}}' http://127.0.0.1:9902
<< {"id":4,"jsonrpc":"2.0","result":32081}

>> bigbang-cli getforkheight -f=a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0

Errors:
* {"code":-6,"message":"Invalid fork"}
* {"code":-6,"message":"Unknown fork"}

查询区块信息

getblockcount - 取得分支上(缺省不带参数表示主链)的区块数量

Usage:
        getblockcount (-f="fork")

Return the number of blocks in the given fork, includes extended block and vacant block

Arguments:
 -f="fork"                              (string, optional) fork hash

Request:
 "param" :
 {
   "fork": ""                           (string, optional) fork hash
 }

Response:
 "result": count                        (int, required) block count

Examples:
>> bigbang-cli getblockcount
<< 32081

>> curl -d '{"id":4,"method":"getblockcount","jsonrpc":"2.0","params":{}}' http://127.0.0.1:9902
<< {"id":4,"jsonrpc":"2.0","result":32081}

>> bigbang-cli getblockcount -f=a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0
<< 32081

>> curl -d '{"id":5,"method":"getblockcount","jsonrpc":"2.0","params":{"fork":"0"}}' http://127.0.0.1:9902
<< {"id":5,"jsonrpc":"2.0","result":32081}

Errors:
* {"code":-6,"message":"Invalid fork"}
* {"code":-6,"message":"Unknown fork"}

getblockhash - 获取某个高度的区块哈希值

Usage:
        getblockhash <height> (-f="fork")

Return a list of block hash in fork at specific height.
First of the list is the main block hash, others are extended blocks hash in order.

Arguments:
 height                                 (int, required) block height
 -f="fork"                              (string, optional) fork hash

Request:
 "param" :
 {
   "height": 0,                         (int, required) block height
   "fork": ""                           (string, optional) fork hash
 }

Response:
 "result" :
   [
     "hash": ""                         (string, required) one block hash
   ]

Examples:
>> bigbang-cli getblockhash 0
<< ["a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0"]

>> curl -d '{"id":37,"method":"getblockhash","jsonrpc":"2.0","params":{"height":0}}' http://127.0.0.1:9902
<< {"id":37,"jsonrpc":"2.0","result":["a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0"]}

>> bigbang-cli getblockhash 0 -f=a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0

Errors:
* {"code":-6,"message":"Invalid fork"}
* {"code":-6,"message":"Unknown fork"}
* {"code":-6,"message":"Block number out of range."}

getblock - 获取给定哈希值的区块的信息

Usage:
        getblock <"block">

Return details of a block with given block-hash.

Arguments:
 "block"                                (string, required) block hash

Request:
 "param" :
 {
   "block": ""                          (string, required) block hash
 }

Response:
 "result" :
 {
   "hash": "",                          (string, required) block hash
   "hashPrev": "",                      (string, required) block prev hash
   "version": 0,                        (uint, required) version
   "type": "",                          (string, required) block type
   "time": 0,                           (uint, required) block time
   "fork": "",                          (string, required) fork hash
   "height": 0,                         (uint, required) block height
   "txmint": "",                        (string, required) transaction mint hash
   [
     "tx": ""                           (string, required) transaction hash
   ]
   "prev": ""                           (string, optional) previous block hash
 }

Examples:
>> bigbang-cli getblock ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c
<< {"hash":"ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c","version":1,"type":"primary-pow","time":1538138566,"prev":"47b86e794e7ce0546def4fe3603d58d9cc9fc87eeee676bd15ae90e45ab51f8a","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","height":31296,"txmint":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","tx":[]}

>> curl -d '{"id":10,"method":"getblock","jsonrpc":"2.0","params":{"block":"ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c"}}' http://127.0.0.1:9902
<< {"id":10,"jsonrpc":"2.0","result":{"hash":"ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c","version":1,"type":"primary-pow","time":1538138566,"prev":"47b86e794e7ce0546def4fe3603d58d9cc9fc87eeee676bd15ae90e45ab51f8a","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","height":31296,"txmint":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","tx":[]}}

Errors:
* {"code":-6,"message":"Unknown block."}

getblockdetail - 获取给定哈希值的区块的详细信息

Usage:
        getblockdetail <"block">

Return details of a block with given block-hash.

Arguments:
 "block"                                (string, required) block hash

Request:
 "param" :
 {
   "block": ""                          (string, required) block hash
 }

Response:
 "result" :
 {
   "hash": "",                          (string, required) block hash
   "hashPrev": "",                      (string, required) block prev hash
   "version": 0,                        (uint, required) version
   "type": "",                          (string, required) block type
   "time": 0,                           (uint, required) block time
   "bits": 0,                           (uint, required) nBits
   "fork": "",                          (string, required) fork hash
   "height": 0,                         (uint, required) block height
   "txmint":                            (object, required) transaction mint data
   {
     "txid": "",                        (string, required) transaction hash
     "version": 0,                      (uint, required) version
     "type": "",                        (string, required) transaction type
     "time": 0,                         (uint, required) transaction timestamp
     "lockuntil": 0,                    (uint, required) unlock time
     "anchor": "",                      (string, required) anchor hash
     [
       "vin":                           (object, required) vin struct
       {
         "txid": "",                    (string, required) pre-vout transaction hash
         "vout": 0                      (uint, required) pre-vout number
       }
     ]
     "sendto": "",                      (string, required) send to address
     "amount": 0.0,                     (double, required) amount
     "txfee": 0.0,                      (double, required) transaction fee
     "data": "",                        (string, required) data
     "sig": "",                         (string, required) sign
     "fork": "",                        (string, required) fork hash
     "confirmations": 0                 (int, optional) confirmations
   }
   [
     "tx":                              (object, required) transaction data
     {
       "txid": "",                      (string, required) transaction hash
       "version": 0,                    (uint, required) version
       "type": "",                      (string, required) transaction type
       "time": 0,                       (uint, required) transaction timestamp
       "lockuntil": 0,                  (uint, required) unlock time
       "anchor": "",                    (string, required) anchor hash
       [
         "vin":                         (object, required) vin struct
         {
           "txid": "",                  (string, required) pre-vout transaction hash
           "vout": 0                    (uint, required) pre-vout number
         }
       ]
       "sendto": "",                    (string, required) send to address
       "amount": 0.0,                   (double, required) amount
       "txfee": 0.0,                    (double, required) transaction fee
       "data": "",                      (string, required) data
       "sig": "",                       (string, required) sign
       "fork": "",                      (string, required) fork hash
       "confirmations": 0               (int, optional) confirmations
     }
   ]
   "prev": ""                           (string, optional) previous block hash
 }

Examples:
>> bigbang-cli getblockdetail ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c
<< {"hash":"ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c","version":1,"type":"primary-pow","time":1538138566,"prev":"47b86e794e7ce0546def4fe3603d58d9cc9fc87eeee676bd15ae90e45ab51f8a","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","height":31296,"txmint":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","tx":[]}

>> curl -d '{"id":10,"method":"getbgetblockdetaillock","jsonrpc":"2.0","params":{"block":"ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c"}}' http://127.0.0.1:9902
<< {"id":10,"jsonrpc":"2.0","result":{"hash":"ca49b8d07ac2849c455a813dd967bb0b306b48406d787259f4ddb8f6a0e0cf4c","version":1,"type":"primary-pow","time":1538138566,"prev":"47b86e794e7ce0546def4fe3603d58d9cc9fc87eeee676bd15ae90e45ab51f8a","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","height":31296,"txmint":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","tx":[]}}

Errors:
* {"code":-6,"message":"Unknown block."}

getblocklocation - 获取给定区块哈希的高度值

Usage:
        getblocklocation <"block">

Return the location with given block.

Arguments:
 "block"                                (string, required) block hash

Request:
 "param" :
 {
   "block": ""                          (string, required) block hash
 }

Response:
 "result" :
 {
   "fork": "",                          (string, required) fork hash
   "height": 0                          (int, required) block height
 }

Examples:
>> bigbang-cli getblocklocation 609a797ca28042d562b11355038c516d65ba30b91c7033d83c61b81aa8c538e3
<< {"fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","height":1}

>> curl -d '{"id":6,"method":"getblocklocation","jsonrpc":"2.0","params":{"block":"609a797ca28042d562b11355038c516d65ba30b91c7033d83c61b81aa8c538e3"}}' http://127.0.0.1:9902
<< {"id":6,"jsonrpc":"2.0","result":{"fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","height":1}}

Errors:
* {"code":-6,"message":"Unknown block."}

查询交易信息

gettransaction - 获取给定交易哈希的交易详细信息

Usage:
        gettransaction <"txid"> (-s|-nos*serialized*)

Get transaction information

Arguments:
 "txid"                                 (string, required) transaction hash
 -s|-nos*serialized*                    (bool, optional, default=false) If serialized=0, return an Object with information about <txid>.
                                        If serialized is non-zero, return a string that is
                                        serialized, hex-encoded data for <txid>.

Request:
 "param" :
 {
   "txid": "",                          (string, required) transaction hash
   "serialized": true|false             (bool, optional, default=false) If serialized=0, return an Object with information about <txid>.
                                        If serialized is non-zero, return a string that is
                                        serialized, hex-encoded data for <txid>.
 }

Response:
 "result" :
 {
   (if serialized=true)
   "serialization": "",                 (string, optional) transaction hex data
   (if serialized=false)
   "transaction":                       (object, optional) transaction data
   {
     "txid": "",                        (string, required) transaction hash
     "version": 0,                      (uint, required) version
     "type": "",                        (string, required) transaction type
     "time": 0,                         (uint, required) transaction timestamp
     "lockuntil": 0,                    (uint, required) unlock time
     "anchor": "",                      (string, required) anchor hash
     [
       "vin":                           (object, required) vin struct
       {
         "txid": "",                    (string, required) pre-vout transaction hash
         "vout": 0                      (uint, required) pre-vout number
       }
     ]
     "sendto": "",                      (string, required) send to address
     "amount": 0.0,                     (double, required) amount
     "txfee": 0.0,                      (double, required) transaction fee
     "data": "",                        (string, required) data
     "sig": "",                         (string, required) sign
     "fork": "",                        (string, required) fork hash
     "confirmations": 0                 (int, optional) confirmations
   }
 }

Examples:
>> bigbang-cli gettransaction 3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29
<< {"transaction":{"txid":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","version":1,"type":"work","time":1547916097,"lockuntil":0,"anchor":"47b86e794e7ce0546def4fe3603d58d9cc9fc87eeee676bd15ae90e45ab51f8a","vin":[],"sendto":"20g00k7pe4krdbbxpn5swgbxc0w4a54w054stt1z107d9n3sk6q7js9gw","amount":15.00000000,"txfee":0.00000000,"data":"","sig":"","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","confirmations":785}}

>> curl -d '{"id":13,"method":"gettransaction","jsonrpc":"2.0","params":{"txid":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","serialized":false}}' http://127.0.0.1:9902
<< {"id":13,"jsonrpc":"2.0","result":{"transaction":{"txid":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","version":1,"type":"work","time":1547916097,"lockuntil":0,"anchor":"47b86e794e7ce0546def4fe3603d58d9cc9fc87eeee676bd15ae90e45ab51f8a","vin":[],"sendto":"20g00k7pe4krdbbxpn5swgbxc0w4a54w054stt1z107d9n3sk6q7js9gw","amount":15.00000000,"txfee":0.00000000,"data":"","sig":"","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","confirmations":785}}}

>> bigbang-cli gettransaction -s 3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29
<< {"serialization":"01000003000000008a1fb55ae490ae15bd76e6ee7ec89fccd9583d60e34fef6d54e07c4e796eb84700020400099ece24f0d5afb6a973c82fac0708a293802933ad07e101da9a8f3335cfc0e1e4000000000000000000000000000000"}

>> curl -d '{"id":13,"method":"gettransaction","jsonrpc":"2.0","params":{"txid":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","serialized":false}}' http://127.0.0.1:9902
<< {"id":14,"method":"gettransaction","jsonrpc":"2.0","params":{"txid":"3d4ed629c594b924d72480e29a332ca91915be685c85940a8c501f8248269e29","serialized":true}}

Errors:
* {"code":-6,"message":"No information available about transaction."}

decodetransaction - 获取给定交易原生字节流数据的交易详细信息

Usage:
        decodetransaction <"txdata">

Return a JSON object representing the serialized, hex-encoded transaction.

Arguments:
 "txdata"                               (string, required) transaction raw data

Request:
 "param" :
 {
   "txdata": ""                         (string, required) transaction raw data
 }

Response:
 "result" :
 {
   "txid": "",                          (string, required) transaction hash
   "version": 0,                        (uint, required) version
   "type": "",                          (string, required) transaction type
   "time": 0,                           (uint, required) transaction timestamp
   "lockuntil": 0,                      (uint, required) unlock time
   "anchor": "",                        (string, required) anchor hash
   [
     "vin":                             (object, required) vin struct
     {
       "txid": "",                      (string, required) pre-vout transaction hash
       "vout": 0                        (uint, required) pre-vout number
     }
   ]
   "sendto": "",                        (string, required) send to address
   "amount": 0.0,                       (double, required) amount
   "txfee": 0.0,                        (double, required) transaction fee
   "data": "",                          (string, required) data
   "sig": "",                           (string, required) sign
   "fork": "",                          (string, required) fork hash
   "confirmations": 0                   (int, optional) confirmations
 }

Examples:
>> bigbang-cli decodetransaction 01000000000000002b747e24738befccff4a05c21dba749632cb8eb410233fa110e3f58a779b4325010ef45be50157453a57519929052d0818c269dee60be98958d5ab65bc7e0919810001b9c3b7aa16c6cb1bf193faf717580d03347148b2145ca98b30b1376d634c12f440420f0000000000a08601000000000002123400
<< {"txid":"b492ea1de2d540288f6e45fd21bc4ac2cd2fcfeb63ec43c50acdb69debfad10a","version":1,"type":"token","time":1547916097,"lockuntil":0,"anchor":"25439b778af5e310a13f2310b48ecb329674ba1dc2054affccef8b73247e742b","vin":[{"txid":"8119097ebc65abd55889e90be6de69c218082d05299951573a455701e55bf40e","vout":0}],"sendto":"1q71vfagprv5hqwckzbvhep0d0ct72j5j2heak2sgp4vptrtc2btdje3q","amount":1.00000000,"txfee":0.10000000,"data":"1234","sig":"","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0"}

>> curl -d '{"id":1,"method":"decodetransaction","jsonrpc":"2.0","params":{"txdata":"01000000000000002b747e24738befccff4a05c21dba749632cb8eb410233fa110e3f58a779b4325010ef45be50157453a57519929052d0818c269dee60be98958d5ab65bc7e0919810001b9c3b7aa16c6cb1bf193faf717580d03347148b2145ca98b30b1376d634c12f440420f0000000000a08601000000000002123400"}}' http://127.0.0.1:9902
<< {"id":1,"jsonrpc":"2.0","result":{"txid":"b492ea1de2d540288f6e45fd21bc4ac2cd2fcfeb63ec43c50acdb69debfad10a","version":1,"type":"token","time":1547916097,"lockuntil":0,"anchor":"25439b778af5e310a13f2310b48ecb329674ba1dc2054affccef8b73247e742b","vin":[{"txid":"8119097ebc65abd55889e90be6de69c218082d05299951573a455701e55bf40e","vout":0}],"sendto":"1q71vfagprv5hqwckzbvhep0d0ct72j5j2heak2sgp4vptrtc2btdje3q","amount":1.00000000,"txfee":0.10000000,"data":"1234","sig":"","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0"}}

Errors:
* {"code":-8,"message":"TX decode failed"}
* {"code":-6,"message":"Unknown anchor block"}

listtransaction - 获取钱包地址的交易信息

Usage:
        listtransaction (-n=count) (-o=offset)

If (offset) < 0,return last (count) transactions,
If (offset) >= 0,return up to (count) most recent transactions skipping the first (offset) transactions.

Arguments:
 -n=count                               (uint, optional) transaction count. If not set, return 10 tx
 -o=offset                              (int, optional) query offset. If not set, from 0

Request:
 "param" :
 {
   "count": 0,                          (uint, optional) transaction count. If not set, return 10 tx
   "offset": 0                          (int, optional) query offset. If not set, from 0
 }

Response:
 "result" :
   [
     "transaction":                     (object, required) wallet transaction data
     {
       "txid": "",                      (string, required) transaction hash
       "fork": "",                      (string, required) fork hash
       "type": "",                      (string, required) transaction type
       "time": 0,                       (uint, required) transaction timestamp
       "send": true|false,              (bool, required) is from me
       "to": "",                        (string, required) to address
       "amount": 0.0,                   (double, required) transaction amount
       "fee": 0.0,                      (double, required) transaction fee
       "lockuntil": 0,                  (uint, required) lockuntil
       "blockheight": 0,                (int, optional) block height
       "from": ""                       (string, optional) from address
     }
   ]

Examples:
>> bigbang-cli listtransaction
<< [{"txid":"4a8e6035b575699cdb25d45beadd49f18fb1303f57ec55493139e65d811e74ff","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","blockheight":31296,"type":"work","time":1547916097,"send":false,"to":"20g098nza351f53wppg0kfnsbxqf80h3x8fwp9vdmc98fbrgbv6mtjagy","amount":15.00000000,"fee":0.00000000,"lockuntil":0},{"txid":"0aa6954236382a6c1c46cce7fa3165b4d1718f5e03ca67cd5fe831616a9000da","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","blockheight":31297,"type":"work","time":1547916097,"send":false,"to":"20g098nza351f53wppg0kfnsbxqf80h3x8fwp9vdmc98fbrgbv6mtjagy","amount":15.00000000,"fee":0.00000000,"lockuntil":0}]

>> curl -d '{"id":2,"method":"listtransaction","jsonrpc":"2.0","params":{}}' http://127.0.0.1:9902
<< {"id":2,"jsonrpc":"2.0","result":[{"txid":"4a8e6035b575699cdb25d45beadd49f18fb1303f57ec55493139e65d811e74ff","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","blockheight":31296,"type":"work","time":1547916097,"send":false,"to":"20g098nza351f53wppg0kfnsbxqf80h3x8fwp9vdmc98fbrgbv6mtjagy","amount":15.00000000,"fee":0.00000000,"lockuntil":0},{"txid":"0aa6954236382a6c1c46cce7fa3165b4d1718f5e03ca67cd5fe831616a9000da","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","blockheight":31297,"type":"work","time":1547916097,"send":false,"to":"20g098nza351f53wppg0kfnsbxqf80h3x8fwp9vdmc98fbrgbv6mtjagy","amount":15.00000000,"fee":0.00000000,"lockuntil":0}]}

>> bigbang-cli listtransaction 1 -1
<< [{"txid":"5a1b7bf5e32a77ecb3c53782a8e06f2b12bdcb73b677d6f89b6f82f85f14373a","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","blockheight":32086,"type":"work","time":1547916097,"send":false,"to":"20g098nza351f53wppg0kfnsbxqf80h3x8fwp9vdmc98fbrgbv6mtjagy","amount":15.00000000,"fee":0.00000000,"lockuntil":0}]

>> curl -d '{"id":0,"method":"listtransaction","jsonrpc":"2.0","params":{"count":1,"offset":-1}}' http://127.0.0.1:9902
<< {"id":0,"jsonrpc":"2.0","result":[{"txid":"5a1b7bf5e32a77ecb3c53782a8e06f2b12bdcb73b677d6f89b6f82f85f14373a","fork":"a63d6f9d8055dc1bd7799593fb46ddc1b4e4519bd049e8eba1a0806917dcafc0","blockheight":32086,"type":"work","time":1547916097,"send":false,"to":"20g098nza351f53wppg0kfnsbxqf80h3x8fwp9vdmc98fbrgbv6mtjagy","amount":15.00000000,"fee":0.00000000,"lockuntil":0}]}

>> listtransaction -n=1 -o=-1

Errors:
* {"code":-6,"message":"Negative, zero or out of range count"}
* {"code":-401,"message":"Failed to list transactions"}

其它RPC命令,请参阅:https://github.com/bigbangcore/BigBang/wiki/JSON-RPC

Clone this wiki locally