diff --git a/api-docs-slate/source/includes/_clients.md b/api-docs-slate/source/includes/_clients.md index d81538a9..219f0f1b 100644 --- a/api-docs-slate/source/includes/_clients.md +++ b/api-docs-slate/source/includes/_clients.md @@ -3,12 +3,10 @@ ## Default Listeners ```shell--visible # With curl you just send HTTP Requests based on further docs -# Only thing to have in mind is Authentication, which is described in Auth section. - -curl http://127.0.0.1:18332/ # will get info from testnet +curl http://127.0.0.1:48332/ # will get info from regtest ``` -By default API listens on these addresses: +By default the API server listens on these `localhost` ports: Network | API Port --------- | ----------- @@ -17,35 +15,33 @@ testnet | 18332 regtest | 48332 simnet | 18556 -You can interact with bcoin with REST Api as well as RPC, -there are couple of ways you can use API. +You can interact with bcoin with its REST API as well as with RPC. +There are couple of ways you can use the API: -- `bcoin-cli` - has almost all methods described to be used. -- `javascript` - Clients used by `bcoin-cli` can be used directly from javascript -- `curl` - or you can use direct HTTP calls for invoking REST/RPC API calls. +- `bcoin-cli` - methods built specifically into bcoin by its developers +- `bcoin-cli rpc` - adds functionality that mimics Bitcoin Core RPC +- `javascript` - methods used by `bcoin-cli` can be accessed directly from javascript +- `curl` - you can use direct HTTP calls for invoking both REST and RPC API calls -## Configuring BCOIN CLI +Only thing to keep in mind is authentication, which is described in the ["Authentication"](#authentication) section. -```shell--visible -# You can use config file -bcoin-cli --config /full/path/to/bcoin.conf -# Or with prefix (which will later load bcoin.conf file from the directory) -bcoin-cli --prefix /full/path/to/bcoin/dir +## Configuring bcoin-cli +```shell--visible # You can configure it by passing arguments: bcoin-cli --network=regtest info bcoin-cli info --network=regtest -# Or use ENV variables (Starting with BCOIN_) +# Or use environment variables (Starting with BCOIN_) export BCOIN_NETWORK=regtest -export BCOIN_API_KEY=yoursecret +export BCOIN_API_KEY=$YOUR-API-KEY bcoin-cli info ``` Install `bcoin-cli` and `bwallet-cli` command line tools with the `bclient` package. Included with `bcoin` by default, but can be installed separately: -`npm install bclient` +`npm install -g bclient` `bcoin-cli` params: @@ -53,58 +49,71 @@ Included with `bcoin` by default, but can be installed separately: Config | Options | Description --------- | ----------- | ----------- -prefix | dir path | This accepts directory where DBs and `bcoin.conf` are located. -network | `main`, `testnet`, `regtest` | This will configure which network to load, also where to look for config file +network | `main`, `testnet`, `regtest` | This will configure which network to load, also where to look for `bcoin.conf` file uri, url | Base HTTP URI | This can be used for custom port -api-key | secret | Secret used by RPC for auth. +api-key | _string_ | Secret used by RPC for authorization ### Wallet Specific Config | Options | Description --------- | ----------- | ----------- -id | primary, custom | specify which account to use by default -token | token str | Token specific wallet +id | _string_ | specify which account to use by default +token | _string_ | Token specific wallet + + +```shell--visible +# Example bcoin.conf syntax: +network: main +prefix: ~/.bcoin +api-key: +``` + +### bcoin.conf and wallet.conf files + +These files may contain any of the configuration parameters, and will be interpreted by bclient at startup. The node and wallet clients look for their own respective conf files. + +[A sample bcoin.conf file is included in the code repository](https://github.com/bcoin-org/bcoin/blob/master/etc/sample.conf) + + + -## Using Javascript Client +## Using Javascript Clients ```javascript--visible -const bcoin = require('bcoin'); -const Client = bcoin.http.Client; -const Wallet = bcoin.http.Wallet; - -const client = new Client({ - network: 'testnet', - uri: 'http://localhost:18332' -}); - -const wallet = new Wallet({ - network: 'testnet', - uri: 'http://localhost:18332', - id: 'primary' -}); +const {NodeClient, WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); +const wallet = new WalletClient(walletOptions); ``` -You can also use api with Javascript Library (used by `bcoin-cli`). -There are two objects: `bcoin.http.Client` for general API and `bcoin.http.Wallet` for wallet API. +You can also use the API with a Javascript library (used by `bcoin-cli`). +There are two objects: `NodeClient` for general API and `WalletClient` for wallet API. +`bcoin` also provides an object `Network` and its method `get` which will return the default configuration paramaters for a specified network. +Custom port numbers are also configurable by the user. -`bcoin.http.Client` options: +`NodeClient` and `WalletClient` options: Config | Type | Description --------- | ----------- | ----------- -network | `main`, `testnet`, `regtest` | Network to use (doesn't lookup configs by itself) -uri | String | URI of the service -apiKey | String | api secret - -`bcoin.http.Wallet` options: +network | _string_ | Network to use: `main`, `testnet`, `regtest` +port | _int_ | bcoin socket port (specific for each network) +apiKey | _string_ | API secret -Config | Type | Description ---------- | ----------- | ----------- -network | `main`, `testnet`, `regtest` | Network to use (doesn't lookup configs by itself) -uri | String | URI of the service -apiKey | String | api secret -id | primary, custom | specify which account to use by default -token | token str | Token specific wallet diff --git a/api-docs-slate/source/includes/_coin.md b/api-docs-slate/source/includes/_coin.md index 3468a7c3..e100bec1 100644 --- a/api-docs-slate/source/includes/_coin.md +++ b/api-docs-slate/source/includes/_coin.md @@ -1,10 +1,14 @@ -# Coin +# bcoin - Coins Getting coin information via API. *Coin stands for UTXO* @@ -19,7 +23,7 @@ let hash, index; ``` ```shell--vars -hash='c13039f53247f9ca14206da079bcf738d91bc60e251ac9ebaba9ea9a862d9092'; +hash='53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc'; index=0; ``` @@ -33,21 +37,21 @@ bcoin-cli coin $hash $index ```javascript const {NodeClient} = require('bclient'); -const client = new NodeClient({ - network: 'testnet' -}); - -(async () => { - await client.open(); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); - const coin = await client.getCoin(hash, index); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(coin); +const client = new NodeClient(clientOptions); - await client.close(); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.getCoin(hash, index); + console.log(result); +})(); ``` > The above command returns JSON structured like this: @@ -55,17 +59,18 @@ const client = new NodeClient({ ```json { "version": 1, - "height": 100019, - "value": 144709200, - "script": "76a9148fc80aadf127f6f92b6ed33404b110f851c8eca188ac", - "address": "mtdCZdNYny2U7met3umk47SoA7HMZGfsa2", + "height": -1, + "value": 30000000, + "script": "76a91400ba915c3d18907b79e6cfcd8b9fdf69edc7a7db88ac", + "address": "R9M3aUWCcKoiqDPusJvqNkAbjffLgCqYip", "coinbase": false, - "hash": "c13039f53247f9ca14206da079bcf738d91bc60e251ac9ebaba9ea9a862d9092", + "hash": "53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc", "index": 0 } ``` -Get coin by outpoint (hash and index). Returns coin in bcoin coin json format. +Get coin by outpoint (hash and index). Returns coin in bcoin coin JSON format. +`value` is always expressed in satoshis. ### HTTP Request `GET /coin/:hash/:index` @@ -85,7 +90,7 @@ let address; ``` ```shell--vars -address='n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr'; +address='R9M3aUWCcKoiqDPusJvqNkAbjffLgCqYip'; ``` ```shell--curl @@ -98,21 +103,21 @@ bcoin-cli coin $address ```javascript const {NodeClient} = require('bclient'); -const client = new NodeClient({ - network: 'testnet' -}); - -(async () => { - await client.open(); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); - const coins = await client.getCoinsByAddress(address); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(coins); +const client = new NodeClient(clientOptions); - await client.close(); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.getCoinsByAddress(address); + console.log(result); +})(); ``` > The above command returns JSON structured like this: @@ -121,13 +126,25 @@ const client = new NodeClient({ [ { "version": 1, - "height": 502, - "value": 275391, - "script": "76a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac", - "address": "n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr", + "height": -1, + "value": 10000000, + "script": "76a91400ba915c3d18907b79e6cfcd8b9fdf69edc7a7db88ac", + "address": "R9M3aUWCcKoiqDPusJvqNkAbjffLgCqYip", "coinbase": false, - "hash": "86150a141ebe5903a5d31e701698a01d598b81f099ea7577dad73033eab02ef9", - "index": 1 + "hash": "2ef8051e6c38e136ba4d195c048e78f9077751758db710475fa532b9d9489324", + "index": 0 + }, + ... + ... + { + "version": 1, + "height": -1, + "value": 50000000, + "script": "76a91400ba915c3d18907b79e6cfcd8b9fdf69edc7a7db88ac", + "address": "R9M3aUWCcKoiqDPusJvqNkAbjffLgCqYip", + "coinbase": false, + "hash": "b3c71dd8959ea97d41324779604b210ae881cdaa5d5abfcbfb3502a0e75c1283", + "index": 0 } ] ``` @@ -151,8 +168,8 @@ let address0, address1; ``` ```shell--vars -address0='n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr'; -address1='mwLHWwWPDwtCBZA7Ltg9QSzKK5icdCU5rb'; +address0='RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ'; +address1='RHpAA3ZmmmWF6FW8qSfaEvh1jR1nUmVYnj'; ``` ```shell--curl @@ -168,18 +185,20 @@ No CLI Option. ```javascript const {NodeClient} = require('bclient'); -const client = new NodeClient({ - network: 'testnet' -}); - -(async () => { - await client.open(); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); - const coins = await client.getCoinsByAddresses([address0, address1]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(coins); +const client = new NodeClient(clientOptions); - await client.close(); +(async () => { + const result = await client.getCoinsByAddresses([address0, address1]); + console.log(result); })().catch((err) => { console.error(err.stack); }); @@ -191,29 +210,29 @@ const client = new NodeClient({ [ { "version": 1, - "height": 502, - "value": 275391, - "script": "76a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac", - "address": "n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr", + "height": -1, + "value": 87654321, + "script": "76a914a4ecde9642f8070241451c5851431be9b658a7fe88ac", + "address": "RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ", "coinbase": false, - "hash": "86150a141ebe5903a5d31e701698a01d598b81f099ea7577dad73033eab02ef9", - "index": 1 + "hash": "4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586", + "index": 0 }, { "version": 1, - "height": 500, - "value": 1095497, - "script": "76a914ad7d7b9ac5260ad13fa55e06143283f5b36495f788ac", - "address": "mwLHWwWPDwtCBZA7Ltg9QSzKK5icdCU5rb", + "height": -1, + "value": 12345678, + "script": "76a9145d9c4bf7f9934668c054f1b1a5589632ddc2b5b088ac", + "address": "RHpAA3ZmmmWF6FW8qSfaEvh1jR1nUmVYnj", "coinbase": false, - "hash": "4692772a73ea834c836915089acf97f2c790380a2b8fd32f82729da72545d8c5", + "hash": "c87c13635f6004a802676a7f93bf90a4b27b433cf26db0c41a656f377406f3e3", "index": 0 } ] + ``` -Get coins by addresses, -returns array of coin objects. +Get coins by addresses, returns array of coin objects. ### HTTP Request `POST /coin/address` diff --git a/api-docs-slate/source/includes/_node.md b/api-docs-slate/source/includes/_node.md index c01f97fb..778290d2 100644 --- a/api-docs-slate/source/includes/_node.md +++ b/api-docs-slate/source/includes/_node.md @@ -1,20 +1,25 @@ -# Node +# bcoin - Node -## JSON-RPC Requests +## bcoin client requests -Route for JSON-RPC requests, most of which mimic the bitcoind RPC calls completely. +Complete list of commands: -```shell--curl -curl $url \ - -H 'Content-Type: application/json' \ - -X POST \ - --data '{ "method": "getblockchaininfo", "params": [] }' -``` +Command |cURL method | Description +----------------------------|---------------|------------ +`/` | `GET` | get info +`/coin/address/:address` | `GET` | UTXO by address +`/coin/:hash/:index` | `GET` | UTXO by txid +`/coin/address` | `POST` | Bulk read UTXOs +`/tx/:hash` | `GET` | TX by hash +`/tx/address/:address` | `GET` | TX by address +`/tx/address` | `POST` | Bulk read TXs +`/block/:block` | `GET` | Block by hash or height +`/mempool` | `GET` | Mempool snapshot +`/broadcast` | `POST` | Broadcast TX +`/fee` | `GET` | Estimate fee +`/reset` | `POST` | Reset chain to specific height -### HTTP Request -`POST /` -More about RPC Requests in RPC Docs. ## Get server info @@ -28,57 +33,58 @@ bcoin-cli info ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - await client.open(); - const info = await client.getInfo(); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(info); +const client = new NodeClient(clientOptions); - await client.close(); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const clientinfo = await client.getInfo(); + console.log(clientinfo); +})(); ``` > The above command returns JSON structured like this: ```json { - "version": "v1.0.0-beta.14", - "network": "testnet", + "version": "v1.0.0-pre", + "network": "regtest", "chain": { - "height": 1157058, - "tip": "00000000000002ac70408966be53a1e01e7e014a3d4f1f275201c751de7d6e77", + "height": 205, + "tip": "38d4ff72bca6737d958e1456be90443c0e09186349f28b952564118ace222331", "progress": 1 }, "pool": { - "host": "203.0.113.114", - "port": 18333, - "agent": "/bcoin:v1.0.0-beta.14/", + "host": "18.188.224.12", + "port": 48444, + "agent": "/bcoin:v1.0.0-pre/", "services": "1001", - "outbound": 8, - "inbound": 0 + "outbound": 1, + "inbound": 1 }, "mempool": { - "tx": 39, - "size": 121512 + "tx": 0, + "size": 0 }, "time": { - "uptime": 7403, - "system": 1502381034, - "adjusted": 1502381035, - "offset": 1 + "uptime": 1744, + "system": 1527028546, + "adjusted": 1527028546, + "offset": 0 }, "memory": { - "total": 87, - "jsHeap": 23, - "jsHeapTotal": 30, - "nativeHeap": 56, - "external": 8 + "total": 90, + "jsHeap": 19, + "jsHeapTotal": 26, + "nativeHeap": 64, + "external": 9 } } ``` @@ -105,17 +111,20 @@ bcoin-cli mempool ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - await client.open(); - const mempoolTxs = await client.getMempool(); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(mempoolTxs); +const client = new NodeClient(clientOptions); - await client.close(); +(async () => { + const mempool = await client.getMempool(); + console.log(mempool); })().catch((err) => { console.error(err.stack); }); @@ -125,8 +134,11 @@ const rpc = new NodeClient({ ```json [ - "9fee8350a3cc2f5bfa9d90f008af0bbc22d84aa5b1242da2f3479935f597c9ed", - "d3bd772f3b369e2e04b9b928e40dddded5ee1448b9d1ee0b6a13e6c2ae283f6a", + "2ef8051e6c38e136ba4d195c048e78f9077751758db710475fa532b9d9489324", + "bc3308b61959664b71ac7fb8e9ee17d13476b5a32926f512882851b7631884f9", + "53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc", + "fff647849be7408faedda377eea6c37718ab39d656af8926e0b4b74453624f32", + "b3c71dd8959ea97d41324779604b210ae881cdaa5d5abfcbfb3502a0e75c1283", ... ] ``` @@ -146,8 +158,8 @@ let blockHash, blockHeight; ``` ```shell--vars -blockHash='00000000cabd2d0245add40f335bab18d3e837eccf868b64aabbbbac74fb21e0'; -blockHeight='1500'; +blockHash='4003e57eb1c60f3d1b774d8a281353c35cd30dca0d76b751c8dd862da11c41de'; +blockHeight='94'; ``` ```shell--curl @@ -162,53 +174,54 @@ bcoin-cli block $blockHeight # by height ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - await client.open(); - const blockByHash = await client.getBlock(blockHash); - const blockByHeight = await client.getBlock(blockHeight); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(blockByHash, blockByHeight); +const client = new NodeClient(clientOptions); - await client.close(); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const blockByHeight = await client.getBlock(blockHeight); + const blockByHash = await client.getBlock(blockHash); + console.log("By height: \n", blockByHeight); + console.log("By hash: \n", blockByHash); +})(); ``` > The above command returns JSON structured like this: ```json { - "hash": "00000000cabd2d0245add40f335bab18d3e837eccf868b64aabbbbac74fb21e0", - "height": 1500, - "version": 1, - "confirmations": 1192251, - "prevBlock": "00000000f651e7fe6d9a4845dcf40f5642216e59054453a4368a73a7295f9f3d", - "merkleRoot": "e3e4590784a828967e6d9319eca2915c1860a63167449f9605e649a0aafe6d0a", - "time": 1337966228, - "bits": 486604799, - "nonce": 2671491584, + "hash": "4003e57eb1c60f3d1b774d8a281353c35cd30dca0d76b751c8dd862da11c41de", + "height": 94, + "depth": 112, + "version": 536870912, + "prevBlock": "353cbab0d0ae1583ceb6bd88d90f44a7bb2cb2aec824eac688dbf1832e648962", + "merkleRoot": "b23e398ccf2fe2dcf81c6e7b4cc3c710a79c78bf7e8a63dd819acf83952f960f", + "time": 1527028558, + "bits": 545259519, + "nonce": 4, "txs": [ { - "hash": "e3e4590784a828967e6d9319eca2915c1860a63167449f9605e649a0aafe6d0a", - "witnessHash": "e3e4590784a828967e6d9319eca2915c1860a63167449f9605e649a0aafe6d0a", + "hash": "b23e398ccf2fe2dcf81c6e7b4cc3c710a79c78bf7e8a63dd819acf83952f960f", + "witnessHash": "b23e398ccf2fe2dcf81c6e7b4cc3c710a79c78bf7e8a63dd819acf83952f960f", "fee": 0, "rate": 0, - "mtime": 1502382669, + "mtime": 1527028763, "index": 0, "version": 1, - "flag": 1, "inputs": [ { "prevout": { "hash": "0000000000000000000000000000000000000000000000000000000000000000", "index": 4294967295 }, - "script": "0494bebf4f0108172f503253482f49636549726f6e2d51432d6d696e65722f", + "script": "015e0e6d696e65642062792062636f696e04899fe44e080000000000000000", "witness": "00", "sequence": 4294967295, "address": null @@ -217,11 +230,12 @@ const rpc = new NodeClient({ "outputs": [ { "value": 5000000000, - "script": "21032fd2666c8d5ffae0147acc0b9628160652679663397e911170ebaf1e26358abfac", - "address": "mtohBeScUtM2ndcmmpSV8o2jcvmknp1Mpy" + "script": "76a91420a060fec9a7dfac723c521e168876909aa37ce588ac", + "address": "RCFhpyWXkz5GxskL96q4KtceRXuAMnWUQo" } ], - "locktime": 0 + "locktime": 0, + "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f015e0e6d696e65642062792062636f696e04899fe44e080000000000000000ffffffff0100f2052a010000001976a91420a060fec9a7dfac723c521e168876909aa37ce588ac00000000" } ] } @@ -247,7 +261,7 @@ let tx; ``` ```shell--vars -tx='0100000001ff2a3afc3a8133a3bfeedd391bc3cff39d47fe4e3caee492a93f92edff76b9d4000000006a47304402204cc6a35cb3d3d976cb10e3c98df66aba29b5efc7b5ecdbc0f4ed949aa64235f20220512fce2d63739012094f12c3a9402919b32149c32d4d71a3448d4695ae8e3dc601210325c9abd8916d6e5ba0b3c501a70c0186f3bf6e4567922b9d83ae205d1d9e9affffffffff0244cff505000000001976a91423f5580d600bcfe5b99d9fe737530fd8b32492a088ac00111024010000001976a91473f3ecd665da93701358bd957393b8085c1aa2d988ac00000000'; +tx='010000000106b014e37704109fefe2c5c9f4227d68840c3497fc89a9832db8504df039a6c7000000006a47304402207dc8173fbd7d23c3950aaf91b1bc78c0ed9bf910d47a977b24a8478a91b28e69022024860f942a16bc67ec54884e338b5b87f4a9518a80f9402564061a3649019319012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46affffffff0280c3c901000000001976a91400ba915c3d18907b79e6cfcd8b9fdf69edc7a7db88acc41c3c28010000001976a91437f306a0154e1f0de4e54d6cf9d46e07722b722688ac00000000'; ``` ```shell--curl @@ -258,26 +272,26 @@ curl $url/broadcast \ ``` ```shell--cli -bcoin-cli broadcast $txhex +bcoin-cli broadcast $tx ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet', -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - await client.open(); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - const result = await client.broadcast(tx); +const client = new NodeClient(clientOptions); +(async () => { + const result = await client.broadcast(tx); console.log(result); - - await client.close(); -})().catch((err) => { - console.error(err.stack); -}); +})(); ``` > The above command returns JSON structured like this: diff --git a/api-docs-slate/source/includes/_node_rpc.md b/api-docs-slate/source/includes/_node_rpc.md index 1ed3e409..be041f27 100644 --- a/api-docs-slate/source/includes/_node_rpc.md +++ b/api-docs-slate/source/includes/_node_rpc.md @@ -1,48 +1,60 @@ # RPC Calls - Node ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ - --data '{ "method": "methodname", "params": [...] "id": "some-id" }' + --data '{ "method": "", "params": [...] "id": "some-id" }' ``` ```shell--cli -bcoin-cli rpc params... +bcoin-cli rpc ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('MethodName', [ ...params ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - // RES will return "result" part of the object, not the id or error - // error will be thrown. -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('', [ ]); + console.log(result); +})(); ``` -> The above command returns JSON structured like this: - -> Further examples will only include "result" part. +> The above cURL command returns JSON structured like this: ```json {"result": resultObject ,"error": errorObject, "id": passedID} ``` +> Further examples will only include "result" part. +> CLI and Javascript calls return just the "result" or an error. + -Bcoin rpc calls mimic Bitcoin Core's RPC. -This is documentation how to use it with `bcoin`. + + +bcoin RPC calls mimic Bitcoin Core's RPC. RPC Calls are accepted at: `POST /` -*Note: bcoin-cli rpc and javascript will return error OR result.* +*Notes:* + +*bcoin-cli rpc and Javascript will either return an error OR the result.* + +*Javascript result will return the "result" part of the object, not the id or error* + +*If a Javascript error is encountered it will be thrown instead of returned in JSON* + +*Be sure to check the debug log for error reports as well!* ### POST Parameters RPC @@ -50,4 +62,4 @@ Parameter | Description --------- | ----------- method | Name of the RPC call params | Parameters accepted by method -id | Will be returned with the response (Shouldn't be object) +id | `int` Will be returned with the response (cURL only) diff --git a/api-docs-slate/source/includes/_node_rpc_block.md b/api-docs-slate/source/includes/_node_rpc_block.md index 543e7305..af25e462 100644 --- a/api-docs-slate/source/includes/_node_rpc_block.md +++ b/api-docs-slate/source/includes/_node_rpc_block.md @@ -3,8 +3,7 @@ ## getblockchaininfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getblockchaininfo" }' ``` @@ -15,67 +14,71 @@ bcoin-cli rpc getblockchaininfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getblockchaininfo'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getblockchaininfo'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "chain": "test", - "blocks": 1178402, - "headers": 1178402, - "bestblockhash": "0000000000000dd897f549915ba7099b6d4f86f4512801d617a7c0c655827d08", - "difficulty": 1048576, - "mediantime": 1502814951, - "verificationprogress": 1, - "chainwork": "00000000000000000000000000000000000000000000002976ca78529498e335", + "chain": "regtest", + "blocks": 98, + "headers": 98, + "bestblockhash": "498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512", + "difficulty": 4.6565423739069247e-10, + "mediantime": 1527028558, + "verificationprogress": 0.9997162305340502, + "chainwork": "00000000000000000000000000000000000000000000000000000000000000c6", "pruned": false, "softforks": [ { "id": "bip34", "version": 2, "reject": { - "status": true + "status": false } }, { "id": "bip66", "version": 3, "reject": { - "status": true + "status": false } }, { "id": "bip65", "version": 4, "reject": { - "status": true + "status": false } } ], "bip9_softforks": { "csv": { - "status": "active", + "status": "defined", "bit": 0, - "startTime": 1456790400, - "timeout": 1493596800 + "startTime": 0, + "timeout": 4294967295 }, "segwit": { - "status": "active", + "status": "defined", "bit": 1, - "startTime": 1462060800, - "timeout": 1493596800 + "startTime": 0, + "timeout": 4294967295 }, "segsignal": { "status": "defined", @@ -84,10 +87,10 @@ const rpc = new NodeClient({ "timeout": 4294967295 }, "testdummy": { - "status": "failed", + "status": "defined", "bit": 28, - "startTime": 1199145601, - "timeout": 1230767999 + "startTime": 0, + "timeout": 4294967295 } }, "pruneheight": null @@ -106,8 +109,7 @@ None. | ## getbestblockhash ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getbestblockhash" }' ``` @@ -118,23 +120,27 @@ bcoin-cli rpc getbestblockhash ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getbestblockhash'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getbestblockhash'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -"0000000000000225f8332239fe00b74c65f916ff71dde5dee33b72ddd3b0e237" +"498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512" ``` Returns Block Hash of the tip. @@ -150,35 +156,38 @@ None. | ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getblockcount" }' ``` ```shell--cli -bcoin-cli rpc getbestblockhash +bcoin-cli rpc getblockcount ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getblockcount'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getblockcount'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -1178418 +98 ``` Returns block count. @@ -197,18 +206,17 @@ let blockhash, details, verbose; ``` ```shell--vars -blockhash='00000000e0290b7c66227c7499692aac5437860ee912424bf8eea3a3883a4e37'; +blockhash='498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512'; verbose=1; details=0; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getblock", - "params": [ "'$blockhash'", "'$verbose'", "'$details'" ] + "params": [ "'$blockhash'", '$verbose', '$details' ] }' ``` @@ -218,51 +226,47 @@ bcoin-cli rpc getblock $blockhash $verbose $details ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getblock', [ blockhash, verbose, details ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getblock', [ blockhash, verbose, details ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "hash": "00000000e0290b7c66227c7499692aac5437860ee912424bf8eea3a3883a4e37", - "confirmations": 1177921, - "strippedsize": 2499, - "size": 2499, - "weight": 9996, - "height": 502, - "version": 1, - "versionHex": "00000001", - "merkleroot": "4f7a9087973b891fc86cc59fd9c2cb696f7a813360d3553626dc6c38909f9571", - "coinbase": "3337346bde777ade327922b5deef5fb7f88e98cecb22", + "hash": "498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512", + "confirmations": 1, + "strippedsize": 197, + "size": 197, + "weight": 788, + "height": 98, + "version": 536870912, + "versionHex": "20000000", + "merkleroot": "674527b1b1b8604677a0b9e3f7a62fd733af9eba254d9f98748d3d0afdf35602", + "coinbase": "01620e6d696e65642062792062636f696e046d2df7a0080000000000000000", "tx": [ - "2a69b021fc6cbd61260767302781c85fb0873acf18980ea6187fc868e4a3e3f9", - "c61f2ef26bb08dcf1e16db4fece56ac92a3acac24e4dac90315e5c0ad6af67e6", - "ed8c8213cc2d214ad2f293caae99e26e2c59d158f3eda5d9c1292e0961e20e76", - "21da008d1fddc1a067d2d6cd9bb6e78acb5bdc9560252c17cfd59c331dd5c2cf", - "90cc439e0a03109c33c966d92ccd18b0509ef678458d85a097397ee9bfbd54c0", - "1d67f7466fd711f8106fb437cb6a59b7ccd14cd6069edc132627a9fb01d4f09c", - "402450f5b4cd794d4198f940977bf4291ce25a7ff8b157adf71c07ed065db380", - "0173a5d24d393127d5e6fc043ff1a00dafc6a2777143cb98a803a0b6e8cd02c7", - "86150a141ebe5903a5d31e701698a01d598b81f099ea7577dad73033eab02ef9" + "674527b1b1b8604677a0b9e3f7a62fd733af9eba254d9f98748d3d0afdf35602" ], - "time": 1296746959, - "mediantime": 1296746728, - "bits": 486604799, - "difficulty": 1, - "chainwork": "000000000000000000000000000000000000000000000000000001f701f701f7", - "previousblockhash": "00000000c7f50b6dfac8b8a59e11b7e62f07fdef20597089b9c5d64ebfe6d682", - "nextblockhash": "00000000f797111d0f67d7f08346757948e7c469f14cddbd1c3d0217306bf003" + "time": 1527028559, + "mediantime": 1527028558, + "bits": 545259519, + "difficulty": 4.6565423739069247e-10, + "chainwork": "00000000000000000000000000000000000000000000000000000000000000c6", + "previousblockhash": "267bec5755cb8362828351a1bedb0de8c8ab37a58627070a79b7aa48d09c7276", + "nextblockhash": null } ``` @@ -284,18 +288,17 @@ let blockhash, details, verbose; ``` ```shell--vars -blockheight=502; +blockheight=50; verbose=1; details=0; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getblockbyheight", - "params": [ "'$blockheight'", "'$verbose'", "'$details'" ] + "params": [ '$blockheight', '$verbose', '$details' ] }' ``` @@ -305,51 +308,47 @@ bcoin-cli rpc getblockbyheight $blockheight $verbose $details ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getblockbyheight', [ blockheight, verbose, details ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getblockbyheight', [ blockheight, verbose, details ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "hash": "00000000e0290b7c66227c7499692aac5437860ee912424bf8eea3a3883a4e37", - "confirmations": 1177921, - "strippedsize": 2499, - "size": 2499, - "weight": 9996, - "height": 502, - "version": 1, - "versionHex": "00000001", - "merkleroot": "4f7a9087973b891fc86cc59fd9c2cb696f7a813360d3553626dc6c38909f9571", - "coinbase": "3337346bde777ade327922b5deef5fb7f88e98cecb22", + "hash": "51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318", + "confirmations": 49, + "strippedsize": 197, + "size": 197, + "weight": 788, + "height": 50, + "version": 536870912, + "versionHex": "20000000", + "merkleroot": "8e2d404a039a7a3e1768b161aa23546aab0444b73905bdd3d68b3d6f1769e8c0", + "coinbase": "01320e6d696e65642062792062636f696e04a829b925080000000000000000", "tx": [ - "2a69b021fc6cbd61260767302781c85fb0873acf18980ea6187fc868e4a3e3f9", - "c61f2ef26bb08dcf1e16db4fece56ac92a3acac24e4dac90315e5c0ad6af67e6", - "ed8c8213cc2d214ad2f293caae99e26e2c59d158f3eda5d9c1292e0961e20e76", - "21da008d1fddc1a067d2d6cd9bb6e78acb5bdc9560252c17cfd59c331dd5c2cf", - "90cc439e0a03109c33c966d92ccd18b0509ef678458d85a097397ee9bfbd54c0", - "1d67f7466fd711f8106fb437cb6a59b7ccd14cd6069edc132627a9fb01d4f09c", - "402450f5b4cd794d4198f940977bf4291ce25a7ff8b157adf71c07ed065db380", - "0173a5d24d393127d5e6fc043ff1a00dafc6a2777143cb98a803a0b6e8cd02c7", - "86150a141ebe5903a5d31e701698a01d598b81f099ea7577dad73033eab02ef9" + "8e2d404a039a7a3e1768b161aa23546aab0444b73905bdd3d68b3d6f1769e8c0" ], - "time": 1296746959, - "mediantime": 1296746728, - "bits": 486604799, - "difficulty": 1, - "chainwork": "000000000000000000000000000000000000000000000000000001f701f701f7", - "previousblockhash": "00000000c7f50b6dfac8b8a59e11b7e62f07fdef20597089b9c5d64ebfe6d682", - "nextblockhash": "00000000f797111d0f67d7f08346757948e7c469f14cddbd1c3d0217306bf003" + "time": 1527028551, + "mediantime": 1527028550, + "bits": 545259519, + "difficulty": 4.6565423739069247e-10, + "chainwork": "0000000000000000000000000000000000000000000000000000000000000066", + "previousblockhash": "69eef02e5b7e2558f96a7e9ecb47dbbc4dd9fb1aa46cc22f36d8e7ee1edde33d", + "nextblockhash": "7f734e621cc3e08834063b9482aa89e0bcaf29e7812b83494f3891c7955958fb" } ``` @@ -371,16 +370,15 @@ let blockheight; ``` ```shell--vars -blockheight=502; +blockheight=50; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getblockhash", - "params": [ "'$blockheight'" ] + "params": [ '$blockheight' ] }' ``` @@ -390,26 +388,30 @@ bcoin-cli rpc getblockhash $blockheight ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getblockhash', [ blockheight ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getblockhash', [ blockheight ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -"00000000e0290b7c66227c7499692aac5437860ee912424bf8eea3a3883a4e37" +"51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318" ``` -Returns block's hash by height. +Returns block's hash given its height. ### Params N. | Name | Default | Description @@ -425,17 +427,16 @@ let blockhash, verbose; ``` ```shell--vars -blockhash='00000000e0290b7c66227c7499692aac5437860ee912424bf8eea3a3883a4e37'; +blockhash='51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318'; verbose=1; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getblockheader", - "params": [ "'$blockhash'", "'$details'" ] + "params": [ "'$blockhash'", '$details' ] }' ``` @@ -445,40 +446,44 @@ bcoin-cli rpc getblockheader $blockhash $verbose ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getblockheader', [ blockheight, verbose ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getblockheader', [ blockhash, verbose ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "hash": "00000000e0290b7c66227c7499692aac5437860ee912424bf8eea3a3883a4e37", - "confirmations": 1177934, - "height": 502, - "version": 1, - "versionHex": "00000001", - "merkleroot": "4f7a9087973b891fc86cc59fd9c2cb696f7a813360d3553626dc6c38909f9571", - "time": 1296746959, - "mediantime": 1296746728, - "bits": 486604799, - "difficulty": 1, - "chainwork": "000000000000000000000000000000000000000000000000000001f701f701f7", - "previousblockhash": "00000000c7f50b6dfac8b8a59e11b7e62f07fdef20597089b9c5d64ebfe6d682", - "nextblockhash": "00000000f797111d0f67d7f08346757948e7c469f14cddbd1c3d0217306bf003" + "hash": "51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318", + "confirmations": 49, + "height": 50, + "version": 536870912, + "versionHex": "20000000", + "merkleroot": "8e2d404a039a7a3e1768b161aa23546aab0444b73905bdd3d68b3d6f1769e8c0", + "time": 1527028551, + "mediantime": 1527028550, + "bits": 545259519, + "difficulty": 4.6565423739069247e-10, + "chainwork": "0000000000000000000000000000000000000000000000000000000000000066", + "previousblockhash": "69eef02e5b7e2558f96a7e9ecb47dbbc4dd9fb1aa46cc22f36d8e7ee1edde33d", + "nextblockhash": "7f734e621cc3e08834063b9482aa89e0bcaf29e7812b83494f3891c7955958fb" } ``` -Returns block's header by hash. +Returns a block's header given its hash. ### Params N. | Name | Default | Description @@ -491,8 +496,7 @@ N. | Name | Default | Description ## getchaintips ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getchaintips" @@ -505,17 +509,21 @@ bcoin-cli rpc getchaintips ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getchaintips'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getchaintips'); + console.log(result); +})(); ``` Returns chaintips. @@ -525,17 +533,11 @@ Returns chaintips. ```json [ { - "height": 1159071, - "hash": "0000000000043bc8896351bf4fbb9fadfa596566e6d88078a2364252346e0d2a", - "branchlen": 1, - "status": "valid-headers" - }, - { - "height": 1158313, - "hash": "0000000000011e8328cf0382888e07f207e178e967f896794d600e39c962362e", - "branchlen": 1, - "status": "valid-headers" - }, + "height": 98, + "hash": "498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512", + "branchlen": 0, + "status": "active" + } ... ] ``` @@ -550,8 +552,7 @@ None. | ## getdifficulty ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getdifficulty" @@ -564,17 +565,21 @@ bcoin-cli rpc getdifficulty ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getdifficulty'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getdifficulty'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: diff --git a/api-docs-slate/source/includes/_node_rpc_chain.md b/api-docs-slate/source/includes/_node_rpc_chain.md index 2443df5b..c89da725 100644 --- a/api-docs-slate/source/includes/_node_rpc_chain.md +++ b/api-docs-slate/source/includes/_node_rpc_chain.md @@ -3,8 +3,7 @@ ## pruneblockchain ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "pruneblockchain", @@ -18,17 +17,21 @@ bcoin-cli rpc pruneblockchain ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('pruneblockchain'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('pruneblockchain'); + console.log(result); +})(); ``` Prunes the blockchain, it will keep blocks specified in Network Configurations. @@ -54,12 +57,11 @@ let blockhash; ``` ```shell--vars -blockhash='0000000000000dca8da883af9515dd90443d59139adbda3f9eeac1d18397fec3'; +blockhash='52d7beaf4c7f392bef2744167c7f4db4bb4113b2635496edcf2d1c94128696aa'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "invalidateblock", @@ -73,24 +75,28 @@ bcoin-cli rpc invalidateblock $blockhash ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('invalidateblock', [ blockhash ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('invalidateblock', [ blockhash ]); + console.log(result); +})(); ``` Invalidates the block in the chain. It will rewind network to blockhash and invalidate it. -It won't accept that block as valid +It won't accept that block as valid. *Invalidation will work while running, restarting node will remove invalid block from list.* ### Params @@ -107,12 +113,11 @@ let blockhash; ``` ```shell--vars -blockhash='0000000000000dca8da883af9515dd90443d59139adbda3f9eeac1d18397fec3'; +blockhash='1896e628f8011b77ea80f4582c29c21b3376183683f587ee863050376add3891' ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "reconsiderblock", @@ -126,14 +131,20 @@ bcoin-cli rpc reconsiderblock $blockhash ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('reconsiderblock', [ blockhash ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('reconsiderblock', [ blockhash ]); + console.log(result); })().catch((err) => { console.error(err.stack); }); diff --git a/api-docs-slate/source/includes/_node_rpc_general.md b/api-docs-slate/source/includes/_node_rpc_general.md index b0a485fe..c9b326ac 100644 --- a/api-docs-slate/source/includes/_node_rpc_general.md +++ b/api-docs-slate/source/includes/_node_rpc_general.md @@ -13,17 +13,21 @@ bcoin-cli rpc stop ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('stop'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('stop'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -44,13 +48,9 @@ None. | ## getinfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ - --data '{ - "method": "getinfo", - "params": [] - }' + --data '{ "method": "getinfo" }' ``` ```shell--cli @@ -59,32 +59,36 @@ bcoin-cli rpc getinfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getinfo'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getinfo'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "version": "v1.0.0-beta.14", + "version": "v1.0.0-pre", "protocolversion": 70015, "walletversion": 0, "balance": 0, - "blocks": 1178980, + "blocks": 205, "timeoffset": 0, - "connections": 8, + "connections": 3, "proxy": "", - "difficulty": 1048576, + "difficulty": 4.6565423739069247e-10, "testnet": true, "keypoololdest": 0, "keypoolsize": 0, @@ -108,13 +112,9 @@ None. | ## getmemoryinfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ - --data '{ - "method": "getmemoryinfo", - "params": [] - }' + --data '{ "method": "getmemoryinfo" }' ``` ```shell--cli @@ -123,28 +123,32 @@ bcoin-cli rpc getmemoryinfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getmemoryinfo'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getmemoryinfo'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "total": 99, - "jsHeap": 19, - "jsHeapTotal": 29, - "nativeHeap": 69, - "external": 10 + "total": 72, + "jsHeap": 14, + "jsHeapTotal": 17, + "nativeHeap": 54, + "external": 12 } ``` @@ -161,8 +165,7 @@ None. | ## setloglevel ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "setloglevel", @@ -176,17 +179,21 @@ bcoin-cli rpc setloglevel none ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('setloglevel', [ 'none' ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('setloglevel', [ 'none' ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -212,12 +219,11 @@ let address; ``` ```shell--vars -address='n34pHHSqsXJQwq9FXUsrfhmTghrVtN74yo'; +address='RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ'; ``` ```shell--curl curl $url/ \ - -H 'Content-Type: application/json' \ -X POST \ --data '{ "method": "validateaddress", @@ -231,17 +237,21 @@ bcoin-cli rpc validateaddress $address ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('validateaddress', [ address ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('validateaddress', [ address ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -249,8 +259,8 @@ const rpc = new NodeClient({ ```json { "isvalid": true, - "address": "n34pHHSqsXJQwq9FXUsrfhmTghrVtN74yo", - "scriptPubKey": "76a914ec61435a3c8f0efee2ffafb8ddb4e1440d2db8d988ac", + "address": "RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ", + "scriptPubKey": "76a914a4ecde9642f8070241451c5851431be9b658a7fe88ac", "ismine": false, "iswatchonly": false } @@ -274,18 +284,17 @@ let nrequired, pubkey0, pubkey1, pubkey2; ```shell--vars nrequired=2; -pubkey0='02b3280e779a7c849f9d6460e926097fe4b0f6280fa6fd038ce8e1236a4688c358'; -pubkey1='021f1dbc575db95a44e016fe6ecf00231109e7799d9b1e007dbe8814017cf0d65c'; -pubkey2='0315613667e3ebe065c0b8d86ae0443d97de56545bdf38c99a6ee584f300206d9a'; +pubkey0='02e3d6bb36b0261628101ee67abd89d678522dc1199912512f814e70803652f395'; +pubkey1='03d7ded41bb871936bf4d411371b25d706c572f28ef8d2613b45392e9f9c4348a5'; +pubkey2='034bc2280e68d3bdd0ef0664e0ad2949a467344d8e59e435fe2d9be81e39f70f76'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "createmultisig", - "params": [ "'$nrequired'", [ "'$pubkey0'", "'$pubkey1'", "'$pubkey2'" ] ] + "params": [ '$nrequired', [ "'$pubkey0'", "'$pubkey1'", "'$pubkey2'" ] ] }' ``` @@ -295,27 +304,30 @@ bcoin-cli rpc createmultisig $nrequired '[ "'$pubkey0'", "'$pubkey1'", "'$pubkey ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('createmultisig', [ nrequired, [ pubkey0, pubkey1, pubkey2 ] ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('createmultisig', [ nrequired, [ pubkey0, pubkey1, pubkey2 ] ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "address": "2MzY9R5P1Wfy9aNdqyoH63K1EQZF7APuZ4S", - "redeemScript": "5221021f1dbc575db95a44e016fe6ecf00231109e7799d9b1e007dbe8814017cf0d65c2102b3280e779a7c849f9d6460e926097fe4b0f6280fa6fd038ce8e1236a4688c358210315613667e3ebe065c0b8d86ae0443d97de56545bdf38c99a6ee584f300206d9a53ae" + "address": "GfNqJAAyrCLr2bVHxn8wjMMYMh1EBPzUNk", + "redeemScript": "522102e3d6bb36b0261628101ee67abd89d678522dc1199912512f814e70803652f39521034bc2280e68d3bdd0ef0664e0ad2949a467344d8e59e435fe2d9be81e39f70f762103d7ded41bb871936bf4d411371b25d706c572f28ef8d2613b45392e9f9c4348a553ae" } - ``` create multisig address @@ -339,8 +351,7 @@ script='5221021f1dbc575db95a44e016fe6ecf00231109e7799d9b1e007dbe8814017cf0d65c21 ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "createwitnessaddress", @@ -354,24 +365,28 @@ bcoin-cli rpc createwitnessaddress $script ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('createwitnessaddress', [ script ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('createwitnessaddress', [ script ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "address": "tb1qlfgqame3n0dt2ldjl2m9qjg6n2vut26jw3ezm25hqx9ez4m9wp5q567kg2", + "address": "rb1qlfgqame3n0dt2ldjl2m9qjg6n2vut26jw3ezm25hqx9ez4m9wp5qjres8a", "witnessScript": "0020fa500eef319bdab57db2fab650491a9a99c5ab5274722daa97018b9157657068" } ``` @@ -392,13 +407,12 @@ let privkey, message; ``` ```shell--vars -privkey='EL4QU6ViZvT4RuCTCivw2uBnvBPSamP5jMtH31gGQLbEEcmNCHVz'; +privkey='EMyedBwL5mb476uhWZ2wzEsSpu8kZwYgYaw5rGbjJh1kRjXF3M2d'; message='hello'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "signmessagewithprivkey", @@ -412,27 +426,32 @@ bcoin-cli rpc signmessagewithprivkey $privkey $message ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('signmessagewithprivkey', [ privkey, message ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('signmessagewithprivkey', [ privkey, message ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -"MEQCIAwF9NPMo5KBRsCWTBJ2r69/h7CfDl+RQfxxwAbNp1WJAiAiubiK5rg9MugiU7EHpwbJLc3b356LAedob0ePI40Wmg==" +"MEUCIQCGLPYuLuSU1XQ7ctRvRzrY4M0dKAxShzEN3fwVoelGvgIgPmQ2RcRpeu0o68YsN42yzykI9VfTPooWHMvsFbIFEkg=" ``` -Signs message with private key. +Signs message with private key. + ### Params N. | Name | Default | Description @@ -448,38 +467,41 @@ let address, signature, message; ``` ```shell--vars -address='R9LTC6Sp6Zwk71qUrm81sEdsppFNiDM6mF'; -signature='MEQCIAwF9NPMo5KBRsCWTBJ2r69/h7CfDl+RQfxxwAbNp1WJAiAiubiK5rg9MugiU7EHpwbJLc3b356LAedob0ePI40Wmg=='; +address='RGCudRpNcn299Ja1EaVzgpnPD3YJgfMMiB'; +signature='MEUCIQCGLPYuLuSU1XQ7ctRvRzrY4M0dKAxShzEN3fwVoelGvgIgPmQ2RcRpeu0o68YsN42yzykI9VfTPooWHMvsFbIFEkg='; message='hello'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "verifymessage", - "params": [ "'$address'", "'$signature'", "'$message'" ] + "params": [ "'$address'", "'$signature'", "$message" ] }' ``` ```shell--cli -bcoin-cli rpc verifymessage $address $signature $message +bcoin-cli rpc verifymessage $address $signature "$message" ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('verifymessage', [ address, signature, message ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('verifymessage', [ address, signature, message ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -488,7 +510,9 @@ const rpc = new NodeClient({ true ``` -Verify sign +Verify signature. + + ### Params N. | Name | Default | Description @@ -508,8 +532,7 @@ timestamp=1503058155; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "setmocktime", @@ -523,17 +546,21 @@ bcoin-cli rpc setmocktime $timestamp ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('setmocktime', [ timestamp ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('setmocktime', [ timestamp ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: diff --git a/api-docs-slate/source/includes/_node_rpc_mempool.md b/api-docs-slate/source/includes/_node_rpc_mempool.md index d288e392..15394f54 100644 --- a/api-docs-slate/source/includes/_node_rpc_mempool.md +++ b/api-docs-slate/source/includes/_node_rpc_mempool.md @@ -3,8 +3,7 @@ ## getmempoolinfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getmempoolinfo" @@ -17,26 +16,30 @@ bcoin-cli rpc getmempoolinfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getmempoolinfo'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getmempoolinfo'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "size": 20, - "bytes": 68064, - "usage": 68064, + "size": 5, + "bytes": 14120, + "usage": 14120, "maxmempool": 100000000, "mempoolminfee": 0.00001 } @@ -58,17 +61,16 @@ let txhash, verbose; ``` ```shell--vars -txhash='939a3b8485b53a718d89e7e4412473b3762fa1d9bbd555fc8b01e73be0ab1881'; +txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; verbose=1; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getmempoolancestors", - "params": [ "'$txhash'", "'$verbose'" ] + "params": [ "'$txhash'", '$verbose' ] }' ``` @@ -78,17 +80,21 @@ bcoin-cli rpc getmempoolancestors $txhash $verbose ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getmempoolancestors', [ txhash, verbose ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getmempoolancestors', [ txhash, verbose ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -97,21 +103,42 @@ const rpc = new NodeClient({ // verbose=1 [ { - "size": 225, + "size": 226, "fee": 0.0000454, "modifiedfee": 0, - "time": 1502891340, - "height": 201, + "time": 1527103521, + "height": 100, "startingpriority": 0, "currentpriority": 0, "descendantcount": 1, "descendantsize": 451, "descendantfees": 9080, - "ancestorcount": 0, + "ancestorcount": 2, "ancestorsize": 0, "ancestorfees": 0, - "depends": [] - } + "depends": [ + "7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795" + ] + }, + { + "size": 225, + "fee": 0.0000454, + "modifiedfee": 0, + "time": 1527103519, + "height": 100, + "startingpriority": 0, + "currentpriority": 0, + "descendantcount": 2, + "descendantsize": 676, + "descendantfees": 13620, + "ancestorcount": 1, + "ancestorsize": 0, + "ancestorfees": 0, + "depends": [ + "d54e576d30f9014ffb06a31b9e36f2f5bb360e8c54980188ee4b09a979e092c2" + ] + }, + ... ] ``` @@ -139,17 +166,16 @@ let txhash, verbose; ``` ```shell--vars -txhash='56ab7663c80cb6ffc9f8a4b493d77b2e6f52ae8ff64eefa8899c2065922665c8'; +txhash='7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795'; verbose=1; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getmempooldescendants", - "params": [ "'$txhash'", "'$verbose'" ] + "params": [ "'$txhash'", '$verbose' ] }' ``` @@ -159,17 +185,21 @@ bcoin-cli rpc getmempooldescendants $txhash $verbose ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getmempooldescendants', [ txhash, verbose ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getmempooldescendants', [ txhash, verbose ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -181,21 +211,40 @@ const rpc = new NodeClient({ "size": 226, "fee": 0.0000454, "modifiedfee": 0, - "time": 1502891378, - "height": 201, + "time": 1527103521, + "height": 100, + "startingpriority": 0, + "currentpriority": 0, + "descendantcount": 1, + "descendantsize": 451, + "descendantfees": 9080, + "ancestorcount": 2, + "ancestorsize": 0, + "ancestorfees": 0, + "depends": [ + "7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795" + ] + }, + { + "size": 225, + "fee": 0.0000454, + "modifiedfee": 0, + "time": 1527103523, + "height": 100, "startingpriority": 0, "currentpriority": 0, "descendantcount": 0, - "descendantsize": 226, + "descendantsize": 225, "descendantfees": 4540, - "ancestorcount": 1, + "ancestorcount": 3, "ancestorsize": 0, "ancestorfees": 0, "depends": [ - "56ab7663c80cb6ffc9f8a4b493d77b2e6f52ae8ff64eefa8899c2065922665c8" + "e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea" ] } ] +[e ``` ```json @@ -222,12 +271,11 @@ let txhash; ``` ```shell--vars -txhash='939a3b8485b53a718d89e7e4412473b3762fa1d9bbd555fc8b01e73be0ab1881'; +txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getmempoolentry", @@ -241,38 +289,42 @@ bcoin-cli rpc getmempoolentry $txhash ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getmempoolentry', [ txhash ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getmempoolentry', [ txhash ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "size": 226, + "size": 225, "fee": 0.0000454, "modifiedfee": 0, - "time": 1502891378, - "height": 201, + "time": 1527103523, + "height": 100, "startingpriority": 0, "currentpriority": 0, "descendantcount": 0, - "descendantsize": 226, + "descendantsize": 225, "descendantfees": 4540, - "ancestorcount": 1, + "ancestorcount": 3, "ancestorsize": 0, "ancestorfees": 0, "depends": [ - "56ab7663c80cb6ffc9f8a4b493d77b2e6f52ae8ff64eefa8899c2065922665c8" + "e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea" ] } ``` @@ -297,12 +349,11 @@ verbose=1; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getrawmempool", - "params": [ "'$verbose'" ] + "params": [ '$verbose' ] }' ``` @@ -312,57 +363,62 @@ bcoin-cli rpc getrawmempool $verbose ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getrawmempool', [ verbose ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getrawmempool', [ verbose ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "56ab7663c80cb6ffc9f8a4b493d77b2e6f52ae8ff64eefa8899c2065922665c8": { + "d54e576d30f9014ffb06a31b9e36f2f5bb360e8c54980188ee4b09a979e092c2": { "size": 225, "fee": 0.0000454, "modifiedfee": 0, - "time": 1502891340, - "height": 201, - "startingpriority": 0, - "currentpriority": 0, - "descendantcount": 1, - "descendantsize": 451, - "descendantfees": 9080, + "time": 1527103516, + "height": 100, + "startingpriority": 2200000000, + "currentpriority": 2200000000, + "descendantcount": 3, + "descendantsize": 901, + "descendantfees": 18160, "ancestorcount": 0, "ancestorsize": 0, "ancestorfees": 0, "depends": [] }, - "939a3b8485b53a718d89e7e4412473b3762fa1d9bbd555fc8b01e73be0ab1881": { - "size": 226, + "7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795": { + "size": 225, "fee": 0.0000454, "modifiedfee": 0, - "time": 1502891378, - "height": 201, + "time": 1527103519, + "height": 100, "startingpriority": 0, "currentpriority": 0, - "descendantcount": 0, - "descendantsize": 226, - "descendantfees": 4540, + "descendantcount": 2, + "descendantsize": 676, + "descendantfees": 13620, "ancestorcount": 1, "ancestorsize": 0, "ancestorfees": 0, "depends": [ - "56ab7663c80cb6ffc9f8a4b493d77b2e6f52ae8ff64eefa8899c2065922665c8" + "d54e576d30f9014ffb06a31b9e36f2f5bb360e8c54980188ee4b09a979e092c2" ] - } + }, + ... } ``` @@ -383,18 +439,17 @@ let txhash, priorityDelta, feeDelta; ``` ```shell--vars -txhash=''; +txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; priorityDelta=1000; feeDelta=1000; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "prioritisetransaction", - "params": [ "'$txhash'", "'$priorityDelta'", "'$feeDelta'" ] + "params": [ "'$txhash'", '$priorityDelta', '$feeDelta' ] }' ``` @@ -404,17 +459,21 @@ bcoin-cli rpc prioritisetransaction $txhash $priorityDelta $feeDelta ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('prioritisetransaction', [ txhash, priorityDelta, feeDelta ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('prioritisetransaction', [ txhash, priorityDelta, feeDelta ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -431,7 +490,7 @@ into accepting Transaction(s) into the block. (even if Priority/Fee doen't quali N. | Name | Default | Description --------- | --------- | --------- | ----------- -1 | txid | Required | Transaction hash +1 | txhash | Required | Transaction hash 2 | priority delta | Required | Virtual priority to add/subtract to the entry 3 | fee delta | Required | Virtual fee to add/subtract to the entry @@ -448,12 +507,11 @@ nblocks=10; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "estimatefee", - "params": [ "'$nblocks'" ] + "params": [ '$nblocks' ] }' ``` @@ -463,17 +521,21 @@ bcoin-cli rpc estimatefee $nblocks ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('estimatefee', [ nblocks ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('estimatefee', [ nblocks ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -502,12 +564,11 @@ nblocks=10; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "estimatepriority", - "params": [ "'$nblocks'" ] + "params": [ '$nblocks' ] }' ``` @@ -517,17 +578,21 @@ bcoin-cli rpc estimatepriority $nblocks ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('estimatepriority', [ nblocks ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('estimatepriority', [ nblocks ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -556,12 +621,11 @@ nblocks=10; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "estimatesmartfee", - "params": [ "'$nblocks'" ] + "params": [ '$nblocks' ] }' ``` @@ -571,17 +635,21 @@ bcoin-cli rpc estimatesmartfee $nblocks ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('estimatesmartfee', [ nblocks ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('estimatesmartfee', [ nblocks ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -613,12 +681,11 @@ nblocks=10; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "estimatesmartpriority", - "params": [ "'$nblocks'" ] + "params": [ '$nblocks' ] }' ``` @@ -628,17 +695,21 @@ bcoin-cli rpc estimatesmartpriority $nblocks ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('estimatesmartpriority', [ nblocks ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('estimatesmartpriority', [ nblocks ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: diff --git a/api-docs-slate/source/includes/_node_rpc_mining.md b/api-docs-slate/source/includes/_node_rpc_mining.md index 2099a521..50b3542b 100644 --- a/api-docs-slate/source/includes/_node_rpc_mining.md +++ b/api-docs-slate/source/includes/_node_rpc_mining.md @@ -1,5 +1,7 @@ # RPC Calls - Mining +*Note: many mining-related RPC calls require `bcoin` to be started with the flag `--coinbase-address` designating a comma-separated list of payout addresses, randomly selected during block creation* + ## getnetworkhashps ```javascript @@ -12,12 +14,11 @@ height=1000000; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getnetworkhashps", - "params": [ "'$blocks'", "'$height'" ] + "params": [ '$blocks', '$height' ] }' ``` @@ -27,17 +28,21 @@ bcoin-cli rpc getnetworkhashps $blocks $height ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getnetworkhashps', [ blocks, height ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getnetworkhashps', [ blocks, height ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -59,8 +64,7 @@ N. | Name | Default | Description ## getmininginfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getmininginfo", @@ -74,34 +78,38 @@ bcoin-cli rpc getmininginfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getmininginfo', []); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getmininginfo', []); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "blocks": 1178789, - "currentblocksize": 11895, - "currentblockweight": 47580, - "currentblocktx": 35, - "difficulty": 1048576, + "blocks": 101, + "currentblocksize": 0, + "currentblockweight": 0, + "currentblocktx": 0, + "difficulty": 0, "errors": "", "genproclimit": 0, - "networkhashps": 10880012194348.812, - "pooledtx": 34, + "networkhashps": 8.766601909687916e-7, + "pooledtx": 0, "testnet": true, - "chain": "test", + "chain": "regtest", "generate": false } @@ -122,8 +130,7 @@ None. | ## getwork ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getwork", @@ -137,26 +144,29 @@ bcoin-cli rpc getwork ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getwork'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); +(async () => { + const result = await client.execute('getwork'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "data": "2000000082c18ff1d76f61dccbf37d5eca24d252c009af5f622ce08700000580000000009f447a03a1df9ae8f1ee24f0cf5ab69f1b321071f0e57344f2c61b922c12b8335994bdb51a0ffff000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000", - "target": "0000000000000000000000000000000000000000000000f0ff0f000000000000", - "height": 1178782 + "data": "200000001072adb70d69fc2b5a6601eeaaa54e31b7c57417028b429a0b98aa374413799c12c94351d52da980c8fa67eaddf6053dee141b14f4e6a3e10bb7db21c0d533b05b05ec88207fffff00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000", + "target": "0000000000000000000000000000000000000000000000000000000000ffff7f", + "height": 102 } ``` @@ -171,8 +181,10 @@ N. | Name | Default | Description ## getworklp ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +# Because there is a request timeout set on CLI http requests. +# without manually adjusting the timeout (or receiving a new transaction on the current +# network) this call will timeout before the request is complete. +curl $url \ -X POST \ --data '{ "method": "getworklp", @@ -181,35 +193,41 @@ curl $url/ \ ``` ```shell--cli -# Because there is a request timeout set on CLI http requests -# without manually adjusting the timeout, this call will timeout before the request is complete +# Because there is a request timeout set on CLI http requests. +# without manually adjusting the timeout (or receiving a new transaction on the current +# network) this call will timeout before the request is complete. bcoin-cli rpc getworklp ``` ```javascript -// Because there is a request timeout set on CLI http requests -// without manually adjusting the timeout, this call will timeout before the request is complete +// Because there is a request timeout set on CLI http requests. +// without manually adjusting the timeout (or receiving a new transaction on the current +// network) this call will timeout before the request is complete. const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getworklp'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getworklp'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "data": "2000000082c18ff1d76f61dccbf37d5eca24d252c009af5f622ce08700000580000000009f447a03a1df9ae8f1ee24f0cf5ab69f1b321071f0e57344f2c61b922c12b8335994bdb51a0ffff000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000", - "target": "0000000000000000000000000000000000000000000000f0ff0f000000000000", - "height": 1178782 + "data": "200000001072adb70d69fc2b5a6601eeaaa54e31b7c57417028b429a0b98aa374413799c09e651f7a930c198755993bf7348fd807836d1560b6baded56857def309a03855b05ecf1207fffff00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000", + "target": "0000000000000000000000000000000000000000000000000000000000ffff7f", + "height": 102 } ``` @@ -228,8 +246,7 @@ None. | ## getblocktemplate ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getblocktemplate", @@ -243,17 +260,21 @@ bcoin-cli rpc getblocktemplate ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getblocktemplate'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getblocktemplate'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -269,42 +290,54 @@ const rpc = new NodeClient({ "prevblock" ], "version": 536870912, - "rules": [ - "csv", - "!segwit" - ], + "rules": [], "vbavailable": {}, "vbrequired": 0, - "height": 1178933, - "previousblockhash": "0000000000000e19ff0c98e7d99987071a791c47338f71389342f7457eeb8695", - "target": "0000000000000ffff00000000000000000000000000000000000000000000000", - "bits": "1a0ffff0", + "height": 102, + "previousblockhash": "4413799c0b98aa37028b429ab7c57417aaa54e315a6601ee0d69fc2b1072adb7", + "target": "7fffff0000000000000000000000000000000000000000000000000000000000", + "bits": "207fffff", "noncerange": "00000000ffffffff", - "curtime": 1502974969, - "mintime": 1502974260, - "maxtime": 1502982169, - "expires": 1502982169, - "sigoplimit": 80000, - "sizelimit": 4000000, - "weightlimit": 4000000, - "longpollid": "0000000000000e19ff0c98e7d99987071a791c47338f71389342f7457eeb86950000000018", + "curtime": 1527115118, + "mintime": 1527103506, + "maxtime": 1527122318, + "expires": 1527122318, + "sigoplimit": 20000, + "sizelimit": 1000000, + "longpollid": "4413799c0b98aa37028b429ab7c57417aaa54e315a6601ee0d69fc2b1072adb700000003", "submitold": false, "coinbaseaux": { - "flags": "62636f696e206d6163626f6f6b" + "flags": "6d696e65642062792062636f696e" }, - "coinbasevalue": 156465644, - "default_witness_commitment": "6a24aa21a9edc9f8a77e851392ce58c6b5c64fafbebd76e92c03a198d1e2c942d71fe05c7bc4", + "coinbasevalue": 5000016600, "transactions": [ { - "data": "010000000194a1dd786bc486412dd4125c90eeac0550131b7ffee190d3c8bce92007dfe682000000006b483045022100e2ee65fcdb3c005e430c279e759764937e70993c3a97c21b8580b16146766cdc022044cbb4a09ce4ed4f9c6be14befb6fbccd7819814073f33220e076ced7b103fca01210396e891cf6f1e71e1a266abd3c1e990331da6dc2d3b41e53c6e991f66262f2f32ffffffff022aee0500000000001976a914a21138d3322b67910f66f676396ea432faee34cb88aca0860100000000001976a91494178f0b288078717873b4228e2aad27b91a492188ac00000000", - "txid": "809c3d8fb6524acc4ffcaeb2a97ccb1c4c1124ccc5034745ba6ac43f8d4d63c9", - "hash": "809c3d8fb6524acc4ffcaeb2a97ccb1c4c1124ccc5034745ba6ac43f8d4d63c9", + "data": "01000000017efbcc72a5733c7b9bcb1b763a81480425425bc10a4157e9553f0fd32eda710b000000006a47304402206a04f6c4fa9be51206e3fb9a48c5960198d7b27ce1b7c1915a4535e63ffdc60b022050796a1e0c09f60384379c2a477bedbce548cbaaa0e42183b737115b4ea77c5d0121020987e993a946a058d0969bd296b08783229fd1a0a779d8bfb376ebe30a164e89ffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac4486a327010000001976a914b1a4d7b11dad88f767d0ad894e11b53d766400a888ac00000000", + "txid": "7444ea74eaee01ed7c7871f355bb5cb244a4ef2c05ae16ad49b4b06cbf34f539", + "hash": "7444ea74eaee01ed7c7871f355bb5cb244a4ef2c05ae16ad49b4b06cbf34f539", "depends": [], - "fee": 11350, - "sigops": 8, - "weight": 904 + "fee": 4540, + "sigops": 2, + "weight": 900 }, - ... + { + "data": "0100000002e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e000000006b483045022100eeae86adccb31514ca25d3ddf265b21de05230fd6c93db7fbd185c133647fe640220392c3b5ebd50f4f0538c686b88e1d7051a81c2e5dff8c96f2a5c61154fa3c43a0121032cbf9d9b3beb61004d158ae897257fab6ce46efbad6b1e51b4a64e74732c3b4dffffffffeaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6000000006a47304402203e3ca4312bee4c465e6d5fcaee7aae1301d043444fe7a8f20b7df9f555ca1b4f022060104fc66cdb68af8cc674e94bb1900328cda94a8f6580d12ef0ad9810f24a290121032cbf9d9b3beb61004d158ae897257fab6ce46efbad6b1e51b4a64e74732c3b4dffffffff0220a6c901000000001976a914253d160f8a14c9586c9204553b50b279c71d2c8888ac005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac00000000", + "txid": "c0f7dc9540629f6e1623cb25edba1d07cab4dd441b71cd247e629a6d817ed1ad", + "hash": "c0f7dc9540629f6e1623cb25edba1d07cab4dd441b71cd247e629a6d817ed1ad", + "depends": [], + "fee": 7520, + "sigops": 2, + "weight": 1492 + }, + { + "data": "0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e010000006b483045022100977567f80741451fe1407fbe453e75d371cc38a0de1411efc7df5c8c3c35d8ec02207a5899976628c19a22dae0058f60f86f43b379991bbf93383b17932310e497b001210284a937f256393b3ba686556e90bd000706600bdbee4169abd092f392689307d2ffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac545ead21010000001976a914520b23898b775a4a5dc19d07a88ca4a4a87b92bf88ac00000000", + "txid": "fa36691ec5f18a9dc56b1dfce3dff293352ebde8bc1b77489cba4921bc5b0c69", + "hash": "fa36691ec5f18a9dc56b1dfce3dff293352ebde8bc1b77489cba4921bc5b0c69", + "depends": [], + "fee": 4540, + "sigops": 2, + "weight": 904 + } ] } ``` @@ -331,13 +364,11 @@ let blockdata; ``` ```shell--vars -blockdata='0100000082d6e6bf4ed6c5b989705920effd072fe6b7119ea5b8c8fa6d0bf5c70000000071959f90386cdc263655d36033817a6f69cbc2d99fc56cc81f893b9787907a4fcfc94a4dffff001d000f90930901000000010000000000000000000000000000000000000000000000000000000000000000ffffffff163337346bde777ade327922b5deef5fb7f88e98cecb22ffffffff01800c0c2a0100000023210207a8b8758b4886d85b7f94fbd9cacb3452c5e643dc3188a1dbea8d1a1dd4bbc3ac0000000001000000017c9665a50c9bcc8c359c58ffd511d8cfe122b440cdb6ad864a43f1644eb31fe6000000006b48304502201569b4872c3639811ab467ec559416c1006d257a5d6fea103a41a408dd8a5682022100c1a3c90cbd148a4ca69189c88d059e2af8268807982d89b76725d38f65494f5201210394afa526e43a0e03f5aaa2a55312f6c25a9b5fedd66e7f4e4847af79d517c5f5ffffffff02bc80b01f010000001976a91451513561deaa318f4a3ad2bfccc889225499194388ac359a0300000000001976a914bc0f9f5fc9dc55323d52a9e354b5fb67cecd389788ac0000000001000000035f836b328d40944483c39c90cb4dfd3d9b83f96d71586b3230118629fb7893f7000000006a473044022076232b5d3b8372da7e0a5b58614676b6ad77debf0ed75a5996f9b91642326059022037e2ee19b56916465e9c76e7e1d558a64738e7444649144bf7e19143423aee1401210281392a2cd37ac1108b8bc0f647784f66017fd837379e6fc2109f1793f5dccfdbffffffff58bd81fd34d42c015ac22537440c49450453e8284b717667c418ed7dc3693579000000006b48304502200352ee3028c8c4ff14574e71837a2e68b1c285dd57b993e19d9b24728161409f022100d7cd062e64e57200bf1ffa0fbd41726a67cfe547849b0fcfe72556fb42596d630121039bd575a5913e93d227afa8e65c5c37954688e53e069980e4790aba8652d9d557ffffffff8a64fa7fb31eff45e2145ba1d09a4ac627e259d14a3b9154c510d44c9954f3c1000000006a473044022044e97e0e287472385c60c68f4e16a73e3e6d7fcb1bc3700fa7c36c4fb653e1cb022034c624487aedb8bc3c86b02d0338b10922fa1c6c8fd8c39eaf64564d62289fe101210370410acad1e5601c9e8e8968ccf648daab3902744091c19b29a17c8e2cf92132ffffffff0268911d00000000001976a91480cac4151b3a9ceffaee95018f0ca3d202a71b2c88ac334f1000000000001976a914cd4529e867a0b96d43e358998387b06fc3e06e8c88ac0000000001000000015f836b328d40944483c39c90cb4dfd3d9b83f96d71586b3230118629fb7893f701000000fd3301347b3d4a6f10829e9c617770a52f2334a434677a08ac775c968b3097b1353d1e1a10b53099a2003c7cb03a5152690e687e191a990048304502201613b0ce320ccc1d206a03f67fecf6d1b31fdd23e51923a821fda745c23cd4db022100854bdd81256edfac75ac7dc9d0b073118b5879f50b26021eeffa4d126f39cf7301493046022100bce73cabbb1d4bca0ee33b241bc526cbb6c17f219057a58993738d614c898e0f022100b9aa31160b3bc6e2bf2e33240ea8543a9f54551b78c7cb268e72a3cee45cc5a3014c69522102ca2a810ab17249b6033a038de563983881b4069270183f3c0aba945653e442162103f480f1b648d0d5167804ad4d586e0e757cc33fde0e133fd036e45d60d2db59e12103c18131d8de99d45fb72a774cab0ccc258cd2abd9605610da20b9a232c88a3cb653aeffffffff025e310100000000001976a91445c502d496058c41721e06c6ebd5a8580dd66d8488ac78940100000000001976a914bc0f9f5fc9dc55323d52a9e354b5fb67cecd389788ac000000000100000001e667afd60a5c5e3190ac4d4ec2ca3a2ac96ae5ec4fdb161ecf8db06bf22e1fc6000000006b483045022100a0cc8f57d5a171aa4a5d3c963640039e11c5dac38820eb90c284eb360326041d02202917e30b20178f9c4464d44f956aa8105b83b24f4a0f011ca380b35f31c6bcf20121029e6f1aaf22a7114a000627eba8b2990c86136e7fab46dffccf1a33a505d039f6ffffffff024c79a81f010000001976a914a196eec6c686089ffcc8a9d4077643ede546535088ac204407000000000017a914184cd0a38ac3b1357d07179553788375a9e8a3b887000000000100000001c054bdbfe97e3997a0858d4578f69e50b018cd2cd966c9339c10030a9e43cc90000000006a47304402201feccc650991032dc98ed330aaa68840feac3e0ae568d674ebc480d8f810eedf02205b06d5dce842cb5f684fb6816d61425d5533cc73b05cbdf2a1552699da98f97d01210391af1358729c7ea974cf76e43a125158687550610108791a1563be587e48bf9affffffff02a194a41f010000001976a914bdfa420798058a37dd0c37ba1d38f103a793649c88ac5b210300000000001976a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac0000000001000000019cf0d401fba9272613dc9e06d64cd1ccb7596acb37b46f10f811d76f46f7671d000000006b48304502202599390550a38555ae661be940716ac669c7493e34216a71ca86d069636d6e3a022100ae406057ec3f60f9e3410360facf1bd1f59b1e4cc27a2b4ba67e325658319b390121032165eff60895ce9b519aa327adc44e4867b3aa5998d8bdb0e277da3fa67873a3ffffffff024e55991f010000001976a9149c5c9a7c09d843b451eaa0c7cbf866623405babf88ac037c0a000000000017a914a4b7adff15fec83376d5e4468afeed627abe1ed88700000000010000000180b35d06ed071cf7ad57b1f87f5ae21c29f47b9740f998414d79cdb4f5502440000000006c4930460221009014b9cb28077036096492e8c0a46bd8aa6d43758fc211817d22e0401db5a0300221008c23434e440108b2d0dce98a0647bab603e8e876467ecb339201473054ff80650121023cf5ef93ca567172647fad0e3b1cb0456cbfad88e4f65e286471ed93fba66a10ffffffff024a2e8c1f010000001976a914bc7aad9746a0bc03ed9715f13c94e554df90b84688acb4630c00000000001976a914bc0f9f5fc9dc55323d52a9e354b5fb67cecd389788ac000000000100000001c702cde8b6a003a898cb437177a2c6af0da0f13f04fce6d52731394dd2a57301000000006c493046022100be75ae6dbf9eab7656562136511501c83918ca28c5f96565ca1960b3dbb581b6022100d15692af456e8721fddeeb0d6df5d8a147afd8a3b2a39bbceae9b1bdfd53ade20121038e297cf2cf71c16592c36ca48f5b2a5bbb73e776e772079f4c695b12eec1a509ffffffff023b37871f010000001976a914682215dfa6912d88f55a1853414d516122fcc66988acbf330400000000001976a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac00000000'; +blockdata='000000203f6397a1442eb6a9901998c4a4b432f8573c7a490b2d5e6d6f2ad0d0fca25e2c56940d79c8f81f3eb5e998bcf79dbf8c7d3b13b01adaac526cf9df8ee385ec0c1ac0055bffff7f20000000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f01640e6d696e65642062792062636f696e046c62c046080000000000000000ffffffff0100f2052a010000001976a91473815900ee35f3815b3407af2eeb1b611cf533d788ac00000000'; ``` ```shell--curl -# Block data is old, so it should return error -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "submitblock", @@ -346,28 +377,31 @@ curl $url/ \ ``` ```shell--cli -# Block data is old, so it should return error bcoin-cli rpc submitblock $blockdata ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - // Block data is old, so it should return error - const res = await rpc.execute('submitblock', [ blockdata ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('submitblock', [ blockdata ]); + console.log(result); +})(); ``` Adds block to chain. + ### Params N. | Name | Default | Description --------- | --------- | --------- | ----------- @@ -380,13 +414,11 @@ let blockdata; ``` ```shell--vars -blockdata='0100000082d6e6bf4ed6c5b989705920effd072fe6b7119ea5b8c8fa6d0bf5c70000000071959f90386cdc263655d36033817a6f69cbc2d99fc56cc81f893b9787907a4fcfc94a4dffff001d000f90930901000000010000000000000000000000000000000000000000000000000000000000000000ffffffff163337346bde777ade327922b5deef5fb7f88e98cecb22ffffffff01800c0c2a0100000023210207a8b8758b4886d85b7f94fbd9cacb3452c5e643dc3188a1dbea8d1a1dd4bbc3ac0000000001000000017c9665a50c9bcc8c359c58ffd511d8cfe122b440cdb6ad864a43f1644eb31fe6000000006b48304502201569b4872c3639811ab467ec559416c1006d257a5d6fea103a41a408dd8a5682022100c1a3c90cbd148a4ca69189c88d059e2af8268807982d89b76725d38f65494f5201210394afa526e43a0e03f5aaa2a55312f6c25a9b5fedd66e7f4e4847af79d517c5f5ffffffff02bc80b01f010000001976a91451513561deaa318f4a3ad2bfccc889225499194388ac359a0300000000001976a914bc0f9f5fc9dc55323d52a9e354b5fb67cecd389788ac0000000001000000035f836b328d40944483c39c90cb4dfd3d9b83f96d71586b3230118629fb7893f7000000006a473044022076232b5d3b8372da7e0a5b58614676b6ad77debf0ed75a5996f9b91642326059022037e2ee19b56916465e9c76e7e1d558a64738e7444649144bf7e19143423aee1401210281392a2cd37ac1108b8bc0f647784f66017fd837379e6fc2109f1793f5dccfdbffffffff58bd81fd34d42c015ac22537440c49450453e8284b717667c418ed7dc3693579000000006b48304502200352ee3028c8c4ff14574e71837a2e68b1c285dd57b993e19d9b24728161409f022100d7cd062e64e57200bf1ffa0fbd41726a67cfe547849b0fcfe72556fb42596d630121039bd575a5913e93d227afa8e65c5c37954688e53e069980e4790aba8652d9d557ffffffff8a64fa7fb31eff45e2145ba1d09a4ac627e259d14a3b9154c510d44c9954f3c1000000006a473044022044e97e0e287472385c60c68f4e16a73e3e6d7fcb1bc3700fa7c36c4fb653e1cb022034c624487aedb8bc3c86b02d0338b10922fa1c6c8fd8c39eaf64564d62289fe101210370410acad1e5601c9e8e8968ccf648daab3902744091c19b29a17c8e2cf92132ffffffff0268911d00000000001976a91480cac4151b3a9ceffaee95018f0ca3d202a71b2c88ac334f1000000000001976a914cd4529e867a0b96d43e358998387b06fc3e06e8c88ac0000000001000000015f836b328d40944483c39c90cb4dfd3d9b83f96d71586b3230118629fb7893f701000000fd3301347b3d4a6f10829e9c617770a52f2334a434677a08ac775c968b3097b1353d1e1a10b53099a2003c7cb03a5152690e687e191a990048304502201613b0ce320ccc1d206a03f67fecf6d1b31fdd23e51923a821fda745c23cd4db022100854bdd81256edfac75ac7dc9d0b073118b5879f50b26021eeffa4d126f39cf7301493046022100bce73cabbb1d4bca0ee33b241bc526cbb6c17f219057a58993738d614c898e0f022100b9aa31160b3bc6e2bf2e33240ea8543a9f54551b78c7cb268e72a3cee45cc5a3014c69522102ca2a810ab17249b6033a038de563983881b4069270183f3c0aba945653e442162103f480f1b648d0d5167804ad4d586e0e757cc33fde0e133fd036e45d60d2db59e12103c18131d8de99d45fb72a774cab0ccc258cd2abd9605610da20b9a232c88a3cb653aeffffffff025e310100000000001976a91445c502d496058c41721e06c6ebd5a8580dd66d8488ac78940100000000001976a914bc0f9f5fc9dc55323d52a9e354b5fb67cecd389788ac000000000100000001e667afd60a5c5e3190ac4d4ec2ca3a2ac96ae5ec4fdb161ecf8db06bf22e1fc6000000006b483045022100a0cc8f57d5a171aa4a5d3c963640039e11c5dac38820eb90c284eb360326041d02202917e30b20178f9c4464d44f956aa8105b83b24f4a0f011ca380b35f31c6bcf20121029e6f1aaf22a7114a000627eba8b2990c86136e7fab46dffccf1a33a505d039f6ffffffff024c79a81f010000001976a914a196eec6c686089ffcc8a9d4077643ede546535088ac204407000000000017a914184cd0a38ac3b1357d07179553788375a9e8a3b887000000000100000001c054bdbfe97e3997a0858d4578f69e50b018cd2cd966c9339c10030a9e43cc90000000006a47304402201feccc650991032dc98ed330aaa68840feac3e0ae568d674ebc480d8f810eedf02205b06d5dce842cb5f684fb6816d61425d5533cc73b05cbdf2a1552699da98f97d01210391af1358729c7ea974cf76e43a125158687550610108791a1563be587e48bf9affffffff02a194a41f010000001976a914bdfa420798058a37dd0c37ba1d38f103a793649c88ac5b210300000000001976a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac0000000001000000019cf0d401fba9272613dc9e06d64cd1ccb7596acb37b46f10f811d76f46f7671d000000006b48304502202599390550a38555ae661be940716ac669c7493e34216a71ca86d069636d6e3a022100ae406057ec3f60f9e3410360facf1bd1f59b1e4cc27a2b4ba67e325658319b390121032165eff60895ce9b519aa327adc44e4867b3aa5998d8bdb0e277da3fa67873a3ffffffff024e55991f010000001976a9149c5c9a7c09d843b451eaa0c7cbf866623405babf88ac037c0a000000000017a914a4b7adff15fec83376d5e4468afeed627abe1ed88700000000010000000180b35d06ed071cf7ad57b1f87f5ae21c29f47b9740f998414d79cdb4f5502440000000006c4930460221009014b9cb28077036096492e8c0a46bd8aa6d43758fc211817d22e0401db5a0300221008c23434e440108b2d0dce98a0647bab603e8e876467ecb339201473054ff80650121023cf5ef93ca567172647fad0e3b1cb0456cbfad88e4f65e286471ed93fba66a10ffffffff024a2e8c1f010000001976a914bc7aad9746a0bc03ed9715f13c94e554df90b84688acb4630c00000000001976a914bc0f9f5fc9dc55323d52a9e354b5fb67cecd389788ac000000000100000001c702cde8b6a003a898cb437177a2c6af0da0f13f04fce6d52731394dd2a57301000000006c493046022100be75ae6dbf9eab7656562136511501c83918ca28c5f96565ca1960b3dbb581b6022100d15692af456e8721fddeeb0d6df5d8a147afd8a3b2a39bbceae9b1bdfd53ade20121038e297cf2cf71c16592c36ca48f5b2a5bbb73e776e772079f4c695b12eec1a509ffffffff023b37871f010000001976a914682215dfa6912d88f55a1853414d516122fcc66988acbf330400000000001976a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac00000000'; +blockdata='000000203f6397a1442eb6a9901998c4a4b432f8573c7a490b2d5e6d6f2ad0d0fca25e2c56940d79c8f81f3eb5e998bcf79dbf8c7d3b13b01adaac526cf9df8ee385ec0c1ac0055bffff7f20000000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f01640e6d696e65642062792062636f696e046c62c046080000000000000000ffffffff0100f2052a010000001976a91473815900ee35f3815b3407af2eeb1b611cf533d788ac00000000'; ``` ```shell--curl -# Block data is old, so it should return error -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "verifyblock", @@ -395,24 +427,27 @@ curl $url/ \ ``` ```shell--cli -# Block data is old, so it should return error bcoin-cli rpc verifyblock $blockdata ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); (async () => { // Block data is old, so it should return error - const res = await rpc.execute('verifyblock', [ blockdata ]); - - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); + const result = await client.execute('verifyblock', [ blockdata ]); + console.log(result); +})(); ``` Verifies the block data. @@ -438,12 +473,11 @@ proclimit=1; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "setgenerate", - "params": [ "'$mining'", "'$proclimit'" ] + "params": [ '$mining', '$proclimit' ] }' ``` @@ -453,17 +487,21 @@ bcoin-cli rpc setgenerate $mining $proclimit ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('setgenerate', [ mining, proclimit ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('setgenerate', [ mining, proclimit ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -485,8 +523,7 @@ N. | Name | Default | Description ## getgenerate ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getgenerate", @@ -500,17 +537,21 @@ bcoin-cli rpc getgenerate ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getgenerate'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getgenerate'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -539,47 +580,50 @@ numblocks=2; ``` ```shell--curl -# Will return once all blocks are mined. -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "generate", - "params": [ "'$numblocks'" ] + "params": [ '$numblocks' ] }' ``` ```shell--cli -# Timeout error bcoin-cli rpc generate $numblocks ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); (async () => { // Timeout error - const res = await rpc.execute('generate', [ numblocks ]); - - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); + const result = await client.execute('generate', [ numblocks ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json [ - "0aac2269ce67d5bda3743b1a179a7824f17b3b6df011befd7bd224cb958bd4ec", - "0871f1a42279397b7508c75e142b903a945a19af08c6de6970e266255d10f08f" + "11c5504f63aebe71b3e6f46a31f83dd24e65e392a11e905f6acdb7346c8b18c0", + "64455db5aa23d6277027aea1851d85da8ee07958ed7caee2ca630b065f4faaa8" ] ``` -Mines `numblocks` number of blocks. +Mines `numblocks` number of blocks. Will return once all blocks are mined. CLI command may +timeout before that happens. + ### Params N. | Name | Default | Description @@ -602,12 +646,11 @@ address='RTZJdYScA7uGb5pbQPEczpDmq9HiYLv2fJ'; ```shell--curl # Will return once all blocks are mined. -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "generatetoaddress", - "params": [ "'$numblocks'", "'$address'" ] + "params": [ '$numblocks', "'$address'" ] }' ``` @@ -618,26 +661,30 @@ bcoin-cli rpc generatetoaddress $numblocks $address ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); (async () => { // Timeout error - const res = await rpc.execute('generatetoaddress', [ numblocks, address ]); - - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); + const result = await client.execute('generatetoaddress', [ numblocks, address ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json [ - "0aac2269ce67d5bda3743b1a179a7824f17b3b6df011befd7bd224cb958bd4ec", - "0871f1a42279397b7508c75e142b903a945a19af08c6de6970e266255d10f08f" + "65e54939c20f61e54173596eb72a7b00b96baac0c58d2cb30d1fad64d1b51dbb", + "3959ee3f58bb1ac05af9bebb51ebf7872bcd4231fa41c384bcfef468541b5166" ] ``` Mines `blocknumber` blocks, with `address` as coinbase. diff --git a/api-docs-slate/source/includes/_node_rpc_network.md b/api-docs-slate/source/includes/_node_rpc_network.md index dae921f4..d9861a1c 100644 --- a/api-docs-slate/source/includes/_node_rpc_network.md +++ b/api-docs-slate/source/includes/_node_rpc_network.md @@ -3,8 +3,7 @@ ## getconnectioncount ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getconnectioncount", @@ -18,17 +17,21 @@ bcoin-cli rpc getconnectioncount ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getconnectioncount'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getconnectioncount'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -47,8 +50,7 @@ None. | ## ping ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "ping", @@ -62,17 +64,21 @@ bcoin-cli rpc ping ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('ping'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('ping'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -93,8 +99,7 @@ None. | ## getpeerinfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getpeerinfo", @@ -108,17 +113,21 @@ bcoin-cli rpc getpeerinfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getpeerinfo'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getpeerinfo'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -126,25 +135,26 @@ const rpc = new NodeClient({ ```json [ { - "id": 1, - "addr": "198.51.100.82:18333", - "addrlocal": "203.0.113.114:60760", - "services": "0000000d", + "id": 65, + "addr": "127.0.0.1:48444", + "addrlocal": "127.0.0.1:42930", + "name": "localhost", + "services": "00000009", "relaytxes": true, - "lastsend": 1503257171, - "lastrecv": 1503257171, - "bytessent": 1962, - "bytesrecv": 32499, - "conntime": 121, - "timeoffset": -1, - "pingtime": 0.143, - "minping": 0.143, + "lastsend": 1527116003, + "lastrecv": 1527116003, + "bytessent": 20734, + "bytesrecv": 19905, + "conntime": 348, + "timeoffset": 0, + "pingtime": 0.001, + "minping": 0, "version": 70015, - "subver": "/Satoshi:0.14.1/", + "subver": "/bcoin:v1.0.0-pre/", "inbound": false, - "startingheight": 1179570, - "besthash": null, - "bestheight": -1, + "startingheight": 5456, + "besthash": "43bc66d363025c8953d0920d0bdd5d78e88905687dc0321053ce8f4c6ca0319d", + "bestheight": 5470, "banscore": 0, "inflight": [], "whitelisted": false @@ -170,14 +180,13 @@ let nodeAddr, cmd; ``` ```shell--vars -nodeAddr='198.51.100.82:18333'; +nodeAddr='127.0.0.1:48444'; cmd='add' ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "addnode", @@ -191,17 +200,21 @@ bcoin-cli rpc addnode $nodeAddr $cmd ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('addnode', [ nodeAddr, cmd ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('addnode', [ nodeAddr, cmd ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -210,7 +223,7 @@ const rpc = new NodeClient({ null ``` -Adds or removes peers in Host List. +Adds or removes peers in Host List. ### Params N. | Name | Default | Description @@ -234,13 +247,12 @@ let nodeAddr; ``` ```shell--vars -nodeAddr='198.51.100.82:18333'; +nodeAddr='127.0.0.1:48444'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "disconnectnode", @@ -254,17 +266,21 @@ bcoin-cli rpc disconnectnode $nodeAddr ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('disconnectnode', [ nodeAddr ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('disconnectnode', [ nodeAddr ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -289,12 +305,11 @@ let nodeAddr; ``` ```shell--vars -nodeAddr='198.51.100.82:18333'; +nodeAddr='127.0.0.1:48444'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getaddednodeinfo", @@ -308,17 +323,21 @@ bcoin-cli rpc getaddednodeinfo $nodeAddr ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getaddednodeinfo', [ nodeAddr ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getaddednodeinfo', [ nodeAddr ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -326,11 +345,11 @@ const rpc = new NodeClient({ ```json [ { - "addednode": "198.51.100.82:18333", + "addednode": "127.0.0.1:48444", "connected": true, "addresses": [ { - "address": "198.51.100.82:18333", + "address": "127.0.0.1:48444", "connected": "outbound" } ] @@ -350,8 +369,7 @@ N. | Name | Default | Description ## getnettotals ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getnettotals", @@ -365,26 +383,30 @@ bcoin-cli rpc getnettotals ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getnettotals'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('getnettotals'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "totalbytesrecv": 370598, - "totalbytessent": 110058, - "timemillis": 1503262547279 + "totalbytesrecv": 42175, + "totalbytessent": 42175, + "timemillis": 1527116369308 } ``` @@ -400,8 +422,7 @@ None. | ## getnetworkinfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getnetworkinfo", @@ -415,17 +436,21 @@ bcoin-cli rpc getnetworkinfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getnetworkinfo'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getnetworkinfo'); + console.log(result); +})(); ``` @@ -433,21 +458,21 @@ const rpc = new NodeClient({ ```json { - "version": "v1.0.0-beta.14", - "subversion": "/bcoin:v1.0.0-beta.14/", + "version": "v1.0.0-pre", + "subversion": "/bcoin:v1.0.0-pre/", "protocolversion": 70015, "localservices": "00000009", "localrelay": true, - "timeoffset": -1, + "timeoffset": 0, "networkactive": true, - "connections": 8, + "connections": 2, "networks": [], "relayfee": 0.00001, "incrementalfee": 0, "localaddresses": [ { - "address": "203.0.113.114", - "port": 18333, + "address": "18.188.224.12", + "port": 48444, "score": 3 } ], @@ -471,13 +496,12 @@ let nodeAddr, cmd; ``` ```shell--vars -nodeAddr='198.51.100.82:18333'; +nodeAddr='127.0.0.1:48444'; cmd='add' ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "setban", @@ -491,17 +515,21 @@ bcoin-cli rpc setban $nodeAddr $cmd ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('setban', [ nodeAddr, cmd ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('setban', [ nodeAddr, cmd ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -529,8 +557,7 @@ remove | Removes node from ban list ## listbanned ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "listbanned", @@ -544,17 +571,21 @@ bcoin-cli rpc listbanned ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('listbanned'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('listbanned'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: @@ -562,12 +593,11 @@ const rpc = new NodeClient({ ```json [ { - "address": "198.51.100.82:18333", - "banned_until": 1503349501, - "ban_created": 1503263101, + "address": "127.0.0.1", + "banned_until": 1527202858, + "ban_created": 1527116458, "ban_reason": "" - }, - ... + } ] ``` @@ -583,8 +613,7 @@ None. | ## clearbanned ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "clearbanned", @@ -598,17 +627,21 @@ bcoin-cli rpc clearbanned ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('clearbanned'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('clearbanned'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: diff --git a/api-docs-slate/source/includes/_node_rpc_tx.md b/api-docs-slate/source/includes/_node_rpc_tx.md index 3747d1a0..6b498f3b 100644 --- a/api-docs-slate/source/includes/_node_rpc_tx.md +++ b/api-docs-slate/source/includes/_node_rpc_tx.md @@ -7,18 +7,17 @@ let txhash, index, includemempool; ``` ```shell--vars -txhash='28d65fdaf5334ffd29066d7076f056bb112baa4bb0842f6eaa06171c277b4e8c'; +txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; index=0; includemempool=1; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "gettxout", - "params": [ "'$txhash'", "'$index'", "'$includemempool'" ] + "params": [ "'$txhash'", '$index', '$includemempool' ] }' ``` @@ -28,33 +27,37 @@ bcoin-cli rpc gettxout $txhash $index $includemempool ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('gettxout', [ txhash, index, includemempool ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('gettxout', [ txhash, index, includemempool ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "bestblock": "00000000000004f0fbf1b2290e8255bbd468640d747fd9d44a16e77d9e129a55", - "confirmations": 1, - "value": 1.01, + "bestblock": "0e11d85b2081b84e131ba6692371737e6bb2aa7bc6d16e92954ffb1f9ad762e5", + "confirmations": 0, + "value": 0.4, "scriptPubKey": { - "asm": "OP_HASH160 6a58967510cfd7e04987b245f73dbf62e8d3fdf8 OP_EQUAL", - "hex": "a9146a58967510cfd7e04987b245f73dbf62e8d3fdf887", - "type": "SCRIPTHASH", + "asm": "OP_DUP OP_HASH160 fe7e0711287688b33b9a5c239336c4700db34e63 OP_EQUALVERIFY OP_CHECKSIG", + "hex": "76a914fe7e0711287688b33b9a5c239336c4700db34e6388ac", + "type": "PUBKEYHASH", "reqSigs": 1, "addresses": [ - "2N2wXjoQbEQTKQuqYdkpHMp7rPpnpumYYqe" + "RYUpgnvLvfi5T7q3hGSVvFrUy14kt61FC1" ] }, "version": 1, @@ -76,8 +79,7 @@ N. | Name | Default | Description ## gettxoutsetinfo ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "gettxoutsetinfo", @@ -91,30 +93,34 @@ bcoin-cli rpc gettxoutsetinfo ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('gettxoutsetinfo'); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('gettxoutsetinfo'); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "height": 1178729, - "bestblock": "00000000000004f0fbf1b2290e8255bbd468640d747fd9d44a16e77d9e129a55", - "transactions": 14827318, - "txouts": 17644185, + "height": 100, + "bestblock": "0e11d85b2081b84e131ba6692371737e6bb2aa7bc6d16e92954ffb1f9ad762e5", + "transactions": 101, + "txouts": 100, "bytes_serialized": 0, "hash_serialized": 0, - "total_amount": 20544080.67292757 + "total_amount": 5000 } ``` @@ -130,20 +136,20 @@ None. | ## getrawtransaction ```javascript -let txhash, verbose=0; +let txhash, verbose; ``` ```shell--vars -txhash='28d65fdaf5334ffd29066d7076f056bb112baa4bb0842f6eaa06171c277b4e8c'; +txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; +verbose=0; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "getrawtransaction", - "params": [ "'$txhash'", "'$verbose'" ] + "params": [ "'$txhash'", '$verbose' ] }' ``` @@ -153,23 +159,27 @@ bcoin-cli rpc getrawtransaction $txhash $verbose ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('getrawtransaction', [ txhash, verbose ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('getrawtransaction', [ txhash, verbose ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -"0100000002500310ff36beb6c3608230534ef995f7751b6f948aeea8d21d5cc9dd5023a2c4010000006b483045022100e7c71d397b687f9f30e6003ceedc4c50436fdb2329b7a8a36c9c6759077969d30220059f24e917260d3e601c77079d03c9e73d04fd85f625eaebfd14a1ff695a72230121020bc134c91f4ff068f3a970616fad577f949406c18849321a2f6d4df96fc56c77feffffffeffed95ded4f227fc6717f224e85e50348ce0198303a5418f157ade42828a1e3000000006b483045022100f0bde463404db0983e0f221bfa1b13edf1063a78e869295c9457864b122a622b02207d9d5df76ecac6289784201e9a918acb34510c2d65144bf8e4753a3413024e320121022565ed0ff8f79ecf11e8f33b9fbba5606dbc0618813acd74603f9466e88fb8a8feffffff02402305060000000017a9146a58967510cfd7e04987b245f73dbf62e8d3fdf8871e194f00000000001976a914132b05f47f2b1b56f26a78d3962e3acd0735f12d88ac00000000" +"0100000001eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6010000006a4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057abffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac10ca0f24010000001976a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac00000000" ``` Returns raw transaction @@ -189,12 +199,11 @@ let rawtx; ``` ```shell--vars -rawtx='0100000002500310ff36beb6c3608230534ef995f7751b6f948aeea8d21d5cc9dd5023a2c4010000006b483045022100e7c71d397b687f9f30e6003ceedc4c50436fdb2329b7a8a36c9c6759077969d30220059f24e917260d3e601c77079d03c9e73d04fd85f625eaebfd14a1ff695a72230121020bc134c91f4ff068f3a970616fad577f949406c18849321a2f6d4df96fc56c77feffffffeffed95ded4f227fc6717f224e85e50348ce0198303a5418f157ade42828a1e3000000006b483045022100f0bde463404db0983e0f221bfa1b13edf1063a78e869295c9457864b122a622b02207d9d5df76ecac6289784201e9a918acb34510c2d65144bf8e4753a3413024e320121022565ed0ff8f79ecf11e8f33b9fbba5606dbc0618813acd74603f9466e88fb8a8feffffff02402305060000000017a9146a58967510cfd7e04987b245f73dbf62e8d3fdf8871e194f00000000001976a914132b05f47f2b1b56f26a78d3962e3acd0735f12d88ac00000000'; +rawtx='0100000001eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6010000006a4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057abffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac10ca0f24010000001976a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac00000000'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "decoderawtransaction", @@ -208,73 +217,68 @@ bcoin-cli rpc decoderawtransaction $rawtx ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('decoderawtransaction', [ rawtx ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('decoderawtransaction', [ rawtx ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "txid": "28d65fdaf5334ffd29066d7076f056bb112baa4bb0842f6eaa06171c277b4e8c", - "hash": "28d65fdaf5334ffd29066d7076f056bb112baa4bb0842f6eaa06171c277b4e8c", - "size": 372, - "vsize": 372, + "txid": "0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8", + "hash": "0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8", + "size": 225, + "vsize": 225, "version": 1, "locktime": 0, "vin": [ { - "txid": "c4a22350ddc95c1dd2a8ee8a946f1b75f795f94e53308260c3b6be36ff100350", + "txid": "e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea", "scriptSig": { - "asm": "3045022100e7c71d397b687f9f30e6003ceedc4c50436fdb2329b7a8a36c9c6759077969d30220059f24e917260d3e601c77079d03c9e73d04fd85f625eaebfd14a1ff695a722301 020bc134c91f4ff068f3a970616fad577f949406c18849321a2f6d4df96fc56c77", - "hex": "483045022100e7c71d397b687f9f30e6003ceedc4c50436fdb2329b7a8a36c9c6759077969d30220059f24e917260d3e601c77079d03c9e73d04fd85f625eaebfd14a1ff695a72230121020bc134c91f4ff068f3a970616fad577f949406c18849321a2f6d4df96fc56c77" + "asm": "30440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add65601 03142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057ab", + "hex": "4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057ab" }, - "sequence": 4294967294, + "sequence": 4294967295, "vout": 1 - }, - { - "txid": "e3a12828e4ad57f118543a309801ce4803e5854e227f71c67f224fed5dd9feef", - "scriptSig": { - "asm": "3045022100f0bde463404db0983e0f221bfa1b13edf1063a78e869295c9457864b122a622b02207d9d5df76ecac6289784201e9a918acb34510c2d65144bf8e4753a3413024e3201 022565ed0ff8f79ecf11e8f33b9fbba5606dbc0618813acd74603f9466e88fb8a8", - "hex": "483045022100f0bde463404db0983e0f221bfa1b13edf1063a78e869295c9457864b122a622b02207d9d5df76ecac6289784201e9a918acb34510c2d65144bf8e4753a3413024e320121022565ed0ff8f79ecf11e8f33b9fbba5606dbc0618813acd74603f9466e88fb8a8" - }, - "sequence": 4294967294, - "vout": 0 } ], "vout": [ { - "value": 1.01, + "value": 0.4, "n": 0, "scriptPubKey": { - "asm": "OP_HASH160 6a58967510cfd7e04987b245f73dbf62e8d3fdf8 OP_EQUAL", - "hex": "a9146a58967510cfd7e04987b245f73dbf62e8d3fdf887", - "type": "SCRIPTHASH", + "asm": "OP_DUP OP_HASH160 fe7e0711287688b33b9a5c239336c4700db34e63 OP_EQUALVERIFY OP_CHECKSIG", + "hex": "76a914fe7e0711287688b33b9a5c239336c4700db34e6388ac", + "type": "PUBKEYHASH", "reqSigs": 1, "addresses": [ - "2N2wXjoQbEQTKQuqYdkpHMp7rPpnpumYYqe" + "RYUpgnvLvfi5T7q3hGSVvFrUy14kt61FC1" ] } }, { - "value": 0.05183774, + "value": 48.9998184, "n": 1, "scriptPubKey": { - "asm": "OP_DUP OP_HASH160 132b05f47f2b1b56f26a78d3962e3acd0735f12d OP_EQUALVERIFY OP_CHECKSIG", - "hex": "76a914132b05f47f2b1b56f26a78d3962e3acd0735f12d88ac", + "asm": "OP_DUP OP_HASH160 af92ad98c7f77559f96430dfef2a6805b87b24f8 OP_EQUALVERIFY OP_CHECKSIG", + "hex": "76a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac", "type": "PUBKEYHASH", "reqSigs": 1, "addresses": [ - "mhGJg1PJg8hVPX9A6zg4q389YFisSzQW6d" + "RRHY3TejXvTh6B1V5auViS9jVUcNxAUcrj" ] } } @@ -302,12 +306,11 @@ let script; ``` ```shell--vars -script='483045022100f0bde463404db0983e0f221bfa1b13edf1063a78e869295c9457864b122a622b02207d9d5df76ecac6289784201e9a918acb34510c2d65144bf8e4753a3413024e320121022565ed0ff8f79ecf11e8f33b9fbba5606dbc0618813acd74603f9466e88fb8a8'; +script='76a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "decodescript", @@ -321,28 +324,34 @@ bcoin-cli rpc decodescript $script ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('decodescript', [ script ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('decodescript', [ script ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "asm": "3045022100f0bde463404db0983e0f221bfa1b13edf1063a78e869295c9457864b122a622b02207d9d5df76ecac6289784201e9a918acb34510c2d65144bf8e4753a3413024e3201 022565ed0ff8f79ecf11e8f33b9fbba5606dbc0618813acd74603f9466e88fb8a8", - "type": "NONSTANDARD", + "asm": "OP_DUP OP_HASH160 af92ad98c7f77559f96430dfef2a6805b87b24f8 OP_EQUALVERIFY OP_CHECKSIG", + "type": "PUBKEYHASH", "reqSigs": 1, - "addresses": [], - "p2sh": "2MyVRHsEpec67MkPLGr4NR2bT1ZFuzFGUoB" + "addresses": [ + "RRHY3TejXvTh6B1V5auViS9jVUcNxAUcrj" + ], + "p2sh": "GYtKY86R5JdPqDGEa3meuhE1tz3f7M45uD" } ``` @@ -361,12 +370,11 @@ let rawtx; ``` ```shell--vars -rawtx='0100000002500310ff36beb6c3608230534ef995f7751b6f948aeea8d21d5cc9dd5023a2c4010000006b483045022100e7c71d397b687f9f30e6003ceedc4c50436fdb2329b7a8a36c9c6759077969d30220059f24e917260d3e601c77079d03c9e73d04fd85f625eaebfd14a1ff695a72230121020bc134c91f4ff068f3a970616fad577f949406c18849321a2f6d4df96fc56c77feffffffeffed95ded4f227fc6717f224e85e50348ce0198303a5418f157ade42828a1e3000000006b483045022100f0bde463404db0983e0f221bfa1b13edf1063a78e869295c9457864b122a622b02207d9d5df76ecac6289784201e9a918acb34510c2d65144bf8e4753a3413024e320121022565ed0ff8f79ecf11e8f33b9fbba5606dbc0618813acd74603f9466e88fb8a8feffffff02402305060000000017a9146a58967510cfd7e04987b245f73dbf62e8d3fdf8871e194f00000000001976a914132b05f47f2b1b56f26a78d3962e3acd0735f12d88ac00000000'; +rawtx='0100000001eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6010000006a4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057abffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac10ca0f24010000001976a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac00000000'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "sendrawtransaction", @@ -380,23 +388,27 @@ bcoin-cli rpc sendrawtransaction $rawtx ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('sendrawtransaction', [ rawtx ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('sendrawtransaction', [ rawtx ]); + console.log(result); +})(); ``` > ```json -"28d65fdaf5334ffd29066d7076f056bb112baa4bb0842f6eaa06171c277b4e8c" +"0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8" ``` Sends raw transaction without verification @@ -415,59 +427,58 @@ let txhash, txindex, amount, address, data; ``` ```shell--vars -txhash='d1e1b6a8ff8c4d2ade2113a5dd250637e5f99667d36dcae9b70139516cb7052f'; +txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; txindex=1; -amount=1; - +amount=48.99900000; address='RStiqGLWA3aSMrWDyJvur4287GQ81AtLh1'; data=''; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "createrawtransaction", "params": [ - [{ "txid": "'$txhash'", "vout": "'$txindex'" }], - { "'$address'": "'$amount'", "data": "'$data'" } + [{ "txid": "'$txhash'", "vout": '$txindex' }], + { "'$address'": '$amount', "data": "'$data'" } ] }' ``` ```shell--cli bcoin-cli rpc createrawtransaction \ - '[{ "txid": "'$txhash'", "vout": "'$txindex'" }]' \ - '{ "'$address'": "'$amount'", "data": "'$data'" }' - + '[{ "txid": "'$txhash'", "vout": '$txindex' }]' \ + '{ "'$address'": '$amount', "data": "'$data'" }' ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'regtest' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); (async () => { const sendTo = { data: data }; - sendTo[address] = amount; - - const res = await rpc.execute('createrawtransaction', [ [{ txid: txhash, vout: txindex }], sendTo]); - - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); + const result = await client.execute('createrawtransaction', [ [{ txid: txhash, vout: txindex }], sendTo]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -"01000000012f05b76c513901b7e9ca6dd36796f9e5370625dda51321de2a4d8cffa8b6e1d10100000000ffffffff0200e1f505000000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac0000000000000000026a0000000000" +"0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e0100000000ffffffff02608a0e24010000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac0000000000000000026a0000000000" ``` + + Creates raw, unsigned transaction without any formal verification. ### Params @@ -485,8 +500,8 @@ N. | Name | Default | Description 1.2 | vout | | Transaction Outpoint Index 1.3 | sequence | | Sequence number for input 2 | sendto | Required | List of addresses with amounts that we are sending to. -2.1 | address | 0 | `address: amount` key pairs -2.2 | data | nullData | Data output +2.1 | address | 0 | `address: amount` key pairs (_string_: _float_) +2.2 | data | nullData | Data output (added as `OP_RETURN`) 3 | locktime | | earliest time a transaction can be added @@ -497,18 +512,16 @@ let rawtx, txhash, txindex, scriptPubKey, amount, privkey; ``` ```shell--vars -rawtx='01000000012f05b76c513901b7e9ca6dd36796f9e5370625dda51321de2a4d8cffa8b6e1d10100000000ffffffff020000000000000000026a0000e1f505000000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac00000000'; -txhash='d1e1b6a8ff8c4d2ade2113a5dd250637e5f99667d36dcae9b70139516cb7052f'; +rawtx='0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e0100000000ffffffff02608a0e24010000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac0000000000000000026a0000000000'; +txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; txindex=1; -scriptPubKey='76a9146efd5e2fda72ae2e37f8fb8cde83fbc8025fc96e88ac'; -amount=1; - -privkey='ET4VkeCoHmtKtoWJKco5PBSaVkqsVwqSbsqhneqN4Uo5yaTMxRmV'; +scriptPubKey='76a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac'; +amount=48.99900000; +privkey='ELvsQiH9X1kgmbzD1j4ESAJnN47whh8qZHVF8B9DpSpecKQDcfX6'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "signrawtransaction", @@ -516,9 +529,9 @@ curl $url/ \ "'$rawtx'", [{ "txid": "'$txhash'", - "vout": "'$txindex'", + "vout": '$txindex', "scriptPubKey": "'$scriptPubKey'", - "amount": "'$amount'" + "amount": '$amount' }], [ "'$privkey'" ] ] @@ -527,19 +540,26 @@ curl $url/ \ ```shell--cli bcoin-cli rpc signrawtransaction $rawtx \ - '[{ "txid": "'$txhash'", "vout": "'$txindex'", "scriptPubKey": "'$scriptPubKey'", "amount": "'$amount'" }]' \ + '[{ "txid": "'$txhash'", "vout": '$txindex', "scriptPubKey": "'$scriptPubKey'", "amount": '$amount' }]' \ '[ "'$privkey'" ]' ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'regtest' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); (async () => { - const res = await rpc.execute('signrawtransaction', [ rawtx, + const result = await client.execute('signrawtransaction', [ rawtx, [{ txid: txhash, vout: txindex, @@ -548,18 +568,15 @@ const rpc = new NodeClient({ }], [ privkey ] ]); - - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json { - "hex": "01000000012f05b76c513901b7e9ca6dd36796f9e5370625dda51321de2a4d8cffa8b6e1d1010000006b48304502210094252b4db106def63264668717c5ad66e2804c5e1b390c6240e82515fb0c12690220708430b14ceb0a15308e665de21cb3eb9e6cd9e4571e110fbfddf65ef702cd990121035ef2bf6d09a343c4c0be6fb5b489b217c00f477a9878b60ca3ceca4c2b052c3cffffffff020000000000000000026a0000e1f505000000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac00000000", + "hex": "0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e010000006a47304402205088870d469e5a878c54186e971cdc59d4e0c74f1c88709f584590ba76a9b97002202b4810a122fc4977e5a77c80dc68d4ffa73d22dbf385e46241dda6bddfd7993901210284a937f256393b3ba686556e90bd000706600bdbee4169abd092f392689307d2ffffffff02608a0e24010000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac0000000000000000026a0000000000", "complete": true } ``` @@ -583,51 +600,55 @@ N. | Name | Default | Description ## gettxoutproof ```javascript -let txhash; +let txid0, txid1; ``` ```shell--vars -txhash='c75f8c12c6d0d1a16d7361b724898968c71de0335993ee589f82fda8ac482bfc'; +txid0='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8'; +txid1='e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "gettxoutproof", - "params": [ "'$txhash'" ] + "params": [ ["'$txid0'", "'$txid1'"] ] }' ``` ```shell--cli -bcoin-cli rpc gettxoutproof $txhash +bcoin-cli rpc gettxoutproof '[ "'$txid0'", "'$txid1'" ]' ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('gettxoutproof', [ txhash ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.execute('gettxoutproof', [ [ txid0, txid1 ] ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -"000000208c13da491196839dd019c4ae0564f351502a4951e11b4302454b020000000000f1788fd057d657150b12e5638c7348fb55fdcda4ff4ddb1d1503de3576de6a4cbe22db58f0ec091b918981c50200000001f1788fd057d657150b12e5638c7348fb55fdcda4ff4ddb1d1503de3576de6a4c0100" +"00000020e562d79a1ffb4f95926ed1c67baab26b7e73712369a61b134eb881205bd8110ef08c63626ea13ca11fddad4f2c0a2b67354efdcd50f769b73330af205dcdd054cbd3055bffff7f20010000000500000004ae4be9cd199b09f605119820680eb23462746e98fbc2b0c635643f00b34c3cd8958799d4b8d29f4ab6ae6495047d330a9ea83b377cbb937395c302ea98c72279eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e02eb01" ``` Checks if transactions are within block. -Returns raw block. +Returns proof of transaction inclusion (raw MerkleBlock). ### Params N. | Name | Default | Description @@ -643,12 +664,11 @@ let proof; ``` ```shell--vars -proof='000000208c13da491196839dd019c4ae0564f351502a4951e11b4302454b020000000000f1788fd057d657150b12e5638c7348fb55fdcda4ff4ddb1d1503de3576de6a4cbe22db58f0ec091b918981c50200000001f1788fd057d657150b12e5638c7348fb55fdcda4ff4ddb1d1503de3576de6a4c0100'; +proof='00000020e562d79a1ffb4f95926ed1c67baab26b7e73712369a61b134eb881205bd8110ef08c63626ea13ca11fddad4f2c0a2b67354efdcd50f769b73330af205dcdd054cbd3055bffff7f20010000000500000004ae4be9cd199b09f605119820680eb23462746e98fbc2b0c635643f00b34c3cd8958799d4b8d29f4ab6ae6495047d330a9ea83b377cbb937395c302ea98c72279eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e02eb01'; ``` ```shell--curl -curl $url/ \ - -H 'Content-Type: application/json' \ +curl $url \ -X POST \ --data '{ "method": "verifytxoutproof", @@ -663,28 +683,34 @@ bcoin-cli rpc verifytxoutproof $proof ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - const res = await rpc.execute('verifytxoutproof', [ proof ]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(res); -})().catch((err) => { - console.error(err.stack); -}); +const client = new NodeClient(clientOptions); + +(async () => { + const result = await client.execute('verifytxoutproof', [ proof ]); + console.log(result); +})(); ``` > The above command returns JSON "result" like this: ```json -[] -``` +[ + "e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea", + "0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8" +]``` -Checks the proof for transaction inclusion. +Checks the proof for transaction inclusion. Returns transaction hash if valid. ### Params N. | Name | Default | Description --------- | --------- | --------- | ----------- -1 | proof | Required | Proof of transaction inclusion. +1 | proof | Required | Proof of transaction inclusion (raw MerkleBlock). diff --git a/api-docs-slate/source/includes/_transaction.md b/api-docs-slate/source/includes/_transaction.md index 36071809..7a80094a 100644 --- a/api-docs-slate/source/includes/_transaction.md +++ b/api-docs-slate/source/includes/_transaction.md @@ -1,11 +1,11 @@ -# Transaction +# bcoin - Transactions Getting transaction information via API. ## Get tx by txhash @@ -15,7 +15,7 @@ let txhash; ``` ```shell--vars -txhash='86150a141ebe5903a5d31e701698a01d598b81f099ea7577dad73033eab02ef9'; +txhash='4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586'; ``` ```shell--curl @@ -28,18 +28,20 @@ bcoin-cli tx $txhash ```javascript const {NodeClient} = require('bclient'); -const client = new NodeClient({ - network: 'testnet' -}); - -(async () => { - await client.open(); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); - const tx = await client.getTX(txhash); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(tx); +const client = new NodeClient(clientOptions); - await client.close(); +(async () => { + const result = await client.getTX(txhash); + console.log(result); })().catch((err) => { console.error(err.stack); }); @@ -49,50 +51,50 @@ const client = new NodeClient({ ```json { - "hash": "86150a141ebe5903a5d31e701698a01d598b81f099ea7577dad73033eab02ef9", - "witnessHash": "86150a141ebe5903a5d31e701698a01d598b81f099ea7577dad73033eab02ef9", - "fee": 50000, - "rate": 220264, - "mtime": 1501093478, - "height": 502, - "block": "00000000e0290b7c66227c7499692aac5437860ee912424bf8eea3a3883a4e37", - "time": 1296746959, - "index": 8, + "hash": "4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586", + "witnessHash": "4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586", + "fee": 4540, + "rate": 20088, + "mtime": 1527029380, + "height": -1, + "block": null, + "time": 0, + "index": -1, "version": 1, - "flag": 1, "inputs": [ { "prevout": { - "hash": "0173a5d24d393127d5e6fc043ff1a00dafc6a2777143cb98a803a0b6e8cd02c7", + "hash": "a88387ca68a67f7f74e91723de0069154b532bf024c0e4054e36ea2234251181", "index": 0 }, - "script": "493046022100be75ae6dbf9eab7656562136511501c83918ca28c5f96565ca1960b3dbb581b6022100d15692af456e8721fddeeb0d6df5d8a147afd8a3b2a39bbceae9b1bdfd53ade20121038e297cf2cf71c16592c36ca48f5b2a5bbb73e776e772079f4c695b12eec1a509", + "script": "4830450221009fcb51c7b5956f4524490ee5f2c446faf29cc159f750d93455a9af393cd5b78d02201c3b8b0388dba8cfe3f5bef52a39e980be581d87e06433390f2b099df3855913012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46a", "witness": "00", "sequence": 4294967295, "coin": { "version": 1, - "height": 502, - "value": 4824247882, - "script": "76a914bc7aad9746a0bc03ed9715f13c94e554df90b84688ac", - "address": "mxhYHwYZdYh1AkLsUbEmU9ZGdvLfoNRdD6", - "coinbase": false + "height": 36, + "value": 5000000000, + "script": "76a91420a060fec9a7dfac723c521e168876909aa37ce588ac", + "address": "RCFhpyWXkz5GxskL96q4KtceRXuAMnWUQo", + "coinbase": true } } ], "outputs": [ { - "value": 4823922491, - "script": "76a914682215dfa6912d88f55a1853414d516122fcc66988ac", - "address": "mq1ZQJW1qPeNPNL83mpAWfNFPW9qwGDR2K" + "value": 87654321, + "script": "76a914a4ecde9642f8070241451c5851431be9b658a7fe88ac", + "address": "RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ" }, { - "value": 275391, - "script": "76a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac", - "address": "n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr" + "value": 4912341139, + "script": "76a9145bd075f5e3c5ff3e8467d94dee593d410967d93d88ac", + "address": "RHefJ5hLW9jyEwwdxhci6r7AH7SAxdpGW3" } ], "locktime": 0, - "confirmations": 1180820 + "hex": "01000000018111253422ea364e05e4c024f02b534b156900de2317e9747f7fa668ca8783a8000000006b4830450221009fcb51c7b5956f4524490ee5f2c446faf29cc159f750d93455a9af393cd5b78d02201c3b8b0388dba8cfe3f5bef52a39e980be581d87e06433390f2b099df3855913012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46affffffff02b17f3905000000001976a914a4ecde9642f8070241451c5851431be9b658a7fe88ac9360cc24010000001976a9145bd075f5e3c5ff3e8467d94dee593d410967d93d88ac00000000", + "confirmations": 207 } ``` @@ -111,7 +113,7 @@ let address; ``` ```shell--vars -address='n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr'; +address='RHefJ5hLW9jyEwwdxhci6r7AH7SAxdpGW3'; ``` ```shell--curl @@ -124,18 +126,20 @@ bcoin-cli tx $address ```javascript const {NodeClient} = require('bclient'); -const client = new NodeClient({ - network: 'testnet' -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -(async () => { - await client.open(); - - const txs = await client.getTXByAddress(address); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(txs); +const client = new NodeClient(clientOptions); - await client.close(); +(async () => { + const result = await client.getTXByAddress(address); + console.log(result); })().catch((err) => { console.error(err.stack); }); @@ -145,70 +149,53 @@ const client = new NodeClient({ ```json [ - ... { - "hash": "8351d991c5dfb49d534fcd28f56bb2d5b0d5f31f5c9e2e0711b5f86312a5abfe", - "witnessHash": "8351d991c5dfb49d534fcd28f56bb2d5b0d5f31f5c9e2e0711b5f86312a5abfe", - "fee": 50000, - "rate": 129198, - "mtime": 1501093478, - "height": 467, - "block": "00000000057c13f1fa6b30c6ec32284875781e31474a532e96739523d926a9e2", - "time": 1296743253, - "index": 20, + "hash": "4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586", + "witnessHash": "4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586", + "fee": 4540, + "rate": 20088, + "mtime": 1527029380, + "height": -1, + "block": null, + "time": 0, + "index": -1, "version": 1, - "flag": 1, "inputs": [ { "prevout": { - "hash": "d4d30e49228051bffe1317a013c06ae53f5325302a03cdcacb3312d0998f512a", - "index": 1 - }, - "script": "47304402201c29f13e8d817f2c2d1ea8b89d1d603677b86d0b4658f5d836bb16c56dc5dc3e02203e815b7ef739ba95c7bbbfdd63f38baa0806ad235f73c7df2492271e0b14ea43012103d50917ce22f377797a28c5e17e33000ea7d7d149d98b942d83f25ef2a223a8aa", - "witness": "00", - "sequence": 4294967295, - "coin": { - "version": 1, - "height": 464, - "value": 457110, - "script": "76a914583d5f973c850ec26f8efa39dabf8fbe0fcbb59c88ac", - "address": "moZXHEWiTwWyy1HSwvNANn9CKoCocPzDwm", - "coinbase": false - } - }, - { - "prevout": { - "hash": "3d708378adc61ad2b6d623bfbb89df92e3c88f6c85f6e132796d5abefae8c587", - "index": 1 + "hash": "a88387ca68a67f7f74e91723de0069154b532bf024c0e4054e36ea2234251181", + "index": 0 }, - "script": "0d17a6a8512d174b6b679c375091483045022100a3d133ccd4353c6dbcd9dc035c059b9b45f3c044644613e2311b8290bd02a3fb022026ae0af0adaea2fad2bc76d40d77fde3628031ee73c8e0e36343d5585e9d93f50121029f15918cd48f9e5cecfc1fccf1efc0c518110a6d6258cf14d0ee49a0fd88a535", + "script": "4830450221009fcb51c7b5956f4524490ee5f2c446faf29cc159f750d93455a9af393cd5b78d02201c3b8b0388dba8cfe3f5bef52a39e980be581d87e06433390f2b099df3855913012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46a", "witness": "00", "sequence": 4294967295, "coin": { "version": 1, - "height": 466, - "value": 966270, - "script": "76a914edb1dfaf6e0b39449da811275386edf2eb54baba88ac", - "address": "n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr", - "coinbase": false + "height": 36, + "value": 5000000000, + "script": "76a91420a060fec9a7dfac723c521e168876909aa37ce588ac", + "address": "RCFhpyWXkz5GxskL96q4KtceRXuAMnWUQo", + "coinbase": true } } ], "outputs": [ { - "value": 1021229, - "script": "76a91419eb536dc042d76454bea8dbec5ddc384e783e5a88ac", - "address": "mht16aZhnsHivv3cDGuzgHGvoLFy8rNkg8" + "value": 87654321, + "script": "76a914a4ecde9642f8070241451c5851431be9b658a7fe88ac", + "address": "RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ" }, { - "value": 352151, - "script": "76a914342e5d1f2eb9c6e99fda90c85ca05aa36616644c88ac", - "address": "mkGrySSnxcqRbtPCisApj3zXCQVmUUWbf1" + "value": 4912341139, + "script": "76a9145bd075f5e3c5ff3e8467d94dee593d410967d93d88ac", + "address": "RHefJ5hLW9jyEwwdxhci6r7AH7SAxdpGW3" } ], "locktime": 0, - "confirmations": 1187258 + "hex": "01000000018111253422ea364e05e4c024f02b534b156900de2317e9747f7fa668ca8783a8000000006b4830450221009fcb51c7b5956f4524490ee5f2c446faf29cc159f750d93455a9af393cd5b78d02201c3b8b0388dba8cfe3f5bef52a39e980be581d87e06433390f2b099df3855913012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46affffffff02b17f3905000000001976a914a4ecde9642f8070241451c5851431be9b658a7fe88ac9360cc24010000001976a9145bd075f5e3c5ff3e8467d94dee593d410967d93d88ac00000000", + "confirmations": 207 } + ... ] ``` @@ -228,8 +215,8 @@ let address0, address1; ``` ```shell--vars -address0='n3BmXQPa1dKi3zEyCdCGNHTuE5GLdmw1Tr'; -address1='mwLHWwWPDwtCBZA7Ltg9QSzKK5icdCU5rb'; +address0='RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ'; +address1='RHpAA3ZmmmWF6FW8qSfaEvh1jR1nUmVYnj'; ``` ```shell--curl @@ -245,90 +232,118 @@ No CLI Option. ```javascript const {NodeClient} = require('bclient'); -const client = new NodeClient({ - network: 'testnet' -}); - -(async () => { - await client.open(); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); - const txs = await client.getTXByAddress([address0, address1]); +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} - console.log(txs); +const client = new NodeClient(clientOptions); - await client.close(); -})().catch((err) => { - console.error(err.stack); -}); +(async () => { + const result = await client.getTXByAddresses([address0, address1]); + console.log(result); +})(); ``` > The above command returns JSON structured like this: ```json [ - ... { - "hash": "4692772a73ea834c836915089acf97f2c790380a2b8fd32f82729da72545d8c5", - "witnessHash": "4692772a73ea834c836915089acf97f2c790380a2b8fd32f82729da72545d8c5", - "fee": 50000, - "rate": 134048, - "mtime": 1501093478, - "height": 500, - "block": "00000000a2424460c992803ed44cfe0c0333e91af04fde9a6a97b468bf1b5f70", - "time": 1296746771, - "index": 3, + "hash": "4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586", + "witnessHash": "4c7846a8ff8415945e96937dea27bdb3144c15d793648d725602784826052586", + "fee": 4540, + "rate": 20088, + "mtime": 1527029380, + "height": -1, + "block": null, + "time": 0, + "index": -1, "version": 1, - "flag": 1, "inputs": [ { "prevout": { - "hash": "cff00582fa957178139b0db60228fc9b252adc01ec6b11c3e16f708802c12d3f", + "hash": "a88387ca68a67f7f74e91723de0069154b532bf024c0e4054e36ea2234251181", "index": 0 }, - "script": "48304502203ef5c34af08cd2865820757844ac079e081e7b41bf427ac896f41ab12a9f9857022100bd0914548145648ec538c088640228baaa983a7c78fbf49526c5c30358fe0f54012103420f2cb862c7a77d7b2376660573eb6976f01f59222892dd16326ee7ef37fc5b", + "script": "4830450221009fcb51c7b5956f4524490ee5f2c446faf29cc159f750d93455a9af393cd5b78d02201c3b8b0388dba8cfe3f5bef52a39e980be581d87e06433390f2b099df3855913012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46a", "witness": "00", "sequence": 4294967295, "coin": { "version": 1, - "height": 499, - "value": 346342, - "script": "76a914f93f789537ba00a23e7e84dcf145dae36f50ea8088ac", - "address": "n4Eras4wT4kRjX34zP96nCiHqietgeKnTn", - "coinbase": false + "height": 36, + "value": 5000000000, + "script": "76a91420a060fec9a7dfac723c521e168876909aa37ce588ac", + "address": "RCFhpyWXkz5GxskL96q4KtceRXuAMnWUQo", + "coinbase": true } + } + ], + "outputs": [ + { + "value": 87654321, + "script": "76a914a4ecde9642f8070241451c5851431be9b658a7fe88ac", + "address": "RQKEexR9ZufYP6AKbwhzdv8iuiMFDh4sNZ" }, + { + "value": 4912341139, + "script": "76a9145bd075f5e3c5ff3e8467d94dee593d410967d93d88ac", + "address": "RHefJ5hLW9jyEwwdxhci6r7AH7SAxdpGW3" + } + ], + "locktime": 0, + "hex": "01000000018111253422ea364e05e4c024f02b534b156900de2317e9747f7fa668ca8783a8000000006b4830450221009fcb51c7b5956f4524490ee5f2c446faf29cc159f750d93455a9af393cd5b78d02201c3b8b0388dba8cfe3f5bef52a39e980be581d87e06433390f2b099df3855913012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46affffffff02b17f3905000000001976a914a4ecde9642f8070241451c5851431be9b658a7fe88ac9360cc24010000001976a9145bd075f5e3c5ff3e8467d94dee593d410967d93d88ac00000000", + "confirmations": 207 + }, + { + "hash": "c87c13635f6004a802676a7f93bf90a4b27b433cf26db0c41a656f377406f3e3", + "witnessHash": "c87c13635f6004a802676a7f93bf90a4b27b433cf26db0c41a656f377406f3e3", + "fee": 4540, + "rate": 20177, + "mtime": 1527029368, + "height": -1, + "block": null, + "time": 0, + "index": -1, + "version": 1, + "inputs": [ { "prevout": { - "hash": "39661409f6bc4d9e08e413e01f867fe276e12e83dae89ee351df17757ca64b3f", + "hash": "ec25d3b6d62135eb7bba6443f0257363d961ed59526f9b4474814aeeddacbe80", "index": 0 }, - "script": "47304402201468bcfff3b1d8bdd0ba5fd94692c4dc7766411bdafe8d65b6e7a5be8f7efa8602207cdcbe3a107db271f24d7d8ac83a887ef4a1b72c910cc9ea5627b4cf37e87bcf0121025f9a9951e2d2a3037c1af09d9789b84a5776c504cd5b59bccd469124eb59835f", + "script": "473044022076644f57ae5a77f5dd511b61cd7349cf85a5646d4e17c7954dfe664c87e812c2022011c91b45c3274074215d32b6dc4599f5d4bf30f7963140e4dfe9f7ce3a9512ff012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46a", "witness": "00", "sequence": 4294967295, "coin": { "version": 1, - "height": 499, - "value": 1024528, - "script": "76a914c4a22b009b02fe8488c5543f0873e062712b7f6888ac", - "address": "mySf1HGynwyAuNyYrapRnwM83k3svzWTgD", - "coinbase": false + "height": 63, + "value": 5000000000, + "script": "76a91420a060fec9a7dfac723c521e168876909aa37ce588ac", + "address": "RCFhpyWXkz5GxskL96q4KtceRXuAMnWUQo", + "coinbase": true } } ], "outputs": [ { - "value": 1095497, - "script": "76a914ad7d7b9ac5260ad13fa55e06143283f5b36495f788ac", - "address": "mwLHWwWPDwtCBZA7Ltg9QSzKK5icdCU5rb" + "value": 12345678, + "script": "76a9145d9c4bf7f9934668c054f1b1a5589632ddc2b5b088ac", + "address": "RHpAA3ZmmmWF6FW8qSfaEvh1jR1nUmVYnj" }, { - "value": 225373, - "script": "76a914bc0f9f5fc9dc55323d52a9e354b5fb67cecd389788ac", - "address": "mxfL3bJohxaoBkKNtUF8xSU1DVKzbiChnZ" + "value": 4987649782, + "script": "76a91438530a92842d2912ea8003b934214b05c713c31888ac", + "address": "RER1Q4xkZ4WdyYSLvWVzeH2o8KVB4yHoXh" } ], "locktime": 0, - "confirmations": 1190528 + "hex": "010000000180beacddee4a8174449b6f5259ed61d9637325f04364ba7beb3521d6b6d325ec000000006a473044022076644f57ae5a77f5dd511b61cd7349cf85a5646d4e17c7954dfe664c87e812c2022011c91b45c3274074215d32b6dc4599f5d4bf30f7963140e4dfe9f7ce3a9512ff012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46affffffff024e61bc00000000001976a9145d9c4bf7f9934668c054f1b1a5589632ddc2b5b088acf67e4929010000001976a91438530a92842d2912ea8003b934214b05c713c31888ac00000000", + "confirmations": 207 } ] ``` diff --git a/api-docs-slate/source/includes/_wallet.md b/api-docs-slate/source/includes/_wallet.md index 0c6c01d1..ad0132ee 100644 --- a/api-docs-slate/source/includes/_wallet.md +++ b/api-docs-slate/source/includes/_wallet.md @@ -1,5 +1,28 @@ # Wallet ## The Wallet Client + +```shell--cli +npm i -g bclient +``` + +```javascript +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); + +const id = 'primary'; // or whatever your wallet name is + +const wallet = walletClient.wallet(id); +``` + The best way to interact with the wallet API is with the bwallet-cli in the `bclient` [package](https://www.npmjs.com/package/bclient). Installing globally with `npm i -g bclient` gives you access to the cli. You can also install locally @@ -11,53 +34,62 @@ pass in a port option. The easiest way to do this is with `bcoin.Network`. You can create a client for a specific wallet (and be compatible with the old api) with the `wallet` method on `WalletClient` class. -```shell--curl -# n/a -``` - -```shell--cli -npm i -g bclient && bwallet-cli -``` - -```javascript -const {WalletClient} = require('bclient'); -const { Network } = require('bcoin'); -const network = Network.get('testnet'); +The wallet HTTP server listens on it's own port, separate from the node's server. +By default the wallet server listens on these `localhost` ports: -const walletClient = new WalletClient({ - port: network.walletPort, - network: network.type -}); -const id = 'primary'; // or whatever your wallet name is -const wallet = WalletClient.wallet(id); +Network | API Port +--------- | ----------- +main | 8334 +testnet | 18334 +regtest | 48334 +simnet | 18558 -``` ## The WalletDB and Object ```javascript -let id, url; +let id; ``` ```shell--vars id="primary" -url="http://localhost:18334" ``` ```shell--curl -curl $url/wallet/$id/ +curl http://x:api-key@127.0.0.1:48334/wallet # will list regtest (default port 48334) wallets + +# examples in these docs will use an environment variable: +walleturl=http://x:api-key@127.0.0.1:48334/wallet/ +curl $walleturl/$id ``` ```shell--cli -bwallet-cli get --id=$id +# Like the node client, you can configure it by passing arguments: +bwallet-cli --network=regtest --id=$id get + +# ...or you can use environment variables. The default `id` is `primary`: +export BCOIN_API_KEY=yoursecret +export BCOIN_NETWORK=regtest +bwallet-cli get ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const wallet = await wallet.getInfo(); - console.log(wallet); + const result = await wallet.getInfo(); + console.log(result); })(); ``` @@ -66,68 +98,43 @@ const wallet = WalletClient.wallet(id); ```json { - "network": "testnet", - "wid": 1, + "network": "regtest", + "wid": 0, "id": "primary", - "initialized": true, "watchOnly": false, "accountDepth": 1, - "token": "977fbb8d212a1e78c7ce9dfda4ff3d7cc8bcd20c4ccf85d2c9c84bbef6c88b3c", + "token": "17715756779e4a5f7c9b26c48d90a09d276752625430b41b5fcf33cf41aa7615", "tokenDepth": 0, - "state": { - "tx": 0, - "coin": 0, - "unconfirmed": 0, - "confirmed": 0 - }, "master": { "encrypted": false }, - "account": { - "name": "default", - "initialized": true, - "witness": false, - "watchOnly": false, - "type": "pubkeyhash", - "m": 1, - "n": 1, - "accountIndex": 0, - "receiveDepth": 1, - "changeDepth": 1, - "nestedDepth": 0, - "lookahead": 10, - "receiveAddress": "mwfDKs919Br8tNFamk6RhRpfaa6cYQ5fMN", - "nestedAddress": null, - "changeAddress": "msG6V75J6XNt5mCqBhjgC4MjDH8ivEEMs9", - "accountKey": "tpubDDRH1rj7ut9ZjcGakR9VGgXU8zYSZypLtMr7Aq6CZaBVBrCaMEHPzye6ZZbUpS8YmroLfVp2pPmCdaKtRdCuTCK2HXzwqWX3bMRj3viPMZo", - "keys": [] + "balance": { + "tx": 5473, + "coin": 5472, + "unconfirmed": 1504999981750, + "confirmed": 1494999998350 } } ``` -Bcoin maintains a wallet database which contains every wallet. Wallets are not usable without also using a wallet database. For testing, the wallet database can be in-memory, but it must be there. Wallets are uniquely identified by an id and the walletdb is created with a default id of `primary`. (See [Create a Wallet](#create-a-wallet) below for more details.) +bcoin maintains a wallet database which contains every wallet. Wallets are not usable without also using a wallet database. For testing, the wallet database can be in-memory, but it must be there. Wallets are uniquely identified by an id and the walletdb is created with a default id of `primary`. (See [Create a Wallet](#create-a-wallet) below for more details.) Wallets in bcoin use bip44. They also originally supported bip45 for multisig, but support was removed to reduce code complexity, and also because bip45 doesn't seem to add any benefit in practice. -The wallet database can contain many different wallets, with many different accounts, with many different addresses for each account. Bcoin should theoretically be able to scale to hundreds of thousands of wallets/accounts/addresses. +The wallet database can contain many different wallets, with many different accounts, with many different addresses for each account. bcoin should theoretically be able to scale to hundreds of thousands of wallets/accounts/addresses. Each account can be of a different type. You could have a pubkeyhash account, as well as a multisig account, a witness pubkeyhash account, etc. Note that accounts should not be accessed directly from the public API. They do not have locks which can lead to race conditions during writes. -## HTTP Server +### wallet object vs wallet client object -The wallet HTTP server listens on it's own port, separate from the node's server. -Default ports are: +bclient returns a WalletClient object that can perform [admin functions](#wallet-admin-commands) without specifying a wallet, and may be useful when managing multiple wallets. WalletClient can also return a wallet object specified by an id. This object performs functions (and may be authorized by a token) specific to that wallet only. -```shell-vars -main: 8334 -testnet: 18334 -regtest: 48334 -simnet: 18558 -``` -This can be changed through configuration options. + ## Configuration Persistent configuration can be added to `wallet.conf` in your `prefix` directory. @@ -136,29 +143,28 @@ Same directory has `bcoin.conf` for the node server. > Example Configuration: ```shell--vars -network: testnet +network: regtest wallet-auth: true -api-key: hunter2 +api-key: api-key http-host: 0.0.0.0 ``` ## Wallet Options -> Wallet options object will look something like this +> Wallet options object will look something like this: ```json { "id": "walletId", "witness": true, "watchOnly": false, - "accountKey": "tpubDCk7nRE1aq9MPdLEV1Y5LHdifspWxKDcQWKArMP7axEaZoNZQ2mxPxc1oBxiPahCtUPKAm5TYzf6WWtJ51Yn27Qzf7snxaK36ZASCgEtbPy", + "accountKey": "rpubKB4S62xohva5NNbR3a3e84ybBb6E5AszR713RHzUrefCrbmqYuSEhvC2Reehdzz6v9vu6xN3XuMuFEC57esDUu38Af1ZZFgFydot9Zzs4ixT", "accountIndex": 1, "type": "pubkeyhash" "m": 1, @@ -188,55 +194,63 @@ mnemonic | String | | A mnemonic phrase to use to instantiate an hd private key. ## Wallet Auth -> The following samples return a wallet object +> The following samples return a wallet object using a wallet token ```javascript let token, id; ``` ```shell--vars -token='977fbb8d212a1e78c7ce9dfda4ff3d7cc8bcd20c4ccf85d2c9c84bbef6c88b3c' -id='foo' +id='primary' +token='17715756779e4a5f7c9b26c48d90a09d276752625430b41b5fcf33cf41aa7615' ``` ```shell--curl -curl $url/wallet/$id \ - -H 'Content-Type: application/json' \ - -d '{ "token": "$token" ... }' +curl $walleturl/$id?token=$token ``` ```shell--cli -bwallet-cli get --network=testnet --token=$token +bwallet-cli get --token=$token ``` ```javascript +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} -const wallet = WalletClient.wallet(id); +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id, token); (async () => { - const wallet = await wallet.getInfo(); - console.log(wallet); + const result = await wallet.getInfo(); + console.log(result); })(); ``` Individual wallets have their own api keys, referred to internally as "tokens" (a 32 byte hash - calculated as `HASH256(m/44'->ec-private-key|tokenDepth)`). -A wallet is always created with a corresponding token. When using api endpoints -for a specific wallet, the token must be sent back in the query string or json +A wallet is always created with a corresponding token. When using API endpoints +for a specific wallet, the token must be sent back in the query string or JSON body. -e.g. To get information from a wallet that requires a token - -`GET /wallet/primary/tx/:hash?token=977fbb8d212a1e78c7ce9dfda4ff3d7cc8bcd20c4ccf85d2c9c84bbef6c88b3c` + ## Reset Authentication Token ```javascript -let id, passphrase; +let id; ``` ```shell--vars -id='foo' -passphrase='bar' +id='primary' +passphrase='secret123' ``` ```shell--cli @@ -244,17 +258,28 @@ bwallet-cli retoken --id=$id --passphrase=$passphrase ``` ```shell--curl -curl $url/wallet/$id/retoken \ - -X POST - --data '{"passphrase":"'$passphrase'"}" +curl $walleturl/$id/retoken \ + -X POST \ + --data '{"passphrase":"'$passphrase'"}' ``` ```javascript -const wallet = new bcoin.http.Wallet({ id: id }); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const token = await wallet.retoken(passphrase); - console.log(token); + const result = await wallet.retoken(passphrase); + console.log(result); })(); ``` @@ -269,7 +294,7 @@ const wallet = new bcoin.http.Wallet({ id: id }); Derive a new wallet token, required for access of this particular wallet. @@ -283,28 +308,34 @@ let id; ``` ```shell--vars -id='foo' +id='primary' ``` ```shell--curl -curl $url/wallet/$id/ - +curl $walleturl/$id ``` ```shell--cli -# ID defaults to `primary` if none is passed bwallet-cli get --id=$id ``` ```javascript -`use strict` +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} -const wallet = WalletClient.wallet(id); -const id = 'foo'; +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const wallet = await wallet.getInfo(); - console.log(wallet); + const result = await wallet.getInfo(); + console.log(result); })(); ``` @@ -312,41 +343,27 @@ const id = 'foo'; ```json { - "network": "testnet", - "wid": 1, - "id": "foo", - "initialized": true, + "network": "regtest", + "wid": 0, + "id": "primary", "watchOnly": false, "accountDepth": 1, - "token": "2d04e217877f15ba920d02c24c6c18f4d39df92f3ae851bec37f0ade063244b2", - "tokenDepth": 0, - "state": { - "tx": 177, - "coin": 177, - "unconfirmed": "8150.0", - "confirmed": "8150.0" - }, + "token": "4d9e2a62f67929340b8c600bef0c965370f29cc64afcdeb7aea9cb52906c1d27", + "tokenDepth": 13, "master": { - "encrypted": false + "encrypted": true, + "until": 0, + "iv": "e33424f46674d4010fb0715bb69abc98", + "algorithm": "pbkdf2", + "n": 50000, + "r": 0, + "p": 0 }, - "account": { - "name": "default", - "initialized": true, - "witness": false, - "watchOnly": false, - "type": "pubkeyhash", - "m": 1, - "n": 1, - "accountIndex": 0, - "receiveDepth": 8, - "changeDepth": 1, - "nestedDepth": 0, - "lookahead": 10, - "receiveAddress": "mu5Puppq4Es3mibRskMwoGjoZujHCFRwGS", - "nestedAddress": null, - "changeAddress": "n3nFYgQR2mrLwC3X66xHNsx4UqhS3rkSnY", - "accountKey": "tpubDC5u44zLNUVo2gPVdqCbtX644PKccH5VZB3nqUgeCiwKoi6BQZGtr5d6hhougcD6PqjszsbR3xHrQ5k8yTbUt64aSthWuNdGi7zSwfGVuxc", - "keys": [] + "balance": { + "tx": 5473, + "coin": 5472, + "unconfirmed": 1504999981750, + "confirmed": 1494999998350 } } ``` @@ -362,31 +379,43 @@ id
_string_ | named id of the wallet whose info you would like to retrieve ## Get Master HD Key ```javascript -let id, network; +let id; ``` ```shell--vars -id='foo' -network='testnet' +id='primary' ``` ```shell--curl -curl $url/wallet/$id/master +curl $walleturl/$id/master ``` ```shell--cli -bwallet-cli master --id=$id --network=$network +bwallet-cli master --id=$id ``` ```javascript -const wallet = new bcoin.http.Wallet({ id: id, network: network}); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const master = await wallet.getMaster(); - console.log(master); + const result = await wallet.getMaster(); + console.log(result); })(); ``` -> Sample response: +> Sample responses: + +> BEFORE passphrase is set: ```json { @@ -404,7 +433,25 @@ const wallet = new bcoin.http.Wallet({ id: id, network: network}); } ``` -Get wallet master HD key. This is normally censored in the wallet info route. The provided api key must have admin access. +> AFTER passphrase is set: + +```json +{ + "encrypted": true, + "until": 1527121890, + "iv": "e33424f46674d4010fb0715bb69abc98", + "ciphertext": "c2bd62d659bc92212de5d9e939d9dc735bd0212d888b1b04a71d319e82e5ddb18008e383130fd0409113264d1cbc0db42d997ccf99510b168c80e2f39f2983382457f031d5aa5ec7a2d61f4fc92c62117e4eed59afa4a17d7cb0aae3ec5fa0d4", + "algorithm": "pbkdf2", + "n": 50000, + "r": 0, + "p": 0 +} +``` + +Get wallet master HD key. This is normally censored in the wallet info route. The provided API key must have admin access. + ### HTTP Request @@ -417,40 +464,52 @@ id
_string_ | named id of the wallet whose info you would like to retrieve ## Create A Wallet ```javascript -let id, passphrase, witness, accountKey; +let id, passphrase, witness, watchOnly, accountKey; ``` ```shell--vars -id='foo' -passphrase='bar' -witness='false' -accountKey='tpubDDh2XgSds1vBbeVgye88gsGQeCityoywRndtyrXcmvWqCgsFUyUKwzeDv8HiJhu9fC8jRAFMqxr4jj8eRTNTycmMao5wmsAScVf4jSMdPYZ' +id='newWallet' +passphrase='secret456' +witness=false +watchOnly=true +accountKey='rpubKBAoFrCN1HzSEDye7jcQaycA8L7MjFGmJD1uuvUZ21d9srAmAxmB7o1tCZRyXmTRuy5ZDQDV6uxtcxfHAadNFtdK7J6RV9QTcHTCEoY5FtQD' ``` ```shell--curl -curl $url/wallet/$id \ +curl $walleturl/$id \ -X PUT \ - --data '{"witness":'$witness', "passphrase":"'$passphrase'", "watchOnly": "true", "accountKey":"'$accountKey'"}' + --data '{"witness":'$witness', "passphrase":"'$passphrase'", "watchOnly": '$watchOnly', "accountKey":"'$accountKey'"}' ``` ```shell--cli # watchOnly defaults to true if --key flag is set -bwallet-cli create $id --witness=$witness --passphrase=$passphrase --watch=$watchOnly --key=$accountKey +bwallet-cli mkwallet $id --witness=$witness --passphrase=$passphrase --watch=$watchOnly --key=$accountKey ``` ```javascript -const client = new bcoin.http.Client(); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); + const options = { - id: id, passphrase: passphrase, witness: witness, - watchOnly: true, + watchOnly: watchOnly, accountKey: accountKey }; (async() => { - const newWallet = await client.createWallet(options) + const result = await walletClient.createWallet(id, options); + console.log(result); })(); ``` @@ -458,41 +517,27 @@ const options = { ```json { - "network": "testnet", + "network": "regtest", "wid": 2, - "id": "foo", - "initialized": true, - "watchOnly": false, + "id": "newWallet", + "watchOnly": true, "accountDepth": 1, - "token": "d9de1ddc83bf058d14520a203df6ade0dc92a684aebfac57b667705b4cac3916", + "token": "21b728d8f9e4d909349cf0c8f1e4e74fd45b180103cb7f1885a197d04012ba08", "tokenDepth": 0, - "state": { - "tx": 0, - "coin": 0, - "unconfirmed": "0.0", - "confirmed": "0.0" - }, "master": { - "encrypted": false + "encrypted": true, + "until": 1527181467, + "iv": "53effaf192a346b40b08a52dac0658ce", + "algorithm": "pbkdf2", + "n": 50000, + "r": 0, + "p": 0 }, - "account": { - "name": "default", - "initialized": true, - "witness": false, - "watchOnly": false, - "type": "pubkeyhash", - "m": 1, - "n": 1, - "accountIndex": 0, - "receiveDepth": 1, - "changeDepth": 1, - "nestedDepth": 0, - "lookahead": 10, - "receiveAddress": "muYkrSDbD8UhyWBMXxXf99EKWn22YqmwyF", - "nestedAddress": null, - "changeAddress": "mwveV7A6svE5EGGSduZmMKTwcbE775NVFt", - "accountKey": "tpubDDh2XgSds1vBbeVgye88gsGQeCityoywRndtyrXcmvWqCgsFUyUKwzeDv8HiJhu9fC8jRAFMqxr4jj8eRTNTycmMao5wmsAScVf4jSMdPYZ", - "keys": [] + "balance": { + "tx": 0, + "coin": 0, + "unconfirmed": 0, + "confirmed": 0 } } ``` @@ -518,28 +563,39 @@ let id, oldPass, newPass; ``` ```shell--vars -id='foo' -oldPass='oldpass123' -newPass='newpass123' +id='newWallet' +oldPass='secret456' +newPass='789secret' ``` ```shell--cli > No cli command available ``` -```shell-curl -curl $url/wallet/$id/passphrase \ - -X POST - --data '{"old":"'$oldPass'", "new":"'$newPass'"}' +```shell--curl +curl $walleturl/$id/passphrase \ + -X POST \ + --data '{"old":"'$oldPass'", "passphrase":"'$newPass'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.setPassphrase(oldPass, newPass); - console.log(response); -}); + const result = await wallet.setPassphrase(oldPass, newPass); + console.log(result); +})(); ``` > Sample Response: @@ -550,6 +606,7 @@ const wallet = WalletClient.wallet(id); Change wallet passphrase. Encrypt if unencrypted. + ### HTTP Request `POST /wallet/:id/passphrase` @@ -561,30 +618,29 @@ old
_string_ | Old passphrase. Pass in empty string if none new
_string_ | New passphrase ## Send a transaction -```javascript -let id, passphrase, rate, value, address; -``` - -```shell--vars -id="foo" -passphrase="bar" -rate=500 -value=1000 -address="moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA" -``` - ```shell--cli +id="primary" +passphrase="secret123" +rate=0.00000500 +value=0.00001000 +address="RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" + bwallet-cli send --id=$id --value=$value --address=$address ---passphrase=$passphrase ``` ```shell--curl -curl $url/wallet/$id/send \ +id="primary" +passphrase="secret123" +rate=500 +value=1000 +address="RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" + +curl $walleturl/$id/send \ -X POST \ --data '{ "passphrase":"'$passphrase'", @@ -596,15 +652,35 @@ curl $url/wallet/$id/send \ ``` ```javascript -const wallet = WalletClient.wallet(id); +let id, passphrase, rate, value, address; +id="primary" +passphrase="secret123" +rate=500 +value=1000 +address="RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" + +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + const options = { + passphrase: passphrase, rate: rate, outputs: [{ value: value, address: address }] }; (async () => { - const tx = await wallet.send(options); - console.log(tx); + const result = await wallet.send(options); + console.log(result); })(); ``` @@ -612,51 +688,59 @@ const options = { ```json { - "wid": 13, - "id": "foo", - "hash": "c2da22cafcd076ea3db74bb2e3cf50f030e5240aa5daf4f778fb4954a866b41c", + "hash": "8fafdf2a6c44fc48dbe01147339a59fa11f2c5a7254d2e6df27ce0a61df29cf7", "height": -1, "block": null, "time": 0, - "mtime": 1503364758, - "date": "2017-08-22T01:19:18Z", + "mtime": 1527181979, + "date": "1970-01-01T00:00:00Z", + "mdate": "2018-05-24T17:12:59Z", "size": 225, "virtualSize": 225, - "fee": 22, - "rate": 1000, + "fee": 4540, + "rate": 20177, "confirmations": 0, "inputs": [ { - "value": 59991393, - "address": "mgChJ3wXDqRns7Y6UhjXCyxeuZZJoQNj7c", + "value": 5000000000, + "address": "R9cS4kuYVWHaDJmRGMpwx7zCNjw97Zm5LL", "path": { "name": "default", "account": 0, - "change": true, - "derivation": "m/0'/1/5" + "change": false, + "derivation": "m/0'/0/0" } } ], "outputs": [ { - "value": 10000000, - "script": "76a9143f4f69730dcb175c830b94226ae13f89bef969c488ac", - "address": "mmHhzmwiUzorZLYhFH9fhrfFTAHGhx1biN" + "value": 1000, + "address": "RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8", + "path": null }, { - "value": 30000000, - "script": "76a9143f4f69730dcb175c830b94226ae13f89bef969c488ac", - "address": "mmHhzmwiUzorZLYhFH9fhrfFTAHGhx1biN" + "value": 4999994460, + "address": "RX3ZPBURVYzjRPR3wYdGepMBa26CGK8VMu", + "path": { + "name": "default", + "account": 0, + "change": true, + "derivation": "m/0'/1/0" + } } - ], - "tx": "01000000015a9b8fa3fb300a29e9cde6464f49882228862b8e333792fea35ad15536383417010000006a47304402202df28a6fe24dc26b016acee539e137b9502009f57ae6988d468d203e770339f202203b6ab4cc020493061db2d405b2799af2b872d3395f5798616fc51e59f304d5cd0121028986f0724eb55b66bba72985212b95a2c5487631e411dc9cc5348a4531928129ffffffff02e8030000000000001976a9144462dc0989942e38474616dc104e46486c5744ee88ac63619303000000001976a9149affd314659d5ce9fa815fde4e82c879d1ea41d188ac00000000" + "tx": "01000000017a2c5144386ed317c1f2ff484e7e11be718721d7ddab15773d0dd6133fb38a14000000006a4730440220710c42d68bd02789c31e7d351a6795c2a9386749e1d8a6aa61d46d5ba345843e022023d83a31e657f043d08d7e86379b818c98d788bb34bfe71ad2d9fa6dcb44b48b0121036b90b9f76925944b238239115f0c12ecee1b7e060e50850b4884aa0e0daea0c4ffffffff02e8030000000000001976a9149e6a64a9dfdf49bfa72e1402663ac40aa5e30a7188ac5cdc052a010000001976a914eebeba5a5b40bb11ca70f48b71bdb2c2b89f0c5c88ac00000000" } - ``` Create, sign, and send a transaction. + + ### HTTP Request `POST /wallet/:id/send` @@ -675,37 +759,32 @@ subtractFee
_bool_ | whether to subtract fee from outputs (evenly) subtractIndex
_int_ | subtract only from specified output index selection
_enum_ - `all`, `random`, `age`, `value`| How to select coins depth
_int_ | number of confirmation for coins to spend - - -### Output object -Property | Description ---------- | ----------- -value
_int_ | Value to send in satoshis +value
_int_ (or _float_) | Value to send in satoshis (or whole BTC, see warning above) address
_string_ | destination address for transaction ## Create a Transaction -```javascript -let id, rate, value, address, passphrase; -``` - -```shell--vars -id="foo" -passphrase="bar" -rate=500 -value=1000 -address="moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA" -``` - ```shell--cli -bwallet-cli mktx --id=$id --rate=$rate --value=$value --address=$address --passphrase=$passphrase +id="multisig1" +passphrase="multisecret123" +rate=0.00000500 +value=0.05000000 +address="RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" + +bwallet-cli mktx --id=$id --value=$value --address=$address ---passphrase=$passphrase ``` ```shell--curl -curl $url/wallet/$id/create \ +id="multisig1" +passphrase="multisecret123" +rate=500 +value=5000000 +address="RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" + +curl $walleturl/$id/create \ -X POST \ --data '{ - "rate":"'$rate'", - "passphrase": "'$passphrase'" + "passphrase":"'$passphrase'", + "rate":'$rate', "outputs":[ {"address":"'$address'", "value":'$value'} ] @@ -713,17 +792,35 @@ curl $url/wallet/$id/create \ ``` ```javascript -const wallet = WalletClient.wallet(id); -const outputs = [{ value: value, address: address }] +let id, passphrase, rate, value, address; +id="multisig1" +passphrase="multisecret123" +rate=500 +value=5000000 +address="RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" + +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + const options = { passphrase: passphrase, - outputs: outputs, rate: rate, + outputs: [{ value: value, address: address }] }; (async () => { - const tx = await wallet.createTX(options); - console.log(tx); + const result = await wallet.createTX(options); + console.log(result); })(); ``` @@ -731,50 +828,56 @@ const options = { ```json { - "hash": "0799a1d3ebfd108d2578a60e1b685350d42e1ef4d5cd326f99b8bf794c81ed17", - "witnessHash": "0799a1d3ebfd108d2578a60e1b685350d42e1ef4d5cd326f99b8bf794c81ed17", - "fee": "0.0000454", - "rate": "0.00020088", - "mtime": 1486686322, + "hash": "2c550d94e3de0de48d82199442aec45bbc75e253eaf67c953db4265691cc60ec", + "witnessHash": "2c550d94e3de0de48d82199442aec45bbc75e253eaf67c953db4265691cc60ec", + "fee": 6800, + "rate": 25855, + "mtime": 1527182869, "version": 1, - "flag": 1, "inputs": [ { "prevout": { - "hash": "6dd8dfa9b425a4126061a1032bc6ff6e208b75ee09d0aac089d105dcf972465a", + "hash": "31ebd87739a0e58098d127d76ee80ebfd8b5d923a8fcaf2d0908c16f123043be", "index": 0 }, - "script": "483045022100e7f1d57e47cd8a28b7c27e015b291f3fd43a6eb0c051a4b65d8697b5133c29f5022020cada0f62a32aecd473f606780b2aef3fd9cbd44cfd5e9e3d9fe6eee32912df012102272dae7ff2302597cb785fd95529da6c07e32946e65ead419291258aa7b17871", + "script": "0000473044022064ac064f8b0e224413cf7e7c3aa2758013dd0cff6b421a273fb6f870894b200f022064da80d0ea08110b1c18817a66b1e576f945f73256407175b0fcc9936644b3320147522102fac079263a41252f1602406313cc26caf76029135fda4f2423b997b6c89ce78f210304ea9eddb0c0fe241c89ceb2ee8b15870ede2757dfbd42fee60ba9f63d91290652ae", "witness": "00", "sequence": 4294967295, "coin": { "version": 1, - "height": 2, - "value": "50.0", - "script": "76a9149621fb4fc6e2e48538f56928f79bef968bf17ac888ac", - "address": "muCnMvAoUFZXzuao4oy3vQJFcUntax53wE", - "coinbase": true + "height": -1, + "value": 10000000, + "script": "a9143ddf94d382bc20b256748e0ab20b040efc07344c87", + "address": "GPV5UXtx3Zbb7CGL7k31kykXkbNUxM6hXW", + "coinbase": false } } ], "outputs": [ { - "value": 10000000, - "script": "76a9143f4f69730dcb175c830b94226ae13f89bef969c488ac", - "address": "mmHhzmwiUzorZLYhFH9fhrfFTAHGhx1biN" + "value": 4993200, + "script": "a9144ff1a73bf41d28a8a60e057a5c4bb0a38c0bbaf887", + "address": "GR8dHeLMn8CPVAztoEjkAxHS6eWSgf6Hcr" }, { - "value": 30000000, - "script": "76a9143f4f69730dcb175c830b94226ae13f89bef969c488ac", - "address": "moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA" + "value": 5000000, + "script": "76a9149e6a64a9dfdf49bfa72e1402663ac40aa5e30a7188ac", + "address": "RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" } ], - "locktime": 0 + "locktime": 0, + "hex": "0100000001be4330126fc108092daffca823d9b5d8bf0ee86ed727d19880e5a03977d8eb3100000000920000473044022064ac064f8b0e224413cf7e7c3aa2758013dd0cff6b421a273fb6f870894b200f022064da80d0ea08110b1c18817a66b1e576f945f73256407175b0fcc9936644b3320147522102fac079263a41252f1602406313cc26caf76029135fda4f2423b997b6c89ce78f210304ea9eddb0c0fe241c89ceb2ee8b15870ede2757dfbd42fee60ba9f63d91290652aeffffffff02b0304c000000000017a9144ff1a73bf41d28a8a60e057a5c4bb0a38c0bbaf887404b4c00000000001976a9149e6a64a9dfdf49bfa72e1402663ac40aa5e30a7188ac00000000" } ``` Create and template a transaction (useful for multisig). -Do not broadcast or add to wallet. +Does not broadcast or add to wallet. + + ### HTTP Request @@ -792,12 +895,7 @@ subtractFee
_bool_ | whether to subtract fee from outputs (evenly) subtractIndex
_int_ | subtract only from specified output index selection
_enum_ - `all`, `random`, `age`, `value`| How to select coins depth
_int_ | number of confirmation for coins to spend - - -### Output object -Property | Description ---------- | ----------- -value
_int_ | Value to send in satoshis +value
_int_ (or _float_) | Value to send in satoshis (or whole BTC, see warning above) address
_string_ | destination address for transaction @@ -808,9 +906,9 @@ let id, tx, passphrase; ``` ```shell--vars -id="foo" -passphrase="bar" -tx="01000000010d72c6b2582c2b2e625d29dd5ad89209de7e2600ab12a1a8e05813c28b703d2c000000006b483045022100af93a8761ad22af858c5bc4e68b5991eac017dcddd933cf125553ec0b83eb8f30220373a4d8ee331ac4c3975718e2a789f873af0520ddbd2db18957cdf488ccd4ee301210215a9110e2a9b293c332c28d69f88081aa2a949fde67e35a13fbe19410994ffd9ffffffff0280969800000000001976a9143f4f69730dcb175c830b94226ae13f89bef969c488ac80c3c901000000001976a9143f4f69730dcb175c830b94226ae13f89bef969c488ac00000000" +id="multisig2" +passphrase="multisecret456" +tx="0100000001be4330126fc108092daffca823d9b5d8bf0ee86ed727d19880e5a03977d8eb3100000000920000473044022064ac064f8b0e224413cf7e7c3aa2758013dd0cff6b421a273fb6f870894b200f022064da80d0ea08110b1c18817a66b1e576f945f73256407175b0fcc9936644b3320147522102fac079263a41252f1602406313cc26caf76029135fda4f2423b997b6c89ce78f210304ea9eddb0c0fe241c89ceb2ee8b15870ede2757dfbd42fee60ba9f63d91290652aeffffffff02b0304c000000000017a9144ff1a73bf41d28a8a60e057a5c4bb0a38c0bbaf887404b4c00000000001976a9149e6a64a9dfdf49bfa72e1402663ac40aa5e30a7188ac00000000" ``` ```shell--cli @@ -818,17 +916,30 @@ bwallet-cli sign --id=$id --passphrase=$passphrase --tx=$tx ``` ```shell--curl -curl $url/wallet/$id/sign \ +curl $walleturl/$id/sign \ -X POST \ --data '{"tx": "'$tx'", "passphrase":"'$passphrase'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); -const options = { passphrase: passphrase }; +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + +const options = { tx: tx, passphrase: passphrase }; + (async () => { - const signedTx = await wallet.sign(tx, options); - console.log(signedTx); + const result = await wallet.sign(options); + console.log(result); })(); ``` @@ -836,45 +947,45 @@ const options = { passphrase: passphrase }; ```json { - "hash": "2a22606ee555d2c26ec979f0c45cd2dc18c7177056189cb345989749fd587868", - "witnessHash": "2a22606ee555d2c26ec979f0c45cd2dc18c7177056189cb345989749fd587868", - "fee": 10000000, - "rate": 44247787, - "mtime": 1503683721, + "hash": "a355e0fcfb727c8161f3b2e55e0cda40f4614ea38d4834f82460cfdc9941381a", + "witnessHash": "a355e0fcfb727c8161f3b2e55e0cda40f4614ea38d4834f82460cfdc9941381a", + "fee": 170, + "rate": 507, + "mtime": 1527183237, "version": 1, "inputs": [ { "prevout": { - "hash": "2c3d708bc21358e0a8a112ab00267ede0992d85add295d622e2b2c58b2c6720d", + "hash": "31ebd87739a0e58098d127d76ee80ebfd8b5d923a8fcaf2d0908c16f123043be", "index": 0 }, - "script": "483045022100af93a8761ad22af858c5bc4e68b5991eac017dcddd933cf125553ec0b83eb8f30220373a4d8ee331ac4c3975718e2a789f873af0520ddbd2db18957cdf488ccd4ee301210215a9110e2a9b293c332c28d69f88081aa2a949fde67e35a13fbe19410994ffd9", + "script": "004730440220764ce5fa17f7d6fc8921a85ddd81e3378e88aae92a02ab8ff72646bb9d2ad3c102203075f1c8f97d48626ed22e86495c28c19386c1adb9160d84ab28fb5c7c65b103014830450221008bbc87270043e0c701cb4ba8bb7b0b8014f7bdac66fb8ae104bfe91e0469983f022003734c66e3c1f40293e90b2327fe509f68ada13c44b69bec364c01763a0699940147522102fac079263a41252f1602406313cc26caf76029135fda4f2423b997b6c89ce78f210304ea9eddb0c0fe241c89ceb2ee8b15870ede2757dfbd42fee60ba9f63d91290652ae", "witness": "00", "sequence": 4294967295, "coin": { "version": 1, - "height": 1179720, - "value": 50000000, - "script": "76a9145730f139d833e3af30ccfb7c4e253ff4bab5de9888ac", - "address": "moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA", + "height": -1, + "value": 10000000, + "script": "a9143ddf94d382bc20b256748e0ab20b040efc07344c87", + "address": "GPV5UXtx3Zbb7CGL7k31kykXkbNUxM6hXW", "coinbase": false } } ], "outputs": [ { - "value": 10000000, - "script": "76a9143f4f69730dcb175c830b94226ae13f89bef969c488ac", - "address": "mmHhzmwiUzorZLYhFH9fhrfFTAHGhx1biN" + "value": 4999830, + "script": "a9144ff1a73bf41d28a8a60e057a5c4bb0a38c0bbaf887", + "address": "GR8dHeLMn8CPVAztoEjkAxHS6eWSgf6Hcr" }, { - "value": 30000000, - "script": "76a9143f4f69730dcb175c830b94226ae13f89bef969c488ac", - "address": "mmHhzmwiUzorZLYhFH9fhrfFTAHGhx1biN" + "value": 5000000, + "script": "76a9149e6a64a9dfdf49bfa72e1402663ac40aa5e30a7188ac", + "address": "RPipJ9yeeQxHn6YcBXd9WPy2V6cezzAuY8" } ], "locktime": 0, - "hex": "01000000010d72c6b2582c2b2e625d29dd5ad89209de7e2600ab12a1a8e05813c28b703d2c000000006b483045022100af93a8761ad22af858c5bc4e68b5991eac017dcddd933cf125553ec0b83eb8f30220373a4d8ee331ac4c3975718e2a789f873af0520ddbd2db18957cdf488ccd4ee301210215a9110e2a9b293c332c28d69f88081aa2a949fde67e35a13fbe19410994ffd9ffffffff0280969800000000001976a9143f4f69730dcb175c830b94226ae13f89bef969c488ac80c3c901000000001976a9143f4f69730dcb175c830b94226ae13f89bef969c488ac00000000" + "hex": "0100000001be4330126fc108092daffca823d9b5d8bf0ee86ed727d19880e5a03977d8eb3100000000da004730440220764ce5fa17f7d6fc8921a85ddd81e3378e88aae92a02ab8ff72646bb9d2ad3c102203075f1c8f97d48626ed22e86495c28c19386c1adb9160d84ab28fb5c7c65b103014830450221008bbc87270043e0c701cb4ba8bb7b0b8014f7bdac66fb8ae104bfe91e0469983f022003734c66e3c1f40293e90b2327fe509f68ada13c44b69bec364c01763a0699940147522102fac079263a41252f1602406313cc26caf76029135fda4f2423b997b6c89ce78f210304ea9eddb0c0fe241c89ceb2ee8b15870ede2757dfbd42fee60ba9f63d91290652aeffffffff02964a4c000000000017a9144ff1a73bf41d28a8a60e057a5c4bb0a38c0bbaf887404b4c00000000001976a9149e6a64a9dfdf49bfa72e1402663ac40aa5e30a7188ac00000000" } ``` @@ -892,42 +1003,65 @@ passphrase
_string_ | passphrase to unlock the wallet ## Zap Transactions -```javascript -let id, age, account; -``` - -```shell--vars -id="foo" -account="baz" +```shell--cli +id="primary" +account="default" age=259200 # 72 hours -``` -```shell--cli -bwallet-cli zap --id=$id account=$account age=$age +bwallet-cli zap --id=$id --account=$account --age=$age ``` ```shell--curl -curl $url/wallet/$id/zap \ +id="primary" +account="default" +age=259200 # 72 hours + +curl $walleturl/$id/zap \ -X POST \ --data '{ - "account": "'$account'", - "age": "'$age'" - }' + "account": "'$account'", + "age": '$age' + }' ``` ```javascript -const wallet = WalletClient.wallet(id); +let id, age, account; +id="primary" +account="default" +age=259200 // 72 hours + +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = wallet.zap(account, age); - console.log(response); + const result = await wallet.zap(account, age); + console.log(result); })(); ``` > Sample Response +```shell--cli +Zapped! +``` -```json +```shell--curl +{ + "success": true +} +``` + +```javascript { "success": true } @@ -952,8 +1086,8 @@ let id, pass, timeout ``` ```shell--vars -id='foo' -pass='bar', +id='primary' +pass='secret123' timeout=60 ``` @@ -962,23 +1096,43 @@ bwallet-cli unlock --id=$id $pass $timeout ``` ```shell--curl -curl $url/wallet/$id/unlock \ - -X POST - --data '{"passphrase":'$pass', "timeout": '$timeout'}' +curl $walleturl/$id/unlock \ + -X POST \ + --data '{"passphrase":"'$pass'", "timeout": '$timeout'}' ``` ```javascript -const client = new bcoin.http.Client(); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + (async () => { - const response = await client.unlock(id, pass, timeout); - console.log(response); + const result = await wallet.unlock(pass, timeout); + console.log(result); })(); ``` > Sample Response -```json +```shell--cli +{"success": true} +``` + +```javascript {"success": true} ``` +```shell--curl +Unlocked. +``` + Derive the AES key from passphrase and hold it in memory for a specified number of seconds. Note: During this time, account creation and signing of transactions will not require a passphrase. @@ -999,7 +1153,7 @@ let id; ``` ```shell--vars -id='foo' +id='primary' ``` ```shell--cli @@ -1007,22 +1161,41 @@ bwallet-cli lock --id=$id ``` ```shell--curl -curl $url/wallet/$id/lock \ +curl $walleturl/$id/lock \ -X POST ``` ```javascript -const client = new bcoin.http.Client(); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + (async () => { - const response = await client.lock(id); - console.log(response); + const result = await wallet.lock(id); + console.log(result); })(); ``` > Sample Response -```json +```shell--cli +{"success": true} +``` + +```javascript {"success": true} ``` +```shell--curl +Locked. +``` If unlock was called, zero the derived AES key and revert to normal behavior. @@ -1037,35 +1210,60 @@ let id, account, key; ``` ```shell--vars -id='foo' -account='test-account' -key='0215a9110e2a9b293c332c28d69f88081aa2a949fde67e35a13fbe19410994ffd9' +id='primary' +watchid='watchonly1' +account='default' +pubkey='0215a9110e2a9b293c332c28d69f88081aa2a949fde67e35a13fbe19410994ffd9' +privkey='EMdDCvF1ZjsCnimTnTQfjw6x8CQmVidtJxKBegCVzPw3g6yRoDkK' ``` ```shell--cli -bwallet-cli import --id=$id $key +bwallet-cli --id=$id --account=$account import $privkey +bwallet-cli --id=$watchid --account=$account import $pubkey ``` ```shell--curl -curl $url/wallet/$id/import \ +curl $walleturl/$id/import \ + -X POST \ + --data '{"account":"'$account'", "privateKey":"'$privkey'"}' + +curl $walleturl/$watchid/import \ -X POST \ - --data '{"account":"'$account'", "privateKey":"'$key'"}' + --data '{"account":"'$account'", "publicKey":"'$pubkey'"}' ``` ```javascript -const wallet = new bcoin.http.Wallet({ id: id }); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); +const watchwallet = walletClient.wallet(watchid); + +(async () => { + const result = await watchwallet.importPublic(account, pubkey); + console.log(result); +})(); + (async () => { - const response = await wallet.importPrivate(account, key); - console.log(response); + const result = await wallet.importPrivate(account, privkey); + console.log(result); })(); ``` -> Sample Response +> Sample Responses ```json -{ - "success": true -} +Imported private key. + +Imported public key. ``` Import a standard WIF key. @@ -1099,9 +1297,9 @@ let id, account, address; ``` ```shell--vars -id='foo' -account='bar' -address='moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA' +id='watchonly1' +account='default' +address='RUkNXekA1QcDzNZhn2TqNavPUxmaosCzJC' ``` ```shell--cli @@ -1109,16 +1307,28 @@ bwallet-cli watch --id=$id --account=$account $address ``` ```shell--curl -curl $url/wallet/$id/import \ +curl $walleturl/$id/import \ -X POST \ --data '{"account":"'$account'", "address":"'$address'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.importAddress(account, address) + const result = await wallet.importAddress(account, address); + console.log(result); })(); ``` @@ -1150,11 +1360,11 @@ let id; ``` ```shell--vars -id="foo" +id="primary" ``` ```shell--curl -curl $url/wallet/$id/block +curl $walleturl/$id/block ``` ```shell--cli @@ -1162,12 +1372,23 @@ bwallet-cli blocks --id=$id ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const blocks = await wallet.getBlocks(); - console.log(blocks); -}()) + const result = await wallet.getBlocks(); + console.log(result); +})(); ``` > Sample Response @@ -1191,8 +1412,8 @@ let id, height; ``` ```shell--vars -id="foo" -height=1179720 +id="primary" +height=50 ``` ```shell--cli @@ -1200,27 +1421,38 @@ bwallet-cli --id=$id block $height ``` ```shell--curl -curl $url/wallet/block/$height +curl $walleturl/$id/block/$height ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const blockInfo = await wallet.getBlock(height); - console.log(blockInfo); -}) + const result = await wallet.getBlock(height); + console.log(result); +})(); ``` > Sample response: ```json { - "hash": "0000000000013cc12ea4b3ff403a3c05d96da695638e468cf26409eca87beb6a", - "height": 1179720, - "time": 1503359756, + "hash": "5a630279111118885f4489471ddf6f7a318b3510e5e17aa73412088d19b8ba78", + "height": 50, + "time": 1527181141, "hashes": [ - "2c3d708bc21358e0a8a112ab00267ede0992d85add295d622e2b2c58b2c6720d" + "4255c0784ae89cfe7ccf878be3a408d8c1f6c665d5df331e27962b4defe3beb8" ] } ``` @@ -1243,27 +1475,38 @@ let id, key, account; ``` ```shell--vars -id="multi-foo" -key="tpubDCUQshhR98hjDDPtefuQdg4Dmpk5mes3TRyUp1Qa4BjxCVytfqmqNWmJ3tUZfqu4qLfEypQhNcpMF3yhZJ8h8hcahnxCzrqWmV5qVHHTqGM" +id="multisig3" +account="default" +key="rpubKBBGCWqgVn4RRVpJTDUvTJnFHYiQuoUNy7s6W57U36KJ3r5inJp7iVRJZHvkFjbgfaGVs9fkvcCQS5ZMmc7BYFCrkADgmGKDCsjYK1vGmoFw" ``` ```shell--cli -bwallet-cli --id=$id shared add $key +bwallet-cli --id=$id --account=$account shared add $key ``` ```shell--curl -curl $url/wallet/$id/shared-key \ - -X PUT - --data '{"accountKey": $key}' +curl $walleturl/$id/shared-key \ + -X PUT \ + --data '{"accountKey": "'$key'", "account": "'$account'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); -account = 'default'; +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.addSharedKey(account, key); - console.log(response); + const result = await wallet.addSharedKey(account, key); + console.log(result); })(); ``` @@ -1279,7 +1522,7 @@ account = 'default'; Add a shared xpubkey to wallet. Must be a multisig wallet. Response will return `addedKey: true` true if key was added on this request. Returns @@ -1302,27 +1545,38 @@ let id, key; ``` ```shell--vars -id="multi-foo" -key="tpubDCUQshhR98hjDDPtefuQdg4Dmpk5mes3TRyUp1Qa4BjxCVytfqmqNWmJ3tUZfqu4qLfEypQhNcpMF3yhZJ8h8hcahnxCzrqWmV5qVHHTqGM" +id="multisig3" +account="default" +key="rpubKBBGCWqgVn4RRVpJTDUvTJnFHYiQuoUNy7s6W57U36KJ3r5inJp7iVRJZHvkFjbgfaGVs9fkvcCQS5ZMmc7BYFCrkADgmGKDCsjYK1vGmoFw" ``` ```shell--cli -bwallet-cli --id=$id shared remove $key +bwallet-cli --id=$id --account=$account shared remove $key ``` ```shell--curl -curl $url/wallet/$id/shared-key \ - -X DELETE - --data '{"accountKey": "'$key'"}' +curl $walleturl/$id/shared-key \ + -X DELETE \ + --data '{"accountKey": "'$key'", "account": "'$account'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); -const account = 'default'; +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.removeSharedKey(account, key); - console.log(response); + const result = await wallet.removeSharedKey(account, key); + console.log(result); })(); ``` @@ -1338,7 +1592,13 @@ const account = 'default'; Remove shared xpubkey from wallet if present. Response will return `removedKey: true` true if key was removed on this request. Returns -`false` if key already removed, but will still return `success: true` with status `200`. +`false` if key was already removed, but will still return `success: true` with status `200`. + + ### HTTP Request @@ -1357,8 +1617,8 @@ let id, address; ``` ```shell--vars -id="foo" -address="n1EDbjFaKFwz2XwWPueDUac4XZsQg8d1p2" +id="primary" +address="RM4xYH2GrcHmiptfsDEF7Kqqbm2Humjm2E" ``` ```shell--cli @@ -1366,15 +1626,26 @@ bwallet-cli --id=$id key $address ``` ```shell--curl -curl $url/wallet/$id/key/$address +curl $walleturl/$id/key/$address ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.getKey(address); - console.log(response); + const result = await wallet.getKey(address); + console.log(result); })(); ``` @@ -1382,20 +1653,17 @@ const wallet = WalletClient.wallet(id); ```json { - "network": "testnet", - "wid": 8, - "id": "foo", "name": "default", "account": 0, "branch": 0, - "index": 7, + "index": 2, "witness": false, "nested": false, - "publicKey": "032b110a0f83d45c1010cf03adea64b440d83a1a3726f7c2d5e94db1d6509b3ac6", + "publicKey": "02548e0a23b90505f1b4017f52cf2beeaa399fce7ff2961e29570c6afdfa9bfc5b", "script": null, "program": null, "type": "pubkeyhash", - "address": "n1EDbjFaKFwz2XwWPueDUac4XZsQg8d1p2" + "address": "RM4xYH2GrcHmiptfsDEF7Kqqbm2Humjm2E" } ``` @@ -1416,24 +1684,36 @@ let id, address; ``` ```shell--vars -id="foo" -address="n1EDbjFaKFwz2XwWPueDUac4XZsQg8d1p2" +id='primary' +passphrase='secret123' +address='RM4xYH2GrcHmiptfsDEF7Kqqbm2Humjm2E' ``` ```shell--cli -bwallet-cli --id=$id dump $address +bwallet-cli --id=$id --passphrase=$passphrase dump $address ``` ```shell--curl -curl $url/wallet/$id/wif/$address +curl $walleturl/$id/wif/$address?passphrase=$passphrase ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.getWIF(address); - console.log(response); + const result = await wallet.getWIF(address, passphrase); + console.log(result); })(); ``` @@ -1441,9 +1721,8 @@ const wallet = WalletClient.wallet(id); ```json { - "privateKey": "cTMUJ7WeFsoQ6dLGR9xdLZeNQafcU88bbibR9TV3W2HheRntYa53" + "privateKey": "EPAcwFM5E6CS1sGCv3PDeJ68nXSfUZwViZ8HyrP9T8GcGSF14EsK" } - ``` Get wallet private key (WIF format) by address. Returns just the private key @@ -1464,23 +1743,35 @@ let id, account; ``` ```shell--vars -id="foo" +id="primary" account="default" ``` ```shell--cli -bwallet-cli --id=$id address +bwallet-cli --id=$id --account=$account address ``` ```shell--curl -curl $url/wallet/$id/address -X POST --data '{"account":"'$account'"}' +curl $walleturl/$id/address -X POST --data '{"account":"'$account'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + (async () => { - const receiveAddress = await wallet.createAddress(account); - console.log(receiveAddress); + const result = await wallet.createAddress(account); + console.log(result); })(); ``` @@ -1488,21 +1779,19 @@ const wallet = WalletClient.wallet(id); ```json { - "network": "testnet", - "wid": 1, - "id": "foo", "name": "default", "account": 0, "branch": 0, - "index": 9, + "index": 5, "witness": false, "nested": false, - "publicKey": "02801d9457837ed50e9538ee1806b6598e12a3c259fdc9258bbd32934f22cb1f80", + "publicKey": "030429c7a7007b9da542c029ea72a21852c2e4dfcce339d626df022068f0149680", "script": null, "program": null, "type": "pubkeyhash", - "address": "mwX8J1CDGUqeQcJPnjNBG4s97vhQsJG7Eq" + "address": "RUkNXekA1QcDzNZhn2TqNavPUxmaosCzJC" } + ``` Derive new receiving address for account. @@ -1526,23 +1815,35 @@ let id, account; ``` ```shell--vars -id="foo" +id="primary" account="default" ``` ```shell--cli -bwallet-cli --id=$id change +bwallet-cli --id=$id --account=$account change ``` ```shell--curl -curl $url/wallet/$id/change -X POST --data '{"account":"'$account'"}' +curl $walleturl/$id/change -X POST --data '{"account":"'$account'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + (async () => { - const receiveAddress = await wallet.createChange(account); - console.log(receiveAddress); + const result = await wallet.createChange(account); + console.log(result); })(); ``` @@ -1550,21 +1851,19 @@ const wallet = WalletClient.wallet(id); ```json { - "network": "testnet", - "wid": 8, - "id": "foo", "name": "default", "account": 0, "branch": 1, - "index": 7, + "index": 27, "witness": false, "nested": false, - "publicKey": "022f5afafcc8c35dbbbe52842d58dc18d739f2dea85021ea1e9183031032f9fa1c", + "publicKey": "02fb03c9c45cbc6436c7c009391bc1410f86da9f6548675e7521856d3b372dfb42", "script": null, "program": null, "type": "pubkeyhash", - "address": "mgdArtHtCsxvcjzxRTMfk5ZyBcnsTgNKTT" + "address": "R9oeK9hgbBEYjmUffYyvPfh7eMw7q4v4XY" } +[ec ``` Derive new change address for account. @@ -1588,8 +1887,8 @@ let id, account; ``` ```shell--vars -id="foo" -account="baz" +id="witness1" +account='default' ``` ```shell--cli @@ -1597,15 +1896,26 @@ bwallet-cli --id=$id nested --account=$account ``` ```shell--curl -curl $url/wallet/$id/nested -X POST --data '{"account": "'$account'"}' +curl $walleturl/$id/nested -X POST --data '{"account": "'$account'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.createNested(account); - console.log(response); + const result = await wallet.createNested(account); + console.log(result); })(); ``` @@ -1613,20 +1923,17 @@ const wallet = WalletClient.wallet(id); ```json { - "network": "testnet", - "wid": 31, - "id": "foo", - "name": "baz", + "name": "default", "account": 0, "branch": 2, - "index": 2, + "index": 1, "witness": true, "nested": true, - "publicKey": "02a7a12fa67a7f0dc0bb2ae2c45d80c9b6248c004ef8b3f8da3f6feaf623f60939", + "publicKey": "02d10d018aad643382a77f6f6305bd209879ae450f9d3fdbcc406a666a20b40332", "script": null, - "program": "0014be20ad0c7ad43d1bb9f922f15cd7ba63b7fee290", + "program": "001421457f563883db273f4cefd519882dfefcb6ba82", "type": "scripthash", - "address": "2NBzYG49AiNJjUr7NA1r4eee8jUpacb3Eo2" + "address": "GX9yN5m5dUcSqfmNgkfQ7XJAHdyvbTHLhU" } ``` @@ -1649,8 +1956,8 @@ let id, account; ``` ```shell--vars -id='foo' -account='bar' +id='primary' +account='default' ``` ```shell--cli @@ -1658,15 +1965,26 @@ bwallet-cli --id=$id balance --account=$account ``` ```shell--curl -curl $url/wallet/$id/balance?account=$account +curl $walleturl/$id/balance?account=$account ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = wallet.getBalance(account); - console.log(response); + const result = await wallet.getBalance(account); + console.log(result); })(); ``` @@ -1674,15 +1992,15 @@ const wallet = WalletClient.wallet(id); ```json { - "wid": 1, - "id": "foo", - "account": 1, - "unconfirmed": "8149.9999546", - "confirmed": "8150.0" + "account": 0, + "tx": 307, + "coin": 287, + "unconfirmed": 1122500000000, + "confirmed": 1122500000000 } ``` -Get wallet or account balance. If no account option is passed, the call defaults to wallet balance (with account index of `-1`) +Get wallet or account balance. If no account option is passed, the call defaults to wallet balance (with account index of `-1`). Balance values for `unconfimred` and `confirmed` are expressed in satoshis. ### HTTP Request @@ -1702,11 +2020,11 @@ let id; ``` ```shell--vars -id="foo" +id="primary" ``` ```shell--curl -curl $url/wallet/$id/coin +curl $walleturl/$id/coin ``` ```shell--cli @@ -1714,11 +2032,22 @@ bwallet-cli --id=$id coins ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = wallet.getCoins(); - console.log(response); + const result = await wallet.getCoins(); + console.log(result); })(); ``` @@ -1728,24 +2057,25 @@ const wallet = WalletClient.wallet(id); [ { "version": 1, - "height": 1180963, - "value": 1000, - "script": "76a9145730f139d833e3af30ccfb7c4e253ff4bab5de9888ac", - "address": "moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA", + "height": -1, + "value": 4999998887, + "script": "76a914a2133747754faf7fbacc31bf0f74808f8409c4b388ac", + "address": "RQ4AZjpaoyXhEk3mjcWYR74YR8XhxoXGzV", "coinbase": false, - "hash": "bf49aaf50dfa229b99e83d29cae2515487b05cccb88cd111fb2ac738dac1058a", - "index": 0 + "hash": "7c7de4c48744b09b69bd36ffdb354199407321e305c0a4bd366a6168e0ff7244", + "index": 1 }, { "version": 1, - "height": 1180963, - "value": 1000, - "script": "76a9145730f139d833e3af30ccfb7c4e253ff4bab5de9888ac", - "address": "moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA", + "height": -1, + "value": 4999998887, + "script": "76a9149433dbda44a1f23396a1bd231443b0d29eb8cf2888ac", + "address": "RNnpD7tGaTpqEuTfBaqrtAqDK1927FLkW2", "coinbase": false, - "hash": "efbaa2681576e0c2a9ee8e0bdaddd889e95e9631b94467b57552e5bc7048c2ae", - "index": 0 - } + "hash": "a97a9993389ae321b263dffb68ba1312ad0655da83aeca75b2372d5abc70544a", + "index": 1 + }, + ... ] ``` List all wallet coins available. @@ -1757,13 +2087,12 @@ List all wallet coins available. ## Lock Coin/Outpoints ```javascript -let id, passphrase, hash, index; +let id, hash, index; ``` ```shell--vars -id="foo" -passphrase="bar" -hash="dd1a110edcdcbb3110a1cbe0a545e4b0a7813ffa5e77df691478205191dad66f" +id="primary" +hash="52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1" index="0" ``` @@ -1772,15 +2101,26 @@ index="0" ``` ```shell--curl -curl $url/wallet/$id/locked$hash/$index -X PUT --data '{"passphrase": "'$pasphrase'"}' +curl $walleturl/$id/locked/$hash/$index -X PUT ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.lockCoin(hash, index); - console.log(response); + const result = await wallet.lockCoin(hash, index); + console.log(result); })(); ``` @@ -1817,9 +2157,8 @@ let id, passphrase, hash, index; ``` ```shell--vars -id="foo" -passphrase="bar" -hash="dd1a110edcdcbb3110a1cbe0a545e4b0a7813ffa5e77df691478205191dad66f" +id="primary" +hash="52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1" index="0" ``` @@ -1828,15 +2167,26 @@ index="0" ``` ```shell--curl -curl $url/wallet/$id/locked/$hash/$index -X DELETE --data '{"passphrase": "'$pasphrase'"}' +curl $walleturl/$id/locked/$hash/$index -X DELETE ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.unlockCoin(hash, index); - console.log(response); + const result = await wallet.unlockCoin(hash, index); + console.log(result); })(); ``` @@ -1874,7 +2224,7 @@ let id; ``` ```shell--vars -id="foo" +id="primary" ``` ```shell--cli @@ -1882,15 +2232,26 @@ id="foo" ``` ```shell--curl -curl $url/wallet/$id/locked +curl $walleturl/$id/locked ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.getLocked(); - console.log(response); + const result = await wallet.getLocked(); + console.log(result); })(); ``` @@ -1899,8 +2260,8 @@ const wallet = WalletClient.wallet(id); ```json [ { - "hash":"dd1a110edcdcbb3110a1cbe0a545e4b0a7813ffa5e77df691478205191dad66f", - "index":0 + "hash": "52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1", + "index": 0 } ] ``` @@ -1924,9 +2285,9 @@ let id, hash, index; ``` ```shell--vars -id="foo" -hash="efbaa2681576e0c2a9ee8e0bdaddd889e95e9631b94467b57552e5bc7048c2ae" -index=0 +id="primary" +hash="52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1" +index="0" ``` ```shell--cli @@ -1936,15 +2297,26 @@ bcoin-cli coin $hash $index ``` ```shell--curl -curl $url/wallet/$id/coin/$hash/$index +curl $walleturl/$id/coin/$hash/$index ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.getCoin(hash, index); - console.log(response); + const result = await wallet.getCoin(hash, index); + console.log(result); })(); ``` @@ -1953,12 +2325,12 @@ const wallet = WalletClient.wallet(id); ```json { "version": 1, - "height": 1180963, - "value": 1000, - "script": "76a9145730f139d833e3af30ccfb7c4e253ff4bab5de9888ac", - "address": "moTyiK7aExe2v3hFJ9BCsYooTziX15PGuA", - "coinbase": false, - "hash": "efbaa2681576e0c2a9ee8e0bdaddd889e95e9631b94467b57552e5bc7048c2ae", + "height": 104, + "value": 5000000000, + "script": "76a91403a394378a680558ea205b604b182566381e116e88ac", + "address": "R9cS4kuYVWHaDJmRGMpwx7zCNjw97Zm5LL", + "coinbase": true, + "hash": "52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1", "index": 0 } ``` diff --git a/api-docs-slate/source/includes/_wallet_accounts.md b/api-docs-slate/source/includes/_wallet_accounts.md index 525f598b..151fc76c 100644 --- a/api-docs-slate/source/includes/_wallet_accounts.md +++ b/api-docs-slate/source/includes/_wallet_accounts.md @@ -3,71 +3,77 @@ > An account object looks like this: ```json - { - "wid": 1, - "id": "test", - "name": "default", - "initialized": true, - "witness": false, - "watchOnly": false, - "type": "pubkeyhash", - "m": 1, - "n": 1, - "accountIndex": 0, - "receiveDepth": 8, - "changeDepth": 1, - "nestedDepth": 0, - "lookahead": 10, - "receiveAddress": "mu5Puppq4Es3mibRskMwoGjoZujHCFRwGS", - "nestedAddress": null, - "changeAddress": "n3nFYgQR2mrLwC3X66xHNsx4UqhS3rkSnY", - "accountKey": "tpubDC5u44zLNUVo2gPVdqCbtX644PKccH5VZB3nqUgeCiwKoi6BQZGtr5d6hhougcD6PqjszsbR3xHrQ5k8yTbUt64aSthWuNdGi7zSwfGVuxc", - "keys": [] +{ + "name": "default", + "initialized": true, + "witness": false, + "watchOnly": false, + "type": "pubkeyhash", + "m": 1, + "n": 1, + "accountIndex": 0, + "receiveDepth": 6, + "changeDepth": 9, + "nestedDepth": 0, + "lookahead": 10, + "receiveAddress": "RLY9z6PCB3fggt36mnfA75jESRtvkALKX5", + "changeAddress": "RPSppa2YUzTK5jWWZ7k74NfMEJtnNKn4vs", + "nestedAddress": null, + "accountKey": "rpubKBBuJXusEYaDdxTwH1nPYRXQnd3XgLAFfNYxVhjrtvLAkDAXaps1nURZVmWuFsXK8RBXiDQu7grCBv6fRtQxgPH3FkKe4UQV7F2sfNBK47sA", + "keys": [], + "balance": { + "tx": 505, + "coin": 501, + "unconfirmed": 1339989996774, + "confirmed": 1339989999000 } - +} ``` Represents a BIP44 Account belonging to a Wallet. Note that this object does not enforce locks. Any method that does a write is internal API only and will lead to race conditions if used elsewhere. From the [BIP44 Specification](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki): -

- - This level splits the key space into independent user identities, so the wallet never mixes the coins across different accounts. - -

-

- - Users can use these accounts to organize the funds in the same fashion as bank accounts; for donation purposes (where all addresses are considered public), for saving purposes, for common expenses etc. - -

-

- - Accounts are numbered from index 0 in sequentially increasing manner. This number is used as child index in BIP32 derivation. - -

-

- - Hardened derivation is used at this level. - -

+ *This level splits the key space into independent user identities, so the wallet never mixes the coins across different accounts.* + *Users can use these accounts to organize the funds in the same fashion as bank accounts; for donation purposes (where all addresses are considered public), for saving purposes, for common expenses etc.* + *Accounts are numbered from index 0 in sequentially increasing manner. This number is used as child index in BIP32 derivation.* + *Hardened derivation is used at this level.* + + ## Get Wallet Account List ```shell--vars -id='test' +id='primary' +``` + +```shell--curl +curl $walleturl/$id/account ``` ```shell--cli -bwallet-cli account list --id=$id +bwallet-cli account --id=$id list ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const accountInfo = await wallet.getAccounts(); - console.log(accountInfo); + const result = await wallet.getAccounts(); + console.log(result); })(); ``` @@ -100,12 +106,12 @@ let id, account; ``` ```shell--vars -id='test' +id='primary' account='default' ``` ```shell--curl -curl $url/wallet/$id/account/$account +curl $walleturl/$id/account/$account ``` ```shell--cli @@ -113,10 +119,22 @@ bwallet-cli --id=$id account get $account ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); + (async () => { - const accountInfo = await wallet.getAccount(account); - console.log(accountInfo); + const result = await wallet.getAccount(account); + console.log(result); })(); ``` @@ -124,8 +142,6 @@ const wallet = WalletClient.wallet(id); ```json { - "wid": 1, - "id": "test", "name": "default", "initialized": true, "witness": false, @@ -134,15 +150,21 @@ const wallet = WalletClient.wallet(id); "m": 1, "n": 1, "accountIndex": 0, - "receiveDepth": 8, - "changeDepth": 1, + "receiveDepth": 6, + "changeDepth": 9, "nestedDepth": 0, "lookahead": 10, - "receiveAddress": "mu5Puppq4Es3mibRskMwoGjoZujHCFRwGS", + "receiveAddress": "RLY9z6PCB3fggt36mnfA75jESRtvkALKX5", + "changeAddress": "RPSppa2YUzTK5jWWZ7k74NfMEJtnNKn4vs", "nestedAddress": null, - "changeAddress": "n3nFYgQR2mrLwC3X66xHNsx4UqhS3rkSnY", - "accountKey": "tpubDC5u44zLNUVo2gPVdqCbtX644PKccH5VZB3nqUgeCiwKoi6BQZGtr5d6hhougcD6PqjszsbR3xHrQ5k8yTbUt64aSthWuNdGi7zSwfGVuxc", - "keys": [] + "accountKey": "rpubKBBuJXusEYaDdxTwH1nPYRXQnd3XgLAFfNYxVhjrtvLAkDAXaps1nURZVmWuFsXK8RBXiDQu7grCBv6fRtQxgPH3FkKe4UQV7F2sfNBK47sA", + "keys": [], + "balance": { + "tx": 505, + "coin": 501, + "unconfirmed": 1339989996774, + "confirmed": 1339989999000 + } } ``` @@ -160,32 +182,44 @@ account
_string_ | id of account you would to retrieve information for ## Create new wallet account ```javascript -let id, name, type; +let id, passphrase, name, type; ``` ```shell--vars -id='test' +id='primary' +passphrase='secret123' name='menace' type='multisig' ``` ```shell--cli -bwallet-cli --id=$id account create $name --type=$type --key=$accountKey +bwallet-cli --id=$id account create --name=$name --type=$type --passphrase=$passphrase ``` ```shell--curl -curl $url/wallet/$id/account/$name \ - -X PUT - --data '{"type": "'$type"}' +curl $walleturl/$id/account/$name \ + -X PUT \ + --data '{"type": "'$type'", "passphrase": "'$passphrase'"}' ``` ```javascript -const wallet = WalletClient.wallet(id); -const options = {type: type} +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); +const options = {name: name, type: type, passphrase: passphrase} (async () => { - const account = await wallet.createAccount(name, options); - console.log(account); + const result = await wallet.createAccount(name, options); + console.log(result); })(); ``` @@ -193,8 +227,6 @@ const options = {type: type} ```json { - "wid": 1, - "id": "test", "name": "menace", "initialized": true, "witness": false, @@ -207,11 +239,17 @@ const options = {type: type} "changeDepth": 1, "nestedDepth": 0, "lookahead": 10, - "receiveAddress": "mg7b3H3ZCHx3fwvUf8gaRHwcgsL7WdJQXv", + "receiveAddress": "GWzk797i4UCw9iG5uSj9DPQWsgt8nGWDA2", + "changeAddress": "GbqDrwBWDfKGgYuu4VvJGEjCpwxS5TiBdM", "nestedAddress": null, - "changeAddress": "mkYtQFpxDcqutMJtyzKNFPnn97zhft56wH", - "accountKey": "tpubDC5u44zLNUVo55dtQsJRsbQgeNfrp8ctxVEdDqDQtR7ES9XG5h1SGhkv2HCuKA2RZysaFzkuy5bgxF9egvG5BJgapWwbYMU4BJ1SeSj916G", - "keys": [] + "accountKey": "rpubKBBuJXusEYaDe2o6iEVjceYB4r7rGhfQGsHRynZ1pbaNvNB5eyo4GvvT3e6dfttpt6x5tomFjbooFj6vBjwpXMwJZcoFWr8LcmbW3BABQoxJ", + "keys": [], + "balance": { + "tx": 0, + "coin": 0, + "unconfirmed": 0, + "confirmed": 0 + } } ``` diff --git a/api-docs-slate/source/includes/_wallet_admin.md b/api-docs-slate/source/includes/_wallet_admin.md index d24c6af1..d4e9fe91 100644 --- a/api-docs-slate/source/includes/_wallet_admin.md +++ b/api-docs-slate/source/includes/_wallet_admin.md @@ -1,5 +1,13 @@ # Wallet Admin Commands +```shell--curl +curl http://x:api-key@127.0.0.1:48334 # will access admin functions for regtest (port 48334) wallets + +# examples in these docs will use an environment variable: +walletadminurl=http://x:api-key@127.0.0.1:48334/ +curl $walletadminurl/ +``` + Admin commands are simply commands no specific to any particular wallet, and may impact all wallets on the system. @@ -15,11 +23,11 @@ let height; ``` ```shell--vars -height = 50000 +height=50 ``` ```shell--curl -curl $walleturl/rescan \ +curl $walletadminurl/rescan \ -X POST \ --data '{"height": '$height'}' ``` @@ -29,18 +37,21 @@ bwallet-cli rescan $height ``` ```javascript -const height = 50000; const {WalletClient} = require('bclient'); -const { Network } = require('bcoin'); -const network = Network.get('testnet'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -const walletClient = new WalletClient({ +const walletOptions = { + network: network.type, port: network.walletPort, - network: network.type -}); + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); (async () => { - await walletClient.rescan(height); + const result = await walletClient.rescan(height); + console.log(result); })(); ``` @@ -54,12 +65,12 @@ const walletClient = new WalletClient({ Initiates a blockchain rescan for the walletdb. Wallets will be rolled back to the specified height (transactions above this height will be unconfirmed). ### Example HTTP Request -`POST /rescan?height=50000` +`POST /rescan?height=50` ## Wallet Resend ```shell--curl -curl $walleturl/resend \ +curl $walletadminurl/resend \ -X POST ``` @@ -69,18 +80,21 @@ bwallet-cli resend ```javascript const {WalletClient} = require('bclient'); -const { Network } = require('bcoin'); -const network = Network.get('testnet'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -const walletClient = new WalletClient({ +const walletOptions = { + network: network.type, port: network.walletPort, - network: network.type -}); + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); (async () => { - await walletClient.resend(); + result = await walletClient.resend(); + console.log(result); })(); - ``` > Response Body: @@ -101,12 +115,12 @@ let path; ``` ```shell--vars -path='/path/to/new/backup' +path='/home/user/walletdb-backup.ldb' ``` ```shell--curl -curl $walleturl/backup?path=/home/user/walletdb-backup.ldb \ - -X POST \ +curl $walletadminurl/backup?path=$path \ + -X POST ``` ```shell--cli @@ -115,18 +129,21 @@ bwallet-cli backup $path ```javascript const {WalletClient} = require('bclient'); -const { Network } = require('bcoin'); -const network = Network.get('testnet'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -const walletClient = new WalletClient({ +const walletOptions = { + network: network.type, port: network.walletPort, - network: network.type -}); + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); (async () => { - await walletClient.backup(path); + const result = await walletClient.backup(path); + console.log(result); })(); - ``` > Response Body: @@ -144,7 +161,7 @@ Safely backup the wallet database to specified path (creates a clone of the data ## List all Wallets ```shell--curl -curl $walleturl/wallet +curl $walletadminurl/wallet ``` ```shell--cli @@ -153,19 +170,21 @@ bwallet-cli wallets ```javascript const {WalletClient} = require('bclient'); -const { Network } = require('bcoin'); -const network = Network.get('testnet'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); -const walletClient = new WalletClient({ +const walletOptions = { + network: network.type, port: network.walletPort, - network: network.type -}); + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); (async () => { - const wallets = await walletClient.getWallets(); - console.log(wallets) + const result = await walletClient.getWallets(); + console.log(result); })(); - ``` > Sample Response Body: @@ -173,7 +192,12 @@ const walletClient = new WalletClient({ ```json [ "primary", - "test" + "newWallet", + "multisig1", + "multisig2", + "watchonly1", + "multisig3", + "witness1" ] ``` diff --git a/api-docs-slate/source/includes/_wallet_tx.md b/api-docs-slate/source/includes/_wallet_tx.md index 12d2fcab..37e12227 100644 --- a/api-docs-slate/source/includes/_wallet_tx.md +++ b/api-docs-slate/source/includes/_wallet_tx.md @@ -7,8 +7,8 @@ let id, hash ``` ```shell--vars -id="foo" -hash="18d2cf5683d7befe06941f59b7fb4ca0e915dcb9c6aece4ce8966a29e7c576fe" +id="primary" +hash="c7dcd8f8923f8cd0d44d0d980ddd4da80f67290ef872aab0f7be5858210712f7" ``` ```shell--cli @@ -16,46 +16,69 @@ bwallet-cli --id=$id tx $hash ``` ```shell--curl -curl $url/wallet/$id/tx/$hash +curl $walleturl/$id/tx/$hash ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.getTX(hash); - console.log(response); + const result = await wallet.getTX(hash); + console.log(result); })(); ``` > Sample Response ```json { - "wid": 1, - "id": "foo", - "hash": "18d2cf5683d7befe06941f59b7fb4ca0e915dcb9c6aece4ce8966a29e7c576fe", - "height": -1, - "block": null, - "time": 0, - "mtime": 1507077109, - "date": "2017-10-04T00:31:49Z", - "size": 225, - "virtualSize": 225, - "fee": 4540, - "rate": 20177, - "confirmations": 0, - "inputs": - [ { value: 5000009080, - address: "SdCEuxkbdMygcKtL36x2CT8p1vhz56SsbG", - path: [Object] } ], - "outputs": - [ { value: 100000000, - address: "SP7K3cSLH66zDisioqPrTC3QSRwP9GPENB", - path: null }, - { value: 4900004540, - address: "SSzzdLbBeWBwNTUpbGdD9gBk6Wzk34sT7J", - path: [Object] } ], - "tx": "010000000148ae6682231f381845f98049c871e9b6bf0a9a7f5c5270354f71079262577977000000006a47304402203359117c409d292700fbacc03e4b540066a6b8ca763f1dd578e8262fe5e74c1b02206c91f816755469cd4a6b110941b51f29e251b86afe246456cf17823ef4fc7f5301210299c1a1049d546a720dd614034ce2802a3f64d64c37b729ae184825f71d0a037affffffff0200e1f505000000001976a91413eab6745a3fcbcf8b4448c130ff8bc37db6e91b88acbc221024010000001976a9143e9958577401fe8d75ed6f162cc6832fcb26094188ac00000000" + "hash": "c7dcd8f8923f8cd0d44d0d980ddd4da80f67290ef872aab0f7be5858210712f7", + "height": 501, + "block": "05b1fa9da2acc862dd8e329bbcd158f240a844951016d9e9cd1a1bf9f61b9ac9", + "time": 1527184717, + "mtime": 1527184717, + "date": "2018-05-24T17:58:37Z", + "mdate": "2018-05-24T17:58:37Z", + "size": 200, + "virtualSize": 173, + "fee": 0, + "rate": 0, + "confirmations": 1, + "inputs": [ + { + "value": 0, + "address": null, + "path": null + } + ], + "outputs": [ + { + "value": 625009040, + "address": "RQCqU5msz7DbNGtti6fYQajEGDY2oabsvN", + "path": { + "name": "default", + "account": 0, + "change": false, + "derivation": "m/0'/0/1" + } + }, + { + "value": 0, + "address": null, + "path": null + } + ], + "tx": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff2002f5010e6d696e65642062792062636f696e04f410f00b080000000000000000ffffffff0290e14025000000001976a914a3b7048d9f72788e1e2e161dc63585322689d01388ac0000000000000000266a24aa21a9ed9dae2d79e9b97a2b1f19bb16dd1c1c633f2fce683fba82eb85248fac3e32f3d90120000000000000000000000000000000000000000000000000000000000000000000000000" } ``` Get wallet transaction details. @@ -76,9 +99,8 @@ let id, hash, passphrase; ``` ```shell--vars -id="foo" -hash="2a22606ee555d2c26ec979f0c45cd2dc18c7177056189cb345989749fd58786" -passphrase="bar" +id="primary" +hash="a97a9993389ae321b263dffb68ba1312ad0655da83aeca75b2372d5abc70544a" ``` ```shell--cli @@ -86,9 +108,8 @@ passphrase="bar" ``` ```shell--curl -curl $url/wallet/$id/tx/$hash \ - -X DELETE \ - --data '{"passphrase": "'$passphrase'"}' +curl $walleturl/$id/tx/$hash \ + -X DELETE ``` ```javascript @@ -114,7 +135,7 @@ let id; ``` ```shell--vars -id='foo' +id='primary' ``` ```shell--cli @@ -122,16 +143,27 @@ bwallet-cli --id=$id history ``` ```shell--curl -curl $url/wallet/$id/tx/history +curl $walleturl/$id/tx/history ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); const account = 'default'; (async () => { - const response = await wallet.getHistory(account); - console.log(response); + const result = await wallet.getHistory(account); + console.log(result); })(); ``` > Sample Response @@ -199,7 +231,7 @@ let id; ``` ```shell--vars -id='foo' +id='primary' ``` ```shell--cli @@ -207,15 +239,26 @@ bwallet-cli --id=$id pending ``` ```shell--curl -curl $url/wallet/$id/tx/unconfirmed +curl $walleturl/$id/tx/unconfirmed ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.getPending(account); - console.log(response); + const result = await wallet.getPending(); + console.log(result); })(); ``` @@ -237,10 +280,10 @@ let id, account, start, end; ``` ```shell--vars -id="foo" -account="foo" -start="1506909119" -end="1506909154" +id="primary" +account="default" +start="1527184612" +end="1527186612" ``` ```shell--cli @@ -248,37 +291,70 @@ end="1506909154" ``` ```shell--curl -curl $url/wallet/$id/tx/range?start=$start +curl $walleturl/$id/tx/range?start=$start'&'end=$end ``` ```javascript -const wallet = WalletClient.wallet(id); +const {WalletClient} = require('bclient'); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +const walletOptions = { + network: network.type, + port: network.walletPort, + apiKey: 'api-key' +} + +const walletClient = new WalletClient(walletOptions); +const wallet = walletClient.wallet(id); (async () => { - const response = await wallet.getRange(account, {start: start, end: end}); - console.log(response); + const result = await wallet.getRange(account, {start: start, end: end}); + console.log(result); })(); ``` > Sample Response ```json [ - { "wid": 1, - "id": "primary", - "hash": "80ac63671e7b8635d10d372c4c3bed5615624d9fa28dfd747abf440417d70983", - "height": -1, - "block": null, - "time": 0, - "mtime": 1506909119, - "date": "2017-10-02T01:51:59Z", + { + "hash": "c7dcd8f8923f8cd0d44d0d980ddd4da80f67290ef872aab0f7be5858210712f7", + "height": 501, + "block": "05b1fa9da2acc862dd8e329bbcd158f240a844951016d9e9cd1a1bf9f61b9ac9", + "time": 1527184717, + "mtime": 1527184717, + "date": "2018-05-24T17:58:37Z", + "mdate": "2018-05-24T17:58:37Z", "size": 200, "virtualSize": 173, "fee": 0, "rate": 0, - "confirmations": 0, - "inputs": [ [Object] ], - "outputs": [ [Object], [Object] ], - "tx": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff20028d010e6d696e65642062792062636f696e045460ad97080000000000000000ffffffff02bc03062a010000001976a914d7ee508e06ece23679ba9ee0a770561ae2ed595688ac0000000000000000266a24aa21a9ed5772988727e8641cf3c7d2bf5a7fee9a5d0e827de0b6bed5658eee8f0821b5200120000000000000000000000000000000000000000000000000000000000000000000000000" + "confirmations": 1, + "inputs": [ + { + "value": 0, + "address": null, + "path": null + } + ], + "outputs": [ + { + "value": 625009040, + "address": "RQCqU5msz7DbNGtti6fYQajEGDY2oabsvN", + "path": { + "name": "default", + "account": 0, + "change": false, + "derivation": "m/0'/0/1" + } + }, + { + "value": 0, + "address": null, + "path": null + } + ], + "tx": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff2002f5010e6d696e65642062792062636f696e04f410f00b080000000000000000ffffffff0290e14025000000001976a914a3b7048d9f72788e1e2e161dc63585322689d01388ac0000000000000000266a24aa21a9ed9dae2d79e9b97a2b1f19bb16dd1c1c633f2fce683fba82eb85248fac3e32f3d90120000000000000000000000000000000000000000000000000000000000000000000000000" }, ... ] diff --git a/api-docs-slate/source/index.html.md b/api-docs-slate/source/index.html.md index e1db1c53..742d5beb 100644 --- a/api-docs-slate/source/index.html.md +++ b/api-docs-slate/source/index.html.md @@ -18,6 +18,8 @@ toc_footers: includes: - clients - node + - coin + - transaction - node_rpc - node_rpc_general - node_rpc_chain @@ -26,10 +28,8 @@ includes: - node_rpc_tx - node_rpc_mining - node_rpc_network - - coin - - transaction - - wallet_admin - wallet + - wallet_admin - wallet_tx - wallet_accounts - wallet_events @@ -40,41 +40,57 @@ search: true # Introduction -Welcome to the Bcoin API! +Welcome to the bcoin API! -The default bcoin HTTP server listens on the standard RPC port (`8332` for main, `18332` for testnet, `48332` for regtest, and `18556` default for simnet). It exposes a REST json api, as well as a JSON-RPC api. +The default bcoin HTTP server listens on the standard RPC port (`8332` for main, `18332` for testnet, `48332` for regtest, and `18556` default for simnet). It exposes a REST JSON, as well as a JSON-RPC api. # Authentication ## Auth ```shell--curl -curl http://x:[api-key]@127.0.0.1:8332/ +# default regtest port is 48332 (may be reconfigured by user), API key is required in URL +curl http://x:api-key@127.0.0.1:48332/ + +# examples in these docs will use an environment variable: +url=http://x:api-key@127.0.0.1:48332/ +curl $url ``` ```shell--cli -export BCOIN_API_KEY=[api-key] +bcoin-cli --api-key=api-key --network=regtest info + +# store API key and network type in environment variables: +export BCOIN_API_KEY=api-key +export BCOIN_NETWORK=regtest bcoin-cli info ``` ```javascript const {NodeClient} = require('bclient'); -const rpc = new NodeClient({ - apiKey: [api-key], - //... -}); -// Or wallet -const wallet = new bcoin.http.Wallet({ - apiKey: [api-key], - //... -}); +const {Network} = require('bcoin'); +const network = Network.get('regtest'); + +// network type derived from bcoin object, client object stores API key +const clientOptions = { + network: network.type, + port: network.rpcPort, + apiKey: 'api-key' +} + +const client = new NodeClient(clientOptions); + +(async () => { + const clientinfo = await client.getInfo(); + console.log(clientinfo); +})(); ``` -> Make sure to replace `[api-key]` with your own key. +> Make sure to replace `api-key` with your own key. -Auth is accomplished via HTTP Basic Auth, using your node's API key (passed via --api-key). +Auth is accomplished via HTTP Basic Auth, using your node's API key.