@mr-zwets/bchn-api-wrapper 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +8 -0
- package/.github/workflows/ci.yaml +36 -0
- package/CLAUDE.md +70 -0
- package/README.md +121 -129
- package/dist/interfaces/interfaces.d.ts +13 -0
- package/dist/interfaces/restInterfaces/interfaces.d.ts +124 -18
- package/dist/interfaces/rpcInterfaces/blockchain.d.ts +293 -102
- package/dist/interfaces/rpcInterfaces/control.d.ts +6 -0
- package/dist/interfaces/rpcInterfaces/generating.d.ts +2 -0
- package/dist/interfaces/rpcInterfaces/mining.d.ts +9 -0
- package/dist/interfaces/rpcInterfaces/network.d.ts +18 -0
- package/dist/interfaces/rpcInterfaces/rawtransactions.d.ts +21 -0
- package/dist/interfaces/rpcInterfaces/util.d.ts +5 -0
- package/dist/interfaces/rpcInterfaces/wallet.d.ts +54 -0
- package/dist/interfaces/rpcInterfaces/zmq.d.ts +1 -0
- package/dist/restClient.d.ts +13 -1
- package/dist/restClient.js +19 -6
- package/dist/rpcClient.d.ts +7 -0
- package/dist/rpcClient.js +7 -0
- package/package.json +7 -8
- package/pnpm-lock.yaml +1279 -0
- package/src/index.ts +3 -3
- package/src/interfaces/interfaces.ts +96 -86
- package/src/interfaces/restInterfaces/interfaces.ts +235 -116
- package/src/interfaces/rpcInterfaces/blockchain.ts +932 -758
- package/src/interfaces/rpcInterfaces/control.ts +68 -62
- package/src/interfaces/rpcInterfaces/generating.ts +23 -21
- package/src/interfaces/rpcInterfaces/index.ts +13 -13
- package/src/interfaces/rpcInterfaces/mining.ts +151 -143
- package/src/interfaces/rpcInterfaces/network.ts +213 -195
- package/src/interfaces/rpcInterfaces/rawtransactions.ts +332 -314
- package/src/interfaces/rpcInterfaces/util.ts +56 -52
- package/src/interfaces/rpcInterfaces/wallet.ts +728 -674
- package/src/interfaces/rpcInterfaces/zmq.ts +12 -11
- package/src/restClient.ts +134 -119
- package/src/rpcClient.ts +100 -93
- package/src/utils/errors.ts +6 -6
- package/src/utils/utils.ts +55 -55
- package/test/restClient.test.ts +33 -31
- package/test/rpcClient.test.ts +119 -115
- package/test/setupTests.ts +56 -54
- package/test/tsconfig.json +4 -4
- package/tsconfig.json +13 -13
- package/vitest.config.ts +8 -8
- package/CHANGELOG.md +0 -7
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
check:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up pnpm
|
|
21
|
+
uses: pnpm/action-setup@v4
|
|
22
|
+
|
|
23
|
+
- name: Set up Node.js
|
|
24
|
+
uses: actions/setup-node@v4
|
|
25
|
+
with:
|
|
26
|
+
node-version: 22
|
|
27
|
+
cache: pnpm
|
|
28
|
+
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: pnpm install
|
|
31
|
+
|
|
32
|
+
- name: Build
|
|
33
|
+
run: pnpm build
|
|
34
|
+
|
|
35
|
+
- name: Run tests
|
|
36
|
+
run: pnpm test run
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Build & Test Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm build # Compile TypeScript to dist/
|
|
9
|
+
pnpm test # Run all tests with Vitest
|
|
10
|
+
pnpm test <file> # Run a specific test file
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
TypeScript library providing type-safe wrappers for Bitcoin Cash Node (BCHN) JSON-RPC and REST interfaces. Types compatible with **BCHN v29.0.0**. Zero runtime dependencies.
|
|
16
|
+
|
|
17
|
+
### Two Client Classes
|
|
18
|
+
|
|
19
|
+
**BchnRestClient** (`src/restClient.ts`)
|
|
20
|
+
- Wraps 11 REST endpoints for read-only blockchain access-
|
|
21
|
+
- Class with dedicated methods for each endpoint
|
|
22
|
+
- Supports format options (`json`, `hex`, `bin`) via conditional return types
|
|
23
|
+
- Uses function overloads for type-safe returns based on parameters (e.g., `getBlock` with `includeTxDetails`)
|
|
24
|
+
|
|
25
|
+
**BchnRpcClient** (`src/rpcClient.ts`)
|
|
26
|
+
- Wraps 136 RPC commands for full node interaction
|
|
27
|
+
- Single generic `request<T extends RpcRequest>()` method
|
|
28
|
+
- Type safety achieved through discriminated union interfaces
|
|
29
|
+
- Each RPC command interface defines: `method`, `params[]`, and `response` type
|
|
30
|
+
|
|
31
|
+
### Interface Organization
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
src/interfaces/
|
|
35
|
+
├── interfaces.ts # Config types, RpcRequest base, shared types
|
|
36
|
+
├── restInterfaces/ # REST response types
|
|
37
|
+
└── rpcInterfaces/ # 136 RPC command interfaces across 9 files
|
|
38
|
+
├── blockchain.ts # 33 commands
|
|
39
|
+
├── wallet.ts # 52 commands
|
|
40
|
+
├── rawtransactions.ts
|
|
41
|
+
├── network.ts # 14 commands
|
|
42
|
+
├── mining.ts
|
|
43
|
+
├── control.ts # 6 commands
|
|
44
|
+
├── util.ts
|
|
45
|
+
├── generating.ts
|
|
46
|
+
└── zmq.ts
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### RPC Type Pattern
|
|
50
|
+
|
|
51
|
+
RPC interfaces follow this pattern for full type inference:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
export interface GetBlockVerbosity1 extends GetBlockBase {
|
|
55
|
+
params: [blockhash: string, verbosity?: 1 | true];
|
|
56
|
+
response: { hash: string; /* ... */ };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Usage - params and response are fully typed:
|
|
60
|
+
const result = await rpcClient.request<GetBlockVerbosity1>("getblock", hash, 1);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Configuration Types
|
|
64
|
+
|
|
65
|
+
- `RpcClientConfig`: Supports URL-based (`{url, rpcUser, rpcPassword}`) or host-based (`{protocol, host, port, rpcUser, rpcPassword}`) configuration
|
|
66
|
+
- `RestClientConfig`: Requires `url`, optional `logger` and `timeoutMs`
|
|
67
|
+
|
|
68
|
+
### Testing
|
|
69
|
+
|
|
70
|
+
Tests use Vitest with MSW (Mock Service Worker) for HTTP interception. Mock server setup is in `test/setupTests.ts`.
|
package/README.md
CHANGED
|
@@ -1,129 +1,121 @@
|
|
|
1
|
-
# BCHN-API-Wrapper
|
|
2
|
-
|
|
3
|
-
This library is a Typescript wrapper for interacting with the Bitcoin Cash Node (BCHN) RPC and REST interfaces.
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
The library
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
The
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
The
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
The `
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
The `
|
|
89
|
-
|
|
90
|
-
The
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
npm run test
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
or using yarn:
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
yarn test
|
|
129
|
-
```
|
|
1
|
+
# BCHN-API-Wrapper
|
|
2
|
+
|
|
3
|
+
This library is a Typescript wrapper for interacting with the Bitcoin Cash Node (BCHN) RPC and REST interfaces.
|
|
4
|
+
|
|
5
|
+
## Compatibility
|
|
6
|
+
|
|
7
|
+
RPC and REST interface types compatible with **BCHN v29.0.0**.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
The library is a simple wrapper for using the BCHN REST and RPC-endpoints in a type-safe way.
|
|
12
|
+
|
|
13
|
+
The library is designed to be easy to use and get started with.
|
|
14
|
+
|
|
15
|
+
The library has good documentation, automated tests and zero dependencies.
|
|
16
|
+
|
|
17
|
+
## Details
|
|
18
|
+
|
|
19
|
+
The `BchnRestClient` uses a class with unique methods for each of the endpoints.
|
|
20
|
+
|
|
21
|
+
The `BchnRpcClient` uses a request function which uses generics to type arguments and responses.
|
|
22
|
+
|
|
23
|
+
The **REST API** is ideal for **read-only** access to general blockchain information such as transactions, blocks, and UTXO data. In contrast, the **RPC API** allows for **full interaction** with the Bitcoin Cash node, including managing the built-in wallet, sending transactions, performing mining operations, and issuing control commands like pruning or stopping the node. While the REST API provides 11 endpoints, the RPC API offers a much broader set of 136 commands.
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
To use the RPC and REST APIs on your BCHN node, you need to enable them in your node's configuration file.
|
|
28
|
+
|
|
29
|
+
<details>
|
|
30
|
+
<summary>BCHN Configuration</summary>
|
|
31
|
+
In the BCHN '.conf' file add the following settings:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
server=1
|
|
35
|
+
rest=1
|
|
36
|
+
txindex=1
|
|
37
|
+
rpcuser=rpcuser
|
|
38
|
+
rpcpassword=rpcpassword
|
|
39
|
+
rpcallowip=127.0.0.1
|
|
40
|
+
rpcport=8332
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To learn more about the `.conf` settings, see the [BCHN documentation](https://docs.bitcoincashnode.org/doc/bitcoin-conf/).
|
|
44
|
+
</details>
|
|
45
|
+
|
|
46
|
+
Note that the REST-endpoints can be made public, but the RPC-endpoints should never be made public. If you want to use the RPC-endpoints of your own node remotely, you need a secure connection using SSL/TLS to encrypt your communication and protect your credentials and data from being exposed. Additionally, ensure you have strong, unique RPC credentials (username and password) set in your node's configuration file.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
Install the BCHN-API-Wrapper from NPM with:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm install @mr-zwets/bchn-api-wrapper
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## REST usage
|
|
57
|
+
|
|
58
|
+
The `BchnRestClient` is a wrapper over the 11 BCHN REST-endpoints. For the list of the BCHN REST-endpoints see the [REST documentation](https://docs.bitcoincashnode.org/doc/REST-interface/).
|
|
59
|
+
|
|
60
|
+
The `RestClientConfig` object accepts optional parameters for `logger` & `timeoutMs`
|
|
61
|
+
|
|
62
|
+
### REST example
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { BchnRestClient, RestClientConfig } from 'bchn-api-wrapper'
|
|
66
|
+
|
|
67
|
+
// Create the RestClientConfig
|
|
68
|
+
const clientOptions: RestClientConfig = {
|
|
69
|
+
url: "http://localhost:8332",
|
|
70
|
+
}
|
|
71
|
+
// Instantiate the REST client to query your BCHN node
|
|
72
|
+
const restClient = new BchnRestClient(clientOptions)
|
|
73
|
+
|
|
74
|
+
// Get the latest blockhash
|
|
75
|
+
const chainInfo = await restClient.getChainInfo()
|
|
76
|
+
const latestBlockHash = chainInfo.bestblockhash
|
|
77
|
+
console.log(`The latest blockhash is ${latestBlockHash}`)
|
|
78
|
+
|
|
79
|
+
// Get block info with includeTxDetails flag
|
|
80
|
+
const fullBlockInfo = await restClient.getBlock(latestBlockHash, true)
|
|
81
|
+
console.log(JSON.stringify(fullBlockInfo))
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## RPC usage
|
|
85
|
+
|
|
86
|
+
The `BchnRpcClient` is a thin type-wrapper over the actual RPC endpoints, with request interfaces for each endpoint. For a complete list of all BCHN RPC-endpoints see the [RPC documentation](https://docs.bitcoincashnode.org/doc/json-rpc/).
|
|
87
|
+
|
|
88
|
+
The `RpcClientConfig` object accepts optional parameters for `logger`, `timeoutMs`, `retryDelayMs` & `maxRetries`
|
|
89
|
+
|
|
90
|
+
The library does not currently support making batched RPC requests.
|
|
91
|
+
|
|
92
|
+
### RPC example
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { BchnRpcClient, RpcClientConfig, GetBestBlockHash, GetBlockVerbosity1 } from 'bchn-api-wrapper'
|
|
96
|
+
|
|
97
|
+
// Create the RpcClientConfig
|
|
98
|
+
const clientOptions: RpcClientConfig = {
|
|
99
|
+
url: "http://localhost:8332",
|
|
100
|
+
rpcUser: "rpcUser",
|
|
101
|
+
rpcPassword: "rpcPassword"
|
|
102
|
+
}
|
|
103
|
+
// Instantiate the RPC client to query your BCHN node
|
|
104
|
+
const rpcClient = new BchnRpcClient(clientOptions)
|
|
105
|
+
|
|
106
|
+
// Get the latest blockhash
|
|
107
|
+
const latestBlockHash = await rpcClient.request<GetBestBlockHash>("getbestblockhash")
|
|
108
|
+
console.log(`The latest blockhash is ${latestBlockHash}`)
|
|
109
|
+
|
|
110
|
+
// Get verbosity1 info about the latest block contents
|
|
111
|
+
const fullBlockInfo = await rpcClient.request<GetBlockVerbosity1>("getblock", latestBlockHash, 1)
|
|
112
|
+
console.log(JSON.stringify(fullBlockInfo))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Run Tests
|
|
116
|
+
|
|
117
|
+
The library has automated tests using vitest, run the testing suite with:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pnpm run test
|
|
121
|
+
```
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Base RPC client authentication and connection settings. */
|
|
1
2
|
export interface BaseRpcClientConfig {
|
|
2
3
|
rpcUser: string;
|
|
3
4
|
rpcPassword: string;
|
|
@@ -6,29 +7,38 @@ export interface BaseRpcClientConfig {
|
|
|
6
7
|
logger?: typeof console;
|
|
7
8
|
timeoutMs?: number;
|
|
8
9
|
}
|
|
10
|
+
/** RPC client config using a full URL (e.g., "http://localhost:8332"). */
|
|
9
11
|
export interface RpcClientUrlConfig extends BaseRpcClientConfig {
|
|
10
12
|
url: string;
|
|
11
13
|
}
|
|
14
|
+
/** RPC client config using separate host, port, and protocol. */
|
|
12
15
|
export interface RpcClientHostConfig extends BaseRpcClientConfig {
|
|
13
16
|
protocol: 'http' | 'https';
|
|
14
17
|
host: string;
|
|
15
18
|
port: number;
|
|
16
19
|
}
|
|
20
|
+
/** RPC client configuration - either URL-based or host-based. */
|
|
17
21
|
export type RpcClientConfig = RpcClientUrlConfig | RpcClientHostConfig;
|
|
22
|
+
/** Valid parameter types for RPC method calls. */
|
|
18
23
|
export type RPCParameter = string | number | boolean | undefined | object;
|
|
19
24
|
declare type RequestResponse = object | string | number | boolean | null | RequestResponse[];
|
|
25
|
+
/** Base interface for all RPC request types with method, params, and response. */
|
|
20
26
|
export interface RpcRequest {
|
|
21
27
|
method: string;
|
|
22
28
|
params: Array<RPCParameter>;
|
|
23
29
|
response: RequestResponse;
|
|
24
30
|
}
|
|
31
|
+
/** REST client configuration. */
|
|
25
32
|
export interface RestClientConfig {
|
|
26
33
|
url: string;
|
|
27
34
|
logger?: typeof console;
|
|
28
35
|
timeoutMs?: number;
|
|
29
36
|
}
|
|
37
|
+
/** REST endpoint response format options. */
|
|
30
38
|
export type formatOptions = 'bin' | 'hex' | 'json';
|
|
39
|
+
/** Conditional return type based on format: JSON returns parsed object, hex/bin return string. */
|
|
31
40
|
export type ResponseType<TFormat extends formatOptions, TJson> = TFormat extends 'json' ? TJson : TFormat extends 'hex' | 'bin' ? string : never;
|
|
41
|
+
/** Base transaction structure used in both REST and RPC responses. */
|
|
32
42
|
export interface Transaction {
|
|
33
43
|
txid: string;
|
|
34
44
|
hash: string;
|
|
@@ -38,6 +48,7 @@ export interface Transaction {
|
|
|
38
48
|
vin: TransactionInput[];
|
|
39
49
|
vout: TransactionOutput[];
|
|
40
50
|
}
|
|
51
|
+
/** Transaction input referencing a previous output (UTXO). */
|
|
41
52
|
export interface TransactionInput {
|
|
42
53
|
txid: string;
|
|
43
54
|
vout: number;
|
|
@@ -47,6 +58,7 @@ export interface TransactionInput {
|
|
|
47
58
|
};
|
|
48
59
|
sequence: number;
|
|
49
60
|
}
|
|
61
|
+
/** Transaction output with value and locking script. */
|
|
50
62
|
export interface TransactionOutput {
|
|
51
63
|
value: number;
|
|
52
64
|
n: number;
|
|
@@ -59,6 +71,7 @@ export interface TransactionOutput {
|
|
|
59
71
|
tokenData: TokenData;
|
|
60
72
|
};
|
|
61
73
|
}
|
|
74
|
+
/** CashTokens data attached to a UTXO (fungible amount and/or NFT). */
|
|
62
75
|
export interface TokenData {
|
|
63
76
|
category: string;
|
|
64
77
|
amount: string;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { Transaction } from "../interfaces.js";
|
|
2
|
-
|
|
2
|
+
/** Adaptive Block Limit Algorithm state (activated May 2024). */
|
|
3
|
+
export interface AblaState {
|
|
4
|
+
epsilon: number;
|
|
5
|
+
beta: number;
|
|
6
|
+
blocksize: number;
|
|
7
|
+
blocksizelimit: number;
|
|
8
|
+
nextblocksizelimit: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base block info fields shared across response types.
|
|
12
|
+
* @note `previousblockhash` not present on genesis block (height 0).
|
|
13
|
+
* @note `nextblockhash` not present on chain tip.
|
|
14
|
+
*/
|
|
15
|
+
interface BlockInfoBase {
|
|
3
16
|
hash: string;
|
|
4
17
|
confirmations: number;
|
|
5
18
|
size: number;
|
|
@@ -7,7 +20,6 @@ export interface BlockInfoNoTxDetails {
|
|
|
7
20
|
version: number;
|
|
8
21
|
versionHex: string;
|
|
9
22
|
merkleroot: string;
|
|
10
|
-
tx: string[];
|
|
11
23
|
time: number;
|
|
12
24
|
mediantime: number;
|
|
13
25
|
nonce: number;
|
|
@@ -17,18 +29,41 @@ export interface BlockInfoNoTxDetails {
|
|
|
17
29
|
nTx: number;
|
|
18
30
|
previousblockhash: string;
|
|
19
31
|
nextblockhash: string;
|
|
20
|
-
ablastate: {
|
|
21
|
-
epsilon: number;
|
|
22
|
-
beta: number;
|
|
23
|
-
blocksize: number;
|
|
24
|
-
blocksizelimit: number;
|
|
25
|
-
nextblocksizelimit: number;
|
|
26
|
-
};
|
|
27
32
|
}
|
|
28
|
-
|
|
33
|
+
/** Block info with tx IDs only - works for any block. */
|
|
34
|
+
export interface BlockInfoNoTxDetails extends BlockInfoBase {
|
|
35
|
+
tx: string[];
|
|
36
|
+
ablastate?: AblaState;
|
|
37
|
+
}
|
|
38
|
+
/** Block info with tx IDs only - for blocks before ABLA activation (May 2024). */
|
|
39
|
+
export interface BlockInfoNoTxDetailsPreAbla extends BlockInfoBase {
|
|
40
|
+
tx: string[];
|
|
41
|
+
}
|
|
42
|
+
/** Block info with tx IDs only - for blocks after ABLA activation (May 2024). */
|
|
43
|
+
export interface BlockInfoNoTxDetailsPostAbla extends BlockInfoBase {
|
|
44
|
+
tx: string[];
|
|
45
|
+
ablastate: AblaState;
|
|
46
|
+
}
|
|
47
|
+
/** Block info with full transaction objects - works for any block. */
|
|
48
|
+
export interface BlockInfoTxDetails extends BlockInfoBase {
|
|
49
|
+
tx: Transaction[];
|
|
50
|
+
ablastate?: AblaState;
|
|
51
|
+
}
|
|
52
|
+
/** Block info with full transaction objects - for blocks before ABLA activation (May 2024). */
|
|
53
|
+
export interface BlockInfoTxDetailsPreAbla extends BlockInfoBase {
|
|
54
|
+
tx: Transaction[];
|
|
55
|
+
}
|
|
56
|
+
/** Block info with full transaction objects - for blocks after ABLA activation (May 2024). */
|
|
57
|
+
export interface BlockInfoTxDetailsPostAbla extends BlockInfoBase {
|
|
29
58
|
tx: Transaction[];
|
|
59
|
+
ablastate: AblaState;
|
|
30
60
|
}
|
|
31
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Base header info fields shared across response types.
|
|
63
|
+
* @note `previousblockhash` not present on genesis block (height 0).
|
|
64
|
+
* @note `nextblockhash` not present on chain tip.
|
|
65
|
+
*/
|
|
66
|
+
interface HeaderInfoBase {
|
|
32
67
|
hash: string;
|
|
33
68
|
confirmations: number;
|
|
34
69
|
height: number;
|
|
@@ -44,14 +79,19 @@ export interface HeaderInfo {
|
|
|
44
79
|
nTx: number;
|
|
45
80
|
previousblockhash: string;
|
|
46
81
|
nextblockhash: string;
|
|
47
|
-
ablastate: {
|
|
48
|
-
epsilon: number;
|
|
49
|
-
beta: number;
|
|
50
|
-
blocksize: number;
|
|
51
|
-
blocksizelimit: number;
|
|
52
|
-
nextblocksizelimit: number;
|
|
53
|
-
};
|
|
54
82
|
}
|
|
83
|
+
/** Block header info - works for any block. */
|
|
84
|
+
export interface HeaderInfo extends HeaderInfoBase {
|
|
85
|
+
ablastate?: AblaState;
|
|
86
|
+
}
|
|
87
|
+
/** Block header info - for blocks before ABLA activation (May 2024). */
|
|
88
|
+
export interface HeaderInfoPreAbla extends HeaderInfoBase {
|
|
89
|
+
}
|
|
90
|
+
/** Block header info - for blocks after ABLA activation (May 2024). */
|
|
91
|
+
export interface HeaderInfoPostAbla extends HeaderInfoBase {
|
|
92
|
+
ablastate: AblaState;
|
|
93
|
+
}
|
|
94
|
+
/** Current blockchain state and synchronization status. */
|
|
55
95
|
export interface ChainInfo {
|
|
56
96
|
chain: 'main' | 'test' | 'regtest';
|
|
57
97
|
blocks: number;
|
|
@@ -66,6 +106,7 @@ export interface ChainInfo {
|
|
|
66
106
|
pruned: boolean;
|
|
67
107
|
warnings: string;
|
|
68
108
|
}
|
|
109
|
+
/** UTXO set query result with bitmap for checked outpoints. */
|
|
69
110
|
export interface UtxosInfo {
|
|
70
111
|
chaintipHash: string;
|
|
71
112
|
chainHeight: number;
|
|
@@ -83,6 +124,7 @@ export interface UtxosInfo {
|
|
|
83
124
|
}[];
|
|
84
125
|
bitmap: string;
|
|
85
126
|
}
|
|
127
|
+
/** Mempool configuration and size statistics. */
|
|
86
128
|
export interface MempoolInfo {
|
|
87
129
|
loaded: boolean;
|
|
88
130
|
size: number;
|
|
@@ -91,7 +133,10 @@ export interface MempoolInfo {
|
|
|
91
133
|
maxmempool: number;
|
|
92
134
|
mempoolminfee: number;
|
|
93
135
|
minrelaytxfee: number;
|
|
136
|
+
permitbaremultisig: boolean;
|
|
137
|
+
maxdatacarriersize: number;
|
|
94
138
|
}
|
|
139
|
+
/** Mempool contents indexed by txid with fee and dependency info. */
|
|
95
140
|
export interface MempoolContent {
|
|
96
141
|
[txid: string]: {
|
|
97
142
|
fees: {
|
|
@@ -104,6 +149,67 @@ export interface MempoolContent {
|
|
|
104
149
|
spentby: string[];
|
|
105
150
|
};
|
|
106
151
|
}
|
|
152
|
+
/** Transaction with block hash (for confirmed transactions). */
|
|
107
153
|
export interface TxDetails extends Transaction {
|
|
108
154
|
blockhash: string;
|
|
109
155
|
}
|
|
156
|
+
/** Script fingerprint and pattern info for bytecode analysis (v29.0.0+). */
|
|
157
|
+
export interface ByteCodePattern {
|
|
158
|
+
fingerprint: string;
|
|
159
|
+
pattern: string;
|
|
160
|
+
patternArgsInfo?: string[];
|
|
161
|
+
}
|
|
162
|
+
/** Script with optional bytecode pattern metadata (v29.0.0+). */
|
|
163
|
+
export interface ScriptPubKeyWithPattern {
|
|
164
|
+
asm: string;
|
|
165
|
+
hex: string;
|
|
166
|
+
type: string;
|
|
167
|
+
address?: string;
|
|
168
|
+
byteCodePattern?: ByteCodePattern;
|
|
169
|
+
}
|
|
170
|
+
/** Transaction input with prevout and pattern info (v29.0.0+). */
|
|
171
|
+
export interface TransactionInputWithPattern {
|
|
172
|
+
txid: string;
|
|
173
|
+
vout: number;
|
|
174
|
+
scriptSig: {
|
|
175
|
+
asm: string;
|
|
176
|
+
hex: string;
|
|
177
|
+
};
|
|
178
|
+
sequence: number;
|
|
179
|
+
prevout?: {
|
|
180
|
+
generated: boolean;
|
|
181
|
+
height: number;
|
|
182
|
+
value: number;
|
|
183
|
+
scriptPubKey: ScriptPubKeyWithPattern;
|
|
184
|
+
};
|
|
185
|
+
redeemScript?: {
|
|
186
|
+
asm: string;
|
|
187
|
+
hex: string;
|
|
188
|
+
type: string;
|
|
189
|
+
byteCodePattern?: ByteCodePattern;
|
|
190
|
+
p2shType?: string;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/** Transaction output with pattern-enabled scriptPubKey (v29.0.0+). */
|
|
194
|
+
export interface TransactionOutputWithPattern {
|
|
195
|
+
value: number;
|
|
196
|
+
n: number;
|
|
197
|
+
scriptPubKey: ScriptPubKeyWithPattern;
|
|
198
|
+
}
|
|
199
|
+
/** Transaction with bytecode patterns and optional fee (v29.0.0+). */
|
|
200
|
+
export interface TxDetailsWithPatterns {
|
|
201
|
+
txid: string;
|
|
202
|
+
hash: string;
|
|
203
|
+
size: number;
|
|
204
|
+
version: number;
|
|
205
|
+
locktime: number;
|
|
206
|
+
vin: TransactionInputWithPattern[];
|
|
207
|
+
vout: TransactionOutputWithPattern[];
|
|
208
|
+
blockhash: string;
|
|
209
|
+
fee?: number;
|
|
210
|
+
}
|
|
211
|
+
/** Block with pattern-enhanced transactions (v29.0.0+). */
|
|
212
|
+
export interface BlockInfoWithPatterns extends Omit<BlockInfoNoTxDetails, 'tx'> {
|
|
213
|
+
tx: TxDetailsWithPatterns[];
|
|
214
|
+
}
|
|
215
|
+
export {};
|