🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

rpc-bitcoin

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rpc-bitcoin - npm Package Compare versions

Comparing version

to
1.7.0

2

package.json
{
"name": "rpc-bitcoin",
"version": "1.6.0",
"version": "1.7.0",
"description": "A TypeScript library to make RPC and HTTP REST requests to Bitcoin Core",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -336,2 +336,95 @@ # rpc-bitcoin [![Build Status](https://travis-ci.com/vansergen/rpc-bitcoin.svg?token=cg5dVMovG8Db6p5Qzzps&branch=master)](https://travis-ci.com/vansergen/rpc-bitcoin)

### Network
- [`addnode`](https://bitcoin.org/en/developer-reference#addnode)
```javascript
const node = "192.168.0.6:8333";
const command = "onetry";
const result = await client.addnode({ node, command });
```
- [`clearbanned`](https://bitcoin.org/en/developer-reference#clearbanned)
```javascript
const result = await client.clearbanned();
```
- [`disconnectnode`](https://bitcoin.org/en/developer-reference#disconnectnode)
```javascript
const address = "192.168.1.123:18333";
let result = await client.disconnectnode({ address });
// or by a `nodeid`
const nodeid = 3;
result = await client.disconnectnode({ nodeid });
```
- [`getaddednodeinfo`](https://bitcoin.org/en/developer-reference#getaddednodeinfo)
```javascript
const node = "192.168.0.201";
const result = await client.getaddednodeinfo({ node });
```
- [`getconnectioncount`](https://bitcoin.org/en/developer-reference#getconnectioncount)
```javascript
const result = await client.getconnectioncount();
```
- [`getnettotals`](https://bitcoin.org/en/developer-reference#getnettotals)
```javascript
const result = await client.getnettotals();
```
- [`getnetworkinfo`](https://bitcoin.org/en/developer-reference#getnetworkinfo)
```javascript
const result = await client.getnetworkinfo();
```
- [`getnodeaddresses`](https://bitcoin.org/en/developer-reference#getnodeaddresses)
```javascript
const count = 8;
const result = await client.getnodeaddresses({ count });
```
- [`getpeerinfo`](https://bitcoin.org/en/developer-reference#getpeerinfo)
```javascript
const result = await client.getpeerinfo();
```
- [`listbanned`](https://bitcoin.org/en/developer-reference#listbanned)
```javascript
const result = await client.listbanned();
```
- [`ping`](https://bitcoin.org/en/developer-reference#ping)
```javascript
const result = await client.ping();
```
- [`setban`](https://bitcoin.org/en/developer-reference#setban)
```javascript
const subnet = "192.168.0.6";
const command = "add";
const bantime = 1581599503;
const absolute = true;
const result = await client.setban({ subnet, command, bantime, absolute });
```
- [`setnetworkactive`](https://bitcoin.org/en/developer-reference#setnetworkactive)
```javascript
const state = false;
const result = await client.setnetworkactive({ state });
```
### ZMQ

@@ -355,3 +448,3 @@

- [getBlock](https://bitcoin.org/en/developer-reference#get-block)
- [`getBlock`](https://bitcoin.org/en/developer-reference#get-block)

@@ -364,3 +457,3 @@ ```javascript

- [getBlockNoTxDetails](https://bitcoin.org/en/developer-reference#get-blocknotxdetails)
- [`getBlockNoTxDetails`](https://bitcoin.org/en/developer-reference#get-blocknotxdetails)

@@ -373,3 +466,3 @@ ```javascript

- [getBlockHashByHeight](https://bitcoin.org/en/developer-reference#get-blockhashbyheight)
- [`getBlockHashByHeight`](https://bitcoin.org/en/developer-reference#get-blockhashbyheight)

@@ -382,3 +475,3 @@ ```javascript

- [getChainInfo](https://bitcoin.org/en/developer-reference#get-chaininfo)
- [`getChainInfo`](https://bitcoin.org/en/developer-reference#get-chaininfo)

@@ -389,3 +482,3 @@ ```javascript

- [getUtxos](https://bitcoin.org/en/developer-reference#get-getutxos)
- [`getUtxos`](https://bitcoin.org/en/developer-reference#get-getutxos)

@@ -408,3 +501,3 @@ ```javascript

- [getHeaders](https://bitcoin.org/en/developer-reference#get-headers)
- [`getHeaders`](https://bitcoin.org/en/developer-reference#get-headers)

@@ -418,3 +511,3 @@ ```javascript

- [getMemPoolContents](https://bitcoin.org/en/developer-reference#get-mempoolcontents)
- [`getMemPoolContents`](https://bitcoin.org/en/developer-reference#get-mempoolcontents)

@@ -425,3 +518,3 @@ ```javascript

- [getMemPoolInfo](https://bitcoin.org/en/developer-reference#get-mempoolinfo)
- [`getMemPoolInfo`](https://bitcoin.org/en/developer-reference#get-mempoolinfo)

@@ -432,3 +525,3 @@ ```javascript

- [getTx](https://bitcoin.org/en/developer-reference#get-tx)
- [`getTx`](https://bitcoin.org/en/developer-reference#get-tx)

@@ -435,0 +528,0 @@ ```javascript

@@ -14,3 +14,3 @@ import { RESTClient, RESTIniOptions } from "./rest";

method: string;
params?: any;
params?: object;
};

@@ -97,2 +97,16 @@

export type AddNodeParams = {
node: string;
command: "add" | "remove" | "onetry";
};
export type DisconnectNodeParams = { address: string } | { nodeid: number };
export type SetBanParams = {
subnet: string;
command: "add" | "remove";
bantime?: number;
absolute?: boolean;
};
export class RPCClient extends RESTClient {

@@ -407,2 +421,101 @@ wallet?: string;

/**
* @description Attempts to add or remove a node from the addnode list.
*/
async addnode({ node, command }: AddNodeParams) {
return this.rpc("addnode", { node, command });
}
/**
* @description Clear all banned IPs.
*/
async clearbanned() {
return this.rpc("clearbanned");
}
/**
* @description Immediately disconnects from the specified peer node.
*/
async disconnectnode(params: DisconnectNodeParams) {
if ("address" in params) {
return this.rpc("disconnectnode", { address: params.address });
}
return this.rpc("disconnectnode", { nodeid: params.nodeid });
}
/**
* @description Returns information about the given added node, or all added nodes
*/
async getaddednodeinfo({ node }: { node?: string } = {}) {
return this.rpc("getaddednodeinfo", { node });
}
/**
* @description Returns the number of connections to other nodes.
*/
async getconnectioncount() {
return this.rpc("getconnectioncount");
}
/**
* @description Returns information about network traffic, including bytes in, bytes out, and current time.
*/
async getnettotals() {
return this.rpc("getnettotals");
}
/**
* @description Returns an object containing various state info regarding P2P networking.
*/
async getnetworkinfo() {
return this.rpc("getnetworkinfo");
}
/**
* @description Return known addresses which can potentially be used to find new nodes in the network
*/
async getnodeaddresses({ count = 1 } = {}) {
return this.rpc("getnodeaddresses", { count });
}
/**
* @description Returns data about each connected network node as a json array of objects.
*/
async getpeerinfo() {
return this.rpc("getpeerinfo");
}
/**
* @description List all banned IPs/Subnets.
*/
async listbanned() {
return this.rpc("listbanned");
}
/**
* @description Requests that a ping be sent to all other nodes, to measure ping time.
*/
async ping() {
return this.rpc("ping");
}
/**
* @description Attempts to add or remove an IP/Subnet from the banned list
*/
async setban({
subnet,
command,
bantime = 0,
absolute = false
}: SetBanParams) {
return this.rpc("setban", { subnet, command, bantime, absolute });
}
/**
* @description Disable/enable all p2p network activity.
*/
async setnetworkactive({ state }: { state: boolean }) {
return this.rpc("setnetworkactive", { state });
}
/**
* @description Returns information about the active ZeroMQ notifications.

@@ -409,0 +522,0 @@ */

@@ -74,3 +74,2 @@ import { RPCClient, ScanTxOutSetParams } from "../.";

"000000000004f7f1ec631acb86a86ef0d97f1294d79f5fba1d0e579c1513b5ea";
const response = { error, id, result };
nock(uri)

@@ -80,3 +79,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { error, id, result });
const data = await client.rpc(method);

@@ -108,3 +107,2 @@ assert.deepStrictEqual(data, result);

const result = "tb1quchcvzestaj5kfnyu6wz7hwyn0lttdq2949tsj";
const response = { result, error, id };
nock(uri)

@@ -114,3 +112,3 @@ .post("/wallet/" + wallet, request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.rpc(method, params, wallet);

@@ -125,3 +123,2 @@ assert.deepStrictEqual(data, result);

"000000006e60e2ae7b464e4e38e061cb4aea9dafa605cc1d38d34601fdf77064";
const response = { result, error, id };
nock(uri)

@@ -131,3 +128,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getbestblockhash();

@@ -268,3 +265,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -274,3 +270,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getblock(params);

@@ -320,3 +316,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -326,3 +321,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getblockchaininfo();

@@ -335,3 +330,2 @@ assert.deepStrictEqual(data, result);

const result = 1583782;
const response = { result, error, id };
nock(uri)

@@ -341,3 +335,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getblockcount();

@@ -353,3 +347,2 @@ assert.deepStrictEqual(data, result);

"00000000a4991fe43933f0a0bde13b6b22b4308442453845903151004e9cc0a5";
const response = { result, error, id };
nock(uri)

@@ -359,3 +352,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getblockhash(params);

@@ -373,3 +366,2 @@ assert.deepStrictEqual(data, result);

"00000020be5175185b585f99038eb6dae6bc084eeb1a0d796ce5a4586aa17d6d00000000f5c0b3856438c40ab89c9d3aa86801bc5536218a59a5f941d31981c831bbf3d358fe965dffff001d1734db1f";
const response = { result, error, id };
nock(uri)

@@ -379,3 +371,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getblockheader(params);

@@ -392,3 +384,2 @@ assert.deepStrictEqual(data, result);

const result = { time: 1570176600, txs: 469 };
const response = { result, error, id };
nock(uri)

@@ -398,3 +389,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getblockstats(params);

@@ -436,3 +427,2 @@ assert.deepStrictEqual(data, result);

];
const response = { result, error, id };
nock(uri)

@@ -442,3 +432,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getchaintips();

@@ -464,3 +454,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -470,3 +459,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getchaintxstats(params);

@@ -479,3 +468,2 @@ assert.deepStrictEqual(data, result);

const result = 1;
const response = { result, error, id };
nock(uri)

@@ -485,3 +473,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getdifficulty();

@@ -525,3 +513,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -531,3 +518,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getmempoolancestors(params);

@@ -571,3 +558,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -577,3 +563,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getmempooldescendants(params);

@@ -614,3 +600,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -620,3 +605,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getmempoolentry(params);

@@ -636,3 +621,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -642,3 +626,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getmempoolinfo();

@@ -702,3 +686,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -708,3 +691,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getrawmempool(params);

@@ -735,3 +718,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -741,3 +723,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.gettxout(params);

@@ -757,3 +739,2 @@ assert.deepStrictEqual(data, result);

"00000020e798ee174759ba2eb4f57c8055eaadb903aeef74a407878265361d00000000005c70c7f197058b8ff6f06d9f144497d1801e057e06735a56b658ac78ff915516fa7ab05dffff001d32384563dd00000009eeeb7a022e70291fe3d8d5186615358d45107c10d71a212459b30fe73174494f956b752c3495a3ba3e539db047bbb2e6b4124d4b4f8cbf89506ea17cf04b0ce5864f91edb21f1918fb1031d5545c7b835fb82d8cdc87f1df76808c599bbcb4e372e0788a9ce2c9b2f1a07305b7bea5e1fca0b19f77d919e51e2e72e438c19df5a953ce7bad42e1c78372ad2df199a08c26153f7846f6cc95c4615572bc997b45803b803c49e6298dec1a9029c32addac44f2abbc8c496def1f47a6ff55d8f90901b66efccdea0dcb52c26d610c4f2ac0b1e699ee4606918ff9901c317919038a5a3f3cedf7d664a2891fe1e116dc52e9ca9166e4e8a6398b10072412ef3893693508204127c87c8c025dded104f34ceeb44958095571907e6787615929cbc8cd03ff0200";
const response = { result, error, id };
nock(uri)

@@ -763,3 +744,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.gettxoutproof(params);

@@ -783,3 +764,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -789,3 +769,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.gettxoutsetinfo();

@@ -801,3 +781,2 @@ assert.deepStrictEqual(data, result);

const result = null;
const response = { result, error, id };
nock(uri)

@@ -807,3 +786,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.preciousblock(params);

@@ -818,3 +797,2 @@ assert.deepStrictEqual(data, result);

const result = 1566856;
const response = { result, error, id };
nock(uri)

@@ -824,3 +802,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.pruneblockchain(params);

@@ -833,3 +811,2 @@ assert.deepStrictEqual(data, result);

const result = null;
const response = { result, error, id };
nock(uri)

@@ -839,3 +816,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.savemempool();

@@ -888,3 +865,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -894,3 +870,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.scantxoutset(params);

@@ -906,3 +882,2 @@ assert.deepStrictEqual(data, result);

const result = true;
const response = { result, error, id };
nock(uri)

@@ -912,3 +887,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.verifychain(params);

@@ -926,3 +901,2 @@ assert.deepStrictEqual(data, result);

];
const response = { result, error, id };
nock(uri)

@@ -932,3 +906,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.verifytxoutproof(params);

@@ -953,3 +927,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -959,3 +932,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getmemoryinfo(params);

@@ -970,3 +943,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -976,3 +948,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getrpcinfo();

@@ -987,3 +959,2 @@ assert.deepStrictEqual(data, result);

'getzmqnotifications\n\nReturns information about the active ZeroMQ notifications.\n\nResult:\n[\n { (json object)\n "type": "pubhashtx", (string) Type of notification\n "address": "...", (string) Address of the publisher\n "hwm": n (numeric) Outbound message high water mark\n },\n ...\n]\n\nExamples:\n> bitcoin-cli getzmqnotifications \n> curl --user myusername --data-binary \'{"jsonrpc": "1.0", "id":"curltest", "method": "getzmqnotifications", "params": [] }\' -H \'content-type: text/plain;\' http://127.0.0.1:8332/\n';
const response = { result, error, id };
nock(uri)

@@ -993,3 +964,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.help(params);

@@ -1027,3 +998,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -1033,3 +1003,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.logging(params);

@@ -1042,3 +1012,2 @@ assert.deepStrictEqual(data, result);

const result = "Bitcoin server stopping";
const response = { result, error, id };
nock(uri)

@@ -1048,3 +1017,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.stop();

@@ -1057,3 +1026,2 @@ assert.deepStrictEqual(data, result);

const result = 31;
const response = { result, error, id };
nock(uri)

@@ -1063,3 +1031,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.uptime();

@@ -1074,4 +1042,3 @@ assert.deepStrictEqual(data, result);

const request = { params, method: "generate", id, jsonrpc };
const result: any[] = [];
const response = { result, error, id };
const result: string[] = [];
nock(uri)

@@ -1081,3 +1048,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.generate(params);

@@ -1091,4 +1058,3 @@ assert.deepStrictEqual(data, result);

const request = { params, method: "generate", id, jsonrpc };
const result: any[] = [];
const response = { result, error, id };
const result: string[] = [];
nock(uri)

@@ -1098,3 +1064,3 @@ .post("/wallet/" + wallet, request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.generate(params, wallet);

@@ -1109,4 +1075,3 @@ assert.deepStrictEqual(data, result);

const request = { params, method: "generate", id, jsonrpc };
const result: any[] = [];
const response = { result, error, id };
const result: string[] = [];
nock(uri)

@@ -1116,3 +1081,3 @@ .post("/wallet/" + wallet, request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.generate(params);

@@ -1126,4 +1091,3 @@ assert.deepStrictEqual(data, result);

const request = { params, method: "generatetoaddress", id, jsonrpc };
const result: any[] = [];
const response = { result, error, id };
const result: string[] = [];
nock(uri)

@@ -1133,3 +1097,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.generatetoaddress(params);

@@ -1144,4 +1108,3 @@ assert.deepStrictEqual(data, result);

const request = { params, method: "generatetoaddress", id, jsonrpc };
const result: any[] = [];
const response = { result, error, id };
const result: string[] = [];
nock(uri)

@@ -1151,3 +1114,3 @@ .post("/wallet/" + wallet, request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.generatetoaddress(params, wallet);

@@ -1163,4 +1126,3 @@ assert.deepStrictEqual(data, result);

const request = { params, method: "generatetoaddress", id, jsonrpc };
const result: any[] = [];
const response = { result, error, id };
const result: string[] = [];
nock(uri)

@@ -1170,3 +1132,3 @@ .post("/wallet/" + wallet, request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.generatetoaddress(params);

@@ -1237,3 +1199,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -1243,3 +1204,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getblocktemplate(params);

@@ -1261,3 +1222,2 @@ assert.deepStrictEqual(data, result);

};
const response = { result, error, id };
nock(uri)

@@ -1267,3 +1227,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getmininginfo();

@@ -1277,3 +1237,2 @@ assert.deepStrictEqual(data, result);

const result = 40893390.77406456;
const response = { result, error, id };
nock(uri)

@@ -1283,3 +1242,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getnetworkhashps(params);

@@ -1296,3 +1255,2 @@ assert.deepStrictEqual(data, result);

const result = true;
const response = { result, error, id };
nock(uri)

@@ -1302,3 +1260,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.prioritisetransaction(params);

@@ -1312,3 +1270,2 @@ assert.deepStrictEqual(data, result);

const result = "duplicate";
const response = { result, error, id };
nock(uri)

@@ -1318,3 +1275,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.submitblock(params);

@@ -1328,3 +1285,2 @@ assert.deepStrictEqual(data, result);

const result = null;
const response = { result, error, id };
nock(uri)

@@ -1334,3 +1290,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.submitheader(params);

@@ -1341,2 +1297,378 @@ assert.deepStrictEqual(data, result);

suite("Network", () => {
test(".addnode()", async () => {
const command: "onetry" = "onetry";
const params = { node: "192.168.0.6:8333", command };
const request = { params, method: "addnode", id, jsonrpc };
const result = null;
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.addnode(params);
assert.deepStrictEqual(data, result);
});
test(".clearbanned()", async () => {
const request = { params: {}, method: "clearbanned", id, jsonrpc };
const result = null;
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.clearbanned();
assert.deepStrictEqual(data, result);
});
test(".disconnectnode()", async () => {
const params = { address: "92.53.89.123:18333" };
const request = { params, method: "disconnectnode", id, jsonrpc };
const result = null;
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.disconnectnode(params);
assert.deepStrictEqual(data, result);
});
test(".getaddednodeinfo()", async () => {
const params = { node: "92.53.89.123:18333" };
const request = { params, method: "getaddednodeinfo", id, jsonrpc };
const result = [
{
addednode: "92.53.89.123:18333",
connected: true,
addresses: [{ address: "92.53.89.123:18333", connected: "outbound" }]
}
];
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.getaddednodeinfo(params);
assert.deepStrictEqual(data, result);
});
test(".getconnectioncount()", async () => {
const request = { params: {}, method: "getconnectioncount", id, jsonrpc };
const result = 9;
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.getconnectioncount();
assert.deepStrictEqual(data, result);
});
test(".getnettotals()", async () => {
const request = { params: {}, method: "getnettotals", id, jsonrpc };
const result = {
totalbytesrecv: 54576627,
totalbytessent: 1420766,
timemillis: 1571931082122,
uploadtarget: {
timeframe: 86400,
target: 0,
target_reached: false,
serve_historical_blocks: true,
bytes_left_in_cycle: 0,
time_left_in_cycle: 0
}
};
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.getnettotals();
assert.deepStrictEqual(data, result);
});
test(".getnetworkinfo()", async () => {
const request = { params: {}, method: "getnetworkinfo", id, jsonrpc };
const result = {
version: 180100,
subversion: "/Satoshi:0.18.1/",
protocolversion: 70015,
localservices: "000000000000040c",
localrelay: true,
timeoffset: -2,
networkactive: true,
connections: 9,
networks: [
{
name: "ipv4",
limited: false,
reachable: true,
proxy: "",
proxy_randomize_credentials: false
},
{
name: "ipv6",
limited: false,
reachable: true,
proxy: "",
proxy_randomize_credentials: false
},
{
name: "onion",
limited: true,
reachable: false,
proxy: "",
proxy_randomize_credentials: false
}
],
relayfee: 0.00001,
incrementalfee: 0.00001,
localaddresses: [],
warnings: "Warning: unknown new rules activated (versionbit 28)"
};
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.getnetworkinfo();
assert.deepStrictEqual(data, result);
});
test(".getnodeaddresses()", async () => {
const params = { count: 2 };
const request = { params, method: "getnodeaddresses", id, jsonrpc };
const result = [
{
time: 1569474479,
services: 1036,
address: "188.162.132.87",
port: 18333
},
{
time: 1569557642,
services: 1037,
address: "174.138.24.48",
port: 18333
}
];
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.getnodeaddresses(params);
assert.deepStrictEqual(data, result);
});
test(".getpeerinfo()", async () => {
const request = { params: {}, method: "getpeerinfo", id, jsonrpc };
const result = [
{
id: 3,
addr: "89.163.139.151:18333",
addrlocal: "178.252.127.208:56815",
addrbind: "192.168.1.110:56815",
services: "000000000000040d",
relaytxes: true,
lastsend: 1571931713,
lastrecv: 1571931697,
bytessent: 98502,
bytesrecv: 395446,
conntime: 1571920343,
timeoffset: -3,
pingtime: 0.042976,
minping: 0.042912,
version: 70015,
subver: "/Satoshi:0.17.0/",
inbound: false,
addnode: false,
startingheight: 1583882,
banscore: 0,
synced_headers: 1583893,
synced_blocks: 1583893,
inflight: [],
whitelisted: false,
minfeefilter: 0.00001,
bytessent_per_msg: {
addr: 275,
feefilter: 32,
getaddr: 24,
getdata: 25990,
getheaders: 1085,
headers: 106,
inv: 60540,
ping: 3072,
pong: 3040,
sendcmpct: 99,
sendheaders: 24,
tx: 4065,
verack: 24,
version: 126
},
bytesrecv_per_msg: {
addr: 30192,
cmpctblock: 16205,
feefilter: 32,
getdata: 549,
getheaders: 1085,
headers: 212,
inv: 53955,
ping: 3040,
pong: 3072,
reject: 77,
sendcmpct: 66,
sendheaders: 24,
tx: 286787,
verack: 24,
version: 126
}
},
{
id: 5,
addr: "165.227.30.200:18333",
addrlocal: "178.252.127.208:56817",
addrbind: "192.168.1.110:56817",
services: "000000000000040d",
relaytxes: true,
lastsend: 1571931697,
lastrecv: 1571931711,
bytessent: 103195,
bytesrecv: 238387,
conntime: 1571920344,
timeoffset: -2,
pingtime: 0.174904,
minping: 0.174861,
version: 70015,
subver: "/Satoshi:0.18.0/",
inbound: false,
addnode: false,
startingheight: 1583882,
banscore: 0,
synced_headers: 1583893,
synced_blocks: 1583893,
inflight: [],
whitelisted: false,
minfeefilter: 0.00001,
bytessent_per_msg: {
addr: 55,
feefilter: 32,
getaddr: 24,
getdata: 15268,
getheaders: 1085,
headers: 636,
inv: 69856,
ping: 3072,
pong: 3040,
sendcmpct: 66,
sendheaders: 24,
tx: 9887,
verack: 24,
version: 126
},
bytesrecv_per_msg: {
addr: 30107,
feefilter: 32,
getdata: 1378,
getheaders: 1085,
headers: 1272,
inv: 47253,
ping: 3040,
pong: 3072,
reject: 77,
sendcmpct: 66,
sendheaders: 24,
tx: 150831,
verack: 24,
version: 126
}
}
];
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.getpeerinfo();
assert.deepStrictEqual(data, result);
});
test(".listbanned()", async () => {
const request = { params: {}, method: "listbanned", id, jsonrpc };
const result = [
{
address: "92.53.89.123/32",
banned_until: 1571932132,
ban_created: 1571932032,
ban_reason: "manually added"
}
];
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.listbanned();
assert.deepStrictEqual(data, result);
});
test(".ping()", async () => {
const request = { params: {}, method: "ping", id, jsonrpc };
const result = null;
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.ping();
assert.deepStrictEqual(data, result);
});
test(".setban()", async () => {
const subnet = "92.53.89.123";
const command: "add" = "add";
const bantime = 1581599503;
const absolute = true;
const params = { subnet, command, bantime, absolute };
const request = { params, method: "setban", id, jsonrpc };
const result = [
{
time: 1569474479,
services: 1036,
address: "188.162.132.87",
port: 18333
},
{
time: 1569557642,
services: 1037,
address: "174.138.24.48",
port: 18333
}
];
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.setban(params);
assert.deepStrictEqual(data, result);
});
test(".setnetworkactive()", async () => {
const params = { state: true };
const request = { params, method: "setnetworkactive", id, jsonrpc };
const result = true;
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, { result, error, id });
const data = await client.setnetworkactive(params);
assert.deepStrictEqual(data, result);
});
});
suite("Zmq", () => {

@@ -1360,3 +1692,2 @@ test(".getzmqnotifications()", async () => {

];
const response = { result, error, id };
nock(uri)

@@ -1366,3 +1697,3 @@ .post("/", request)

.basicAuth(auth)
.reply(200, response);
.reply(200, { result, error, id });
const data = await client.getzmqnotifications();

@@ -1369,0 +1700,0 @@ assert.deepStrictEqual(data, result);