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

rpc-bitcoin

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.4.0

{
"name": "rpc-bitcoin",
"version": "1.3.0",
"version": "1.4.0",
"description": "A TypeScript library to make RPC and HTTP REST requests to Bitcoin Core",

@@ -40,3 +40,3 @@ "main": "build/index.js",

"mocha": "^6.2.2",
"nock": "^11.5.0",
"nock": "^11.6.0",
"prettier": "^1.18.2",

@@ -43,0 +43,0 @@ "ts-node": "^8.4.1",

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

"000000004182034f427d463b92162d35d0accef9ea0c5354a87e870ca1815b4c";
const data = await client.getchaintxstats({ nblocks, blockhash });
const result = await client.getchaintxstats({ nblocks, blockhash });
```

@@ -114,3 +114,3 @@

const txid = "3e128c38f35520d4121d582f15998b7f74b44f17aa650b4d60decf975e642b9a";
const data = await client.getmempoolancestors({ txid, verbose });
const result = await client.getmempoolancestors({ txid, verbose });
```

@@ -123,3 +123,3 @@

const txid = "ff758ffd73729be8afae0d683547f7840bdaee75ad5e5c464fb621b2509c366b";
const data = await client.getmempooldescendants({ txid, verbose });
const result = await client.getmempooldescendants({ txid, verbose });
```

@@ -131,3 +131,3 @@

const txid = "0629e01f05088728b089715f247de82a160428c06d6c85484adab2aa66574ace";
const data = await client.getmempoolentry({ txid });
const result = await client.getmempoolentry({ txid });
```

@@ -145,3 +145,3 @@

const verbose = true;
const data = await client.getrawmempool({ verbose });
const result = await client.getrawmempool({ verbose });
```

@@ -155,3 +155,3 @@

const include_mempool = true;
const data = await client.gettxout({ txid, n, include_mempool });
const result = await client.gettxout({ txid, n, include_mempool });
```

@@ -167,3 +167,3 @@

"000000000000000000055bc30b762904ab996430603cafe846cc6adc82c4af1e";
const data = await client.gettxoutproof({ txids, blockhash });
const result = await client.gettxoutproof({ txids, blockhash });
```

@@ -182,3 +182,3 @@

"00000000000000261a35cf378bf8fa1bf6ac87800d798ce2a11f581f562e92ba";
const data = await client.preciousblock({ blockhash });
const result = await client.preciousblock({ blockhash });
```

@@ -230,2 +230,44 @@

### Control
- [`getmemoryinfo`](https://bitcoin.org/en/developer-reference#getmemoryinfo)
```javascript
const mode = "mallocinfo";
const result = await client.getmemoryinfo({ mode });
```
- [`getrpcinfo`](https://bitcoin.org/en/developer-reference#getrpcinfo)
```javascript
const result = await client.getrpcinfo();
```
- [`help`](https://bitcoin.org/en/developer-reference#help)
```javascript
const command = "getzmqnotifications";
const result = await client.help({ command });
```
- [`logging`](https://bitcoin.org/en/developer-reference#logging)
```javascript
const include = ["net", "rpc"];
const exclude = ["mempoolrej", "estimatefee"];
const result = await client.logging({ include, exclude });
```
- [`stop`](https://bitcoin.org/en/developer-reference#stop)
```javascript
const result = await client.stop();
```
- [`uptime`](https://bitcoin.org/en/developer-reference#uptime)
```javascript
const result = await client.uptime();
```
### ZMQ

@@ -232,0 +274,0 @@

@@ -62,2 +62,11 @@ import { RESTClient, RESTIniOptions } from "./rest";

export type HelpParams = {
command?: string;
};
export type LoggingParams = {
include?: string[] | "all" | "none" | 0 | 1;
exclude?: string[] | "all" | "none" | 0 | 1;
};
export class RPCClient extends RESTClient {

@@ -261,2 +270,44 @@ wallet?: string;

/**
* @description Returns an object containing information about memory usage.
*/
async getmemoryinfo({ mode = "stats" } = {}) {
return this.rpc("getmemoryinfo", { mode });
}
/**
* @description Returns details of the RPC server.
*/
async getrpcinfo() {
return this.rpc("getrpcinfo");
}
/**
* @description List all commands, or get help for a specified command.
*/
async help({ command }: HelpParams = {}) {
return this.rpc("help", { command });
}
/**
* @description Gets and sets the logging configuration.
*/
async logging({ include, exclude }: LoggingParams = {}) {
return this.rpc("logging", { include, exclude });
}
/**
* @description Stop Bitcoin server.
*/
async stop() {
return this.rpc("stop");
}
/**
* @description Returns the total uptime of the server.
*/
async uptime() {
return this.rpc("uptime");
}
/**
* @description Returns information about the active ZeroMQ notifications.

@@ -263,0 +314,0 @@ */

@@ -894,2 +894,121 @@ import {

suite("Control", () => {
test(".getmemoryinfo()", async () => {
const params = { mode: "stats" };
const request = { params, method: "getmemoryinfo", id, jsonrpc };
const result = {
locked: {
used: 194112,
free: 68032,
total: 262144,
locked: 0,
chunks_used: 6065,
chunks_free: 3
}
};
const response = { result, error, id };
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, response);
const data = await client.getmemoryinfo(params);
assert.deepStrictEqual(data, result);
});
test(".getrpcinfo()", async () => {
const request = { params: {}, method: "getrpcinfo", id, jsonrpc };
const result = {
active_commands: [{ method: "getrpcinfo", duration: 0 }]
};
const response = { result, error, id };
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, response);
const data = await client.getrpcinfo();
assert.deepStrictEqual(data, result);
});
test(".help()", async () => {
const params = { command: "getzmqnotifications" };
const request = { params, method: "help", id, jsonrpc };
const 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)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, response);
const data = await client.help(params);
assert.deepStrictEqual(data, result);
});
test(".logging()", async () => {
const include = ["net", "rpc"];
const exclude = ["mempoolrej", "estimatefee"];
const params = { include, exclude };
const request = { params, method: "logging", id, jsonrpc };
const result = {
net: true,
tor: false,
mempool: false,
http: false,
bench: false,
zmq: false,
db: false,
rpc: true,
estimatefee: false,
addrman: false,
selectcoins: false,
reindex: false,
cmpctblock: false,
rand: false,
prune: false,
proxy: false,
mempoolrej: false,
libevent: false,
coindb: false,
qt: false,
leveldb: false
};
const response = { result, error, id };
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, response);
const data = await client.logging(params);
assert.deepStrictEqual(data, result);
});
test(".stop()", async () => {
const request = { params: {}, method: "stop", id, jsonrpc };
const result = "Bitcoin server stopping";
const response = { result, error, id };
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, response);
const data = await client.stop();
assert.deepStrictEqual(data, result);
});
test(".uptime()", async () => {
const request = { params: {}, method: "uptime", id, jsonrpc };
const result = 31;
const response = { result, error, id };
nock(uri)
.post("/", request)
.times(1)
.basicAuth(auth)
.reply(200, response);
const data = await client.uptime();
assert.deepStrictEqual(data, result);
});
});
suite("Zmq", () => {

@@ -896,0 +1015,0 @@ test(".getzmqnotifications()", async () => {