lightning 6.5.0 → 6.7.0
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/CHANGELOG.md +8 -0
- package/README.md +1 -0
- package/grpc/grpc_services.json +3 -0
- package/grpc/protos/chainkit.proto +59 -0
- package/index.js +2 -0
- package/lnd_methods/index.js +2 -0
- package/lnd_methods/invoices/get_invoices.d.ts +2 -1
- package/lnd_methods/macaroon/methods.json +4 -0
- package/lnd_methods/macaroon/subscribe_to_rpc_requests.d.ts +4 -0
- package/lnd_methods/offchain/get_failed_payments.d.ts +4 -1
- package/lnd_methods/offchain/get_payment.d.ts +2 -2
- package/lnd_methods/offchain/get_payments.d.ts +4 -1
- package/lnd_methods/offchain/get_pending_payments.d.ts +4 -1
- package/lnd_methods/onchain/get_block.js +149 -0
- package/lnd_methods/onchain/index.js +2 -0
- package/package.json +4 -4
- package/test/lnd_grpc/test_authenticated_lnd_grpc.js +1 -0
- package/test/lnd_methods/onchain/test_get_block.js +231 -0
- package/typescript/shared.d.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## 6.7.0
|
|
4
|
+
|
|
5
|
+
- `getBlock`: add `height` to allow fetching a raw block at a specified height
|
|
6
|
+
|
|
7
|
+
## 6.6.0
|
|
8
|
+
|
|
9
|
+
- `getBlock`: Add method to get a raw block from the chain
|
|
10
|
+
|
|
3
11
|
## 6.5.0
|
|
4
12
|
|
|
5
13
|
- `getFailedPayments`, `getInvoices`, `getPayments`, `getPendingPayments`: add
|
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ variables set:
|
|
|
139
139
|
specific channel.
|
|
140
140
|
- [getBackups](https://github.com/alexbosworth/ln-service#getbackups): Get recovery details for
|
|
141
141
|
all channels.
|
|
142
|
+
- [getBlock](https://github.com/alexbosworth/ln-service#getblock): Get a block
|
|
142
143
|
- [getChainBalance](https://github.com/alexbosworth/ln-service#getchainbalance): Get the amount
|
|
143
144
|
of on-chain funds.
|
|
144
145
|
- [getChainFeeEstimate](https://github.com/alexbosworth/ln-service#getchainfeeestimate):
|
package/grpc/grpc_services.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"maxReceiveMessageLength": 924288000,
|
|
5
5
|
"packageTypes": {
|
|
6
6
|
"Autopilot": "autopilotrpc",
|
|
7
|
+
"ChainKit": "chainrpc",
|
|
7
8
|
"ChainNotifier": "chainrpc",
|
|
8
9
|
"Invoices": "invoicesrpc",
|
|
9
10
|
"Lightning": "lnrpc",
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
},
|
|
20
21
|
"protoFiles": {
|
|
21
22
|
"Autopilot": "autopilot.proto",
|
|
23
|
+
"ChainKit": "chainkit.proto",
|
|
22
24
|
"ChainNotifier": "chainnotifier.proto",
|
|
23
25
|
"Invoices": "invoices.proto",
|
|
24
26
|
"Lightning": "lightning.proto",
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"protosDir": "../grpc/protos",
|
|
36
38
|
"serviceTypes": {
|
|
37
39
|
"autopilot": "Autopilot",
|
|
40
|
+
"blocks": "ChainKit",
|
|
38
41
|
"chain": "ChainNotifier",
|
|
39
42
|
"default": "Lightning",
|
|
40
43
|
"invoices": "Invoices",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package chainrpc;
|
|
4
|
+
|
|
5
|
+
option go_package = "github.com/lightningnetwork/lnd/lnrpc/chainrpc";
|
|
6
|
+
|
|
7
|
+
// ChainKit is a service that can be used to get information from the
|
|
8
|
+
// chain backend.
|
|
9
|
+
service ChainKit {
|
|
10
|
+
/* lncli: `chain getblock`
|
|
11
|
+
GetBlock returns a block given the corresponding block hash.
|
|
12
|
+
*/
|
|
13
|
+
rpc GetBlock (GetBlockRequest) returns (GetBlockResponse);
|
|
14
|
+
|
|
15
|
+
/* lncli: `chain getbestblock`
|
|
16
|
+
GetBestBlock returns the block hash and current height from the valid
|
|
17
|
+
most-work chain.
|
|
18
|
+
*/
|
|
19
|
+
rpc GetBestBlock (GetBestBlockRequest) returns (GetBestBlockResponse);
|
|
20
|
+
|
|
21
|
+
/* lncli: `chain getblockhash`
|
|
22
|
+
GetBlockHash returns the hash of the block in the best blockchain
|
|
23
|
+
at the given height.
|
|
24
|
+
*/
|
|
25
|
+
rpc GetBlockHash (GetBlockHashRequest) returns (GetBlockHashResponse);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
message GetBlockRequest {
|
|
29
|
+
// The hash of the requested block.
|
|
30
|
+
bytes block_hash = 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// TODO(ffranr): The neutrino GetBlock response includes many
|
|
34
|
+
// additional helpful fields. Consider adding them here also.
|
|
35
|
+
message GetBlockResponse {
|
|
36
|
+
// The raw bytes of the requested block.
|
|
37
|
+
bytes raw_block = 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
message GetBestBlockRequest {
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
message GetBestBlockResponse {
|
|
44
|
+
// The hash of the best block.
|
|
45
|
+
bytes block_hash = 1;
|
|
46
|
+
|
|
47
|
+
// The height of the best block.
|
|
48
|
+
int32 block_height = 2;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
message GetBlockHashRequest {
|
|
52
|
+
// Block height of the target best chain block.
|
|
53
|
+
int64 block_height = 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
message GetBlockHashResponse {
|
|
57
|
+
// The hash of the best block at the specified height.
|
|
58
|
+
bytes block_hash = 1;
|
|
59
|
+
}
|
package/index.js
CHANGED
|
@@ -32,6 +32,7 @@ const {getAccessIds} = require('./lnd_methods');
|
|
|
32
32
|
const {getAutopilot} = require('./lnd_methods');
|
|
33
33
|
const {getBackup} = require('./lnd_methods');
|
|
34
34
|
const {getBackups} = require('./lnd_methods');
|
|
35
|
+
const {getBlock} = require('./lnd_methods');
|
|
35
36
|
const {getChainBalance} = require('./lnd_methods');
|
|
36
37
|
const {getChainFeeEstimate} = require('./lnd_methods');
|
|
37
38
|
const {getChainFeeRate} = require('./lnd_methods');
|
|
@@ -182,6 +183,7 @@ module.exports = {
|
|
|
182
183
|
getAutopilot,
|
|
183
184
|
getBackup,
|
|
184
185
|
getBackups,
|
|
186
|
+
getBlock,
|
|
185
187
|
getChainBalance,
|
|
186
188
|
getChainFeeEstimate,
|
|
187
189
|
getChainFeeRate,
|
package/lnd_methods/index.js
CHANGED
|
@@ -30,6 +30,7 @@ const {getAccessIds} = require('./macaroon');
|
|
|
30
30
|
const {getAutopilot} = require('./info');
|
|
31
31
|
const {getBackup} = require('./offchain');
|
|
32
32
|
const {getBackups} = require('./offchain');
|
|
33
|
+
const {getBlock} = require('./onchain');
|
|
33
34
|
const {getChainBalance} = require('./onchain');
|
|
34
35
|
const {getChainFeeEstimate} = require('./onchain');
|
|
35
36
|
const {getChainFeeRate} = require('./onchain');
|
|
@@ -176,6 +177,7 @@ module.exports = {
|
|
|
176
177
|
getAutopilot,
|
|
177
178
|
getBackup,
|
|
178
179
|
getBackups,
|
|
180
|
+
getBlock,
|
|
179
181
|
getChainBalance,
|
|
180
182
|
getChainFeeEstimate,
|
|
181
183
|
getChainFeeRate,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
@@ -8,7 +9,7 @@ export type GetInvoicesArgs = AuthenticatedLightningArgs<
|
|
|
8
9
|
PaginationArgs & {
|
|
9
10
|
/** Omit Canceled and Settled Invoices Bool */
|
|
10
11
|
is_unconfirmed?: boolean;
|
|
11
|
-
}
|
|
12
|
+
} & DateRangeFilterArgs
|
|
12
13
|
>;
|
|
13
14
|
|
|
14
15
|
export type GetInvoicesResult = {
|
|
@@ -77,6 +77,10 @@ export type SubscribeToRpcRequestsOpenChannelRequestEvent =
|
|
|
77
77
|
partner_public_key: string;
|
|
78
78
|
/** Peer Output CSV Delay Number */
|
|
79
79
|
partner_csv_delay?: number;
|
|
80
|
+
/** Routing Base Fee Millitokens Charged String */
|
|
81
|
+
base_fee_mtokens?: string;
|
|
82
|
+
/** Routing Fee Rate In Millitokens Per Million Number */
|
|
83
|
+
fee_rate?: number;
|
|
80
84
|
}>;
|
|
81
85
|
|
|
82
86
|
/** A pay to route request was intercepted: by default it will be rejected */
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
7
|
-
export type GetFailedPaymentsArgs = AuthenticatedLightningArgs<
|
|
8
|
+
export type GetFailedPaymentsArgs = AuthenticatedLightningArgs<
|
|
9
|
+
PaginationArgs & DateRangeFilterArgs
|
|
10
|
+
>;
|
|
8
11
|
|
|
9
12
|
export type GetFailedPaymentsResult = {
|
|
10
13
|
payments: {
|
|
@@ -91,7 +91,7 @@ export type GetPaymentResult = {
|
|
|
91
91
|
tokens: number;
|
|
92
92
|
/** Total Millitokens Paid On All Paths */
|
|
93
93
|
total_mtokens: string;
|
|
94
|
-
}[]
|
|
94
|
+
}[];
|
|
95
95
|
/** BOLT 11 Payment Request */
|
|
96
96
|
request?: string;
|
|
97
97
|
/** Payment Forwarding Fee Rounded Up Tokens */
|
|
@@ -147,7 +147,7 @@ export type GetPaymentResult = {
|
|
|
147
147
|
tokens: number;
|
|
148
148
|
/** Total Millitokens Pending */
|
|
149
149
|
total_mtokens: string;
|
|
150
|
-
}[]
|
|
150
|
+
}[];
|
|
151
151
|
/** BOLT 11 Payment Request */
|
|
152
152
|
request?: string;
|
|
153
153
|
/** Payment Tokens Rounded Up */
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
7
|
-
export type GetPaymentsArgs = AuthenticatedLightningArgs<
|
|
8
|
+
export type GetPaymentsArgs = AuthenticatedLightningArgs<
|
|
9
|
+
PaginationArgs & DateRangeFilterArgs
|
|
10
|
+
>;
|
|
8
11
|
|
|
9
12
|
export type GetPaymentsResult = {
|
|
10
13
|
payments: {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticatedLightningArgs,
|
|
3
3
|
AuthenticatedLightningMethod,
|
|
4
|
+
DateRangeFilterArgs,
|
|
4
5
|
PaginationArgs,
|
|
5
6
|
} from '../../typescript';
|
|
6
7
|
|
|
7
|
-
export type GetPendingPaymentsArgs = AuthenticatedLightningArgs<
|
|
8
|
+
export type GetPendingPaymentsArgs = AuthenticatedLightningArgs<
|
|
9
|
+
PaginationArgs & DateRangeFilterArgs
|
|
10
|
+
>;
|
|
8
11
|
|
|
9
12
|
export type GetPendingPaymentsResult = {
|
|
10
13
|
payments: {
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const asyncAuto = require('async/auto');
|
|
2
|
+
const {returnResult} = require('asyncjs-util');
|
|
3
|
+
|
|
4
|
+
const {isLnd} = require('./../../lnd_requests');
|
|
5
|
+
|
|
6
|
+
const bufferAsHex = buffer => buffer.toString('hex');
|
|
7
|
+
const errorNotFound = '-5: Block not found';
|
|
8
|
+
const errorUnknownMethod = 'unknown service chainrpc.ChainKit';
|
|
9
|
+
const hexAsReversedBuffer = hex => Buffer.from(hex, 'hex').reverse();
|
|
10
|
+
const {isBuffer} = Buffer;
|
|
11
|
+
const isNumber = n => !isNaN(n);
|
|
12
|
+
const isHash = n => /^[0-9A-F]{64}$/i.test(n);
|
|
13
|
+
const method = 'getBlock';
|
|
14
|
+
const type = 'blocks';
|
|
15
|
+
|
|
16
|
+
/** Get a block in the chain
|
|
17
|
+
|
|
18
|
+
This method requires LND built with `chainkit` build tag
|
|
19
|
+
|
|
20
|
+
Requires `onchain:read` permission
|
|
21
|
+
|
|
22
|
+
This method is not supported on LND 0.15.5 and below
|
|
23
|
+
|
|
24
|
+
{
|
|
25
|
+
[height]: <Block Height Number>
|
|
26
|
+
[id]: <Block Hash Hex String>
|
|
27
|
+
lnd: <Authenticated LND API Object>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@returns via cbk or Promise
|
|
31
|
+
{
|
|
32
|
+
block: <Raw Block Bytes Hex String>
|
|
33
|
+
}
|
|
34
|
+
*/
|
|
35
|
+
module.exports = ({height, id, lnd}, cbk) => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
return asyncAuto({
|
|
38
|
+
// Check arguments
|
|
39
|
+
validate: cbk => {
|
|
40
|
+
if (height !== undefined && !isNumber(height)) {
|
|
41
|
+
return cbk([400, 'ExpectedNumericBlockHeightOfBlockToRetrieve']);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!!id && !isHash(id)) {
|
|
45
|
+
return cbk([400, 'ExpectedIdentifyingBlockHashOfBlockToRetrieve']);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (height !== undefined && !!id) {
|
|
49
|
+
return cbk([400, 'ExpectedEitherHeightOrIdNotBoth']);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!isLnd({lnd, method, type})) {
|
|
53
|
+
return cbk([400, 'ExpectedAuthenticatedLndToRetrieveBlock']);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return cbk();
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// Get the best block in the chain to find the default block hash
|
|
60
|
+
getTip: ['validate', ({}, cbk) => {
|
|
61
|
+
// Exit early when a specific block is requested
|
|
62
|
+
if (height !== undefined || !!id) {
|
|
63
|
+
return cbk();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return lnd[type].getBestBlock({}, (err, res) => {
|
|
67
|
+
if (!!err && err.details === errorUnknownMethod) {
|
|
68
|
+
return cbk([501, 'GetBestBlockMethodNotSupported']);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!!err) {
|
|
72
|
+
return cbk([503, 'UnexpectedErrorGettingBestBlock', {err}]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!res) {
|
|
76
|
+
return cbk([503, 'ExpectedResponseForBestBlockRequest']);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!isBuffer(res.block_hash)) {
|
|
80
|
+
return cbk([503, 'ExpectedChainTipInfoInGetBestBlockResponse']);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return cbk(null, res.block_hash);
|
|
84
|
+
});
|
|
85
|
+
}],
|
|
86
|
+
|
|
87
|
+
// Get the hash of the block to fetch
|
|
88
|
+
getHash: ['getTip', ({getTip}, cbk) => {
|
|
89
|
+
// Exit early when the hash to get is specified
|
|
90
|
+
if (!!id) {
|
|
91
|
+
return cbk(null, hexAsReversedBuffer(id));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Exit early when the hash comes from the chain tip
|
|
95
|
+
if (!!getTip) {
|
|
96
|
+
return cbk(null, getTip);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return lnd[type].getBlockHash({block_height: height}, (err, res) => {
|
|
100
|
+
if (!!err && err.details === errorUnknownMethod) {
|
|
101
|
+
return cbk([501, 'GetBlockHashMethodNotSupported']);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!!err) {
|
|
105
|
+
return cbk([503, 'UnexpectedErrorGettingBlockHash', {err}]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!res) {
|
|
109
|
+
return cbk([503, 'ExpectedResponseForGetBlockHashRequest']);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!isBuffer(res.block_hash)) {
|
|
113
|
+
return cbk([503, 'ExpectedBlockHashInGetBlockHashResponse']);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return cbk(null, res.block_hash);
|
|
117
|
+
});
|
|
118
|
+
}],
|
|
119
|
+
|
|
120
|
+
// Get the block
|
|
121
|
+
getBlock: ['getHash', ({getHash}, cbk) => {
|
|
122
|
+
return lnd[type][method]({block_hash: getHash}, (err, res) => {
|
|
123
|
+
if (!!err && err.details === errorNotFound) {
|
|
124
|
+
return cbk([404, 'BlockNotFound']);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!!err && err.details === errorUnknownMethod) {
|
|
128
|
+
return cbk([501, 'GetBlockMethodNotSupported']);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!!err) {
|
|
132
|
+
return cbk([503, 'UnexpectedErrorWhenGettingChainBlock', {err}]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!res) {
|
|
136
|
+
return cbk([503, 'ExpectedResponseForChainBlockRequest']);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!isBuffer(res.raw_block)) {
|
|
140
|
+
return cbk([503, 'ExpectedRawBlockInChainBlockResponse']);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return cbk(null, {block: bufferAsHex(res.raw_block)});
|
|
144
|
+
});
|
|
145
|
+
}],
|
|
146
|
+
},
|
|
147
|
+
returnResult({reject, resolve, of: 'getBlock'}, cbk));
|
|
148
|
+
});
|
|
149
|
+
};
|
|
@@ -3,6 +3,7 @@ const cancelPendingChannel = require('./cancel_pending_channel');
|
|
|
3
3
|
const closeChannel = require('./close_channel');
|
|
4
4
|
const fundPendingChannels = require('./fund_pending_channels');
|
|
5
5
|
const fundPsbt = require('./fund_psbt');
|
|
6
|
+
const getBlock = require('./get_block');
|
|
6
7
|
const getChainBalance = require('./get_chain_balance');
|
|
7
8
|
const getChainFeeEstimate = require('./get_chain_fee_estimate');
|
|
8
9
|
const getChainFeeRate = require('./get_chain_fee_rate');
|
|
@@ -37,6 +38,7 @@ module.exports = {
|
|
|
37
38
|
closeChannel,
|
|
38
39
|
fundPendingChannels,
|
|
39
40
|
fundPsbt,
|
|
41
|
+
getBlock,
|
|
40
42
|
getChainBalance,
|
|
41
43
|
getChainFeeEstimate,
|
|
42
44
|
getChainFeeRate,
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@grpc/grpc-js": "1.8.0",
|
|
11
11
|
"@grpc/proto-loader": "0.7.4",
|
|
12
|
-
"@types/express": "4.17.
|
|
13
|
-
"@types/node": "18.11.
|
|
12
|
+
"@types/express": "4.17.15",
|
|
13
|
+
"@types/node": "18.11.16",
|
|
14
14
|
"@types/request": "2.48.8",
|
|
15
15
|
"@types/ws": "8.5.3",
|
|
16
16
|
"async": "3.2.4",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"invoices": "2.2.2",
|
|
27
27
|
"psbt": "2.7.1",
|
|
28
28
|
"tiny-secp256k1": "2.2.1",
|
|
29
|
-
"type-fest": "3.
|
|
29
|
+
"type-fest": "3.4.0"
|
|
30
30
|
},
|
|
31
31
|
"description": "Lightning Network client library",
|
|
32
32
|
"devDependencies": {
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"directory": "test/typescript"
|
|
60
60
|
},
|
|
61
61
|
"types": "index.d.ts",
|
|
62
|
-
"version": "6.
|
|
62
|
+
"version": "6.7.0"
|
|
63
63
|
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {getBlock} = require('./../../../lnd_methods');
|
|
4
|
+
|
|
5
|
+
const tests = [
|
|
6
|
+
{
|
|
7
|
+
args: {height: 'invalid'},
|
|
8
|
+
description: 'A valid height is expected to get a block',
|
|
9
|
+
error: [400, 'ExpectedNumericBlockHeightOfBlockToRetrieve'],
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
args: {id: 'invalid'},
|
|
13
|
+
description: 'A valid id is expected to get a block',
|
|
14
|
+
error: [400, 'ExpectedIdentifyingBlockHashOfBlockToRetrieve'],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
args: {height: 1, id: Buffer.alloc(32).toString('hex')},
|
|
18
|
+
description: 'Only a height or an id is required',
|
|
19
|
+
error: [400, 'ExpectedEitherHeightOrIdNotBoth'],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
args: {id: Buffer.alloc(32).toString('hex')},
|
|
23
|
+
description: 'An lnd object is required to get a block',
|
|
24
|
+
error: [400, 'ExpectedAuthenticatedLndToRetrieveBlock'],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
args: {
|
|
28
|
+
lnd: {
|
|
29
|
+
blocks: {
|
|
30
|
+
getBestBlock: ({}, cbk) => cbk({
|
|
31
|
+
details: 'unknown service chainrpc.ChainKit',
|
|
32
|
+
}),
|
|
33
|
+
getBlock: ({}, cbk) => cbk('err'),
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
description: 'An unsupported error is returned',
|
|
38
|
+
error: [501, 'GetBestBlockMethodNotSupported'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
args: {
|
|
42
|
+
lnd: {
|
|
43
|
+
blocks: {
|
|
44
|
+
getBestBlock: ({}, cbk) => cbk('err'),
|
|
45
|
+
getBlock: ({}, cbk) => cbk('getBlockErr'),
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
description: 'An error is returned',
|
|
50
|
+
error: [503, 'UnexpectedErrorGettingBestBlock', {err: 'err'}],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
args: {
|
|
54
|
+
lnd: {
|
|
55
|
+
blocks: {
|
|
56
|
+
getBestBlock: ({}, cbk) => cbk(),
|
|
57
|
+
getBlock: ({}, cbk) => cbk(),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
description: 'An error is returned when there is no best block result',
|
|
62
|
+
error: [503, 'ExpectedResponseForBestBlockRequest'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
args: {
|
|
66
|
+
lnd: {
|
|
67
|
+
blocks: {
|
|
68
|
+
getBestBlock: ({}, cbk) => cbk(null, {}),
|
|
69
|
+
getBlock: ({}, cbk) => cbk(),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
description: 'An error is returned when there is no result info',
|
|
74
|
+
error: [503, 'ExpectedChainTipInfoInGetBestBlockResponse'],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
args: {
|
|
78
|
+
height: 1,
|
|
79
|
+
lnd: {
|
|
80
|
+
blocks: {
|
|
81
|
+
getBlock: ({}, cbk) => cbk(),
|
|
82
|
+
getBlockHash: ({}, cbk) => cbk({
|
|
83
|
+
details: 'unknown service chainrpc.ChainKit',
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
description: 'An error is returned when get hash for height unsupported',
|
|
89
|
+
error: [501, 'GetBlockHashMethodNotSupported'],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
args: {
|
|
93
|
+
height: 1,
|
|
94
|
+
lnd: {
|
|
95
|
+
blocks: {
|
|
96
|
+
getBlock: ({}, cbk) => cbk(),
|
|
97
|
+
getBlockHash: ({}, cbk) => cbk('err'),
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
description: 'An unexpected error for getting block hash is returned',
|
|
102
|
+
error: [503, 'UnexpectedErrorGettingBlockHash', {err: 'err'}],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
args: {
|
|
106
|
+
height: 1,
|
|
107
|
+
lnd: {
|
|
108
|
+
blocks: {
|
|
109
|
+
getBlock: ({}, cbk) => cbk(),
|
|
110
|
+
getBlockHash: ({}, cbk) => cbk(),
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
description: 'A result is expected for getting a block hash',
|
|
115
|
+
error: [503, 'ExpectedResponseForGetBlockHashRequest'],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
args: {
|
|
119
|
+
height: 1,
|
|
120
|
+
lnd: {
|
|
121
|
+
blocks: {
|
|
122
|
+
getBlock: ({}, cbk) => cbk(),
|
|
123
|
+
getBlockHash: ({}, cbk) => cbk(null, {}),
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
description: 'A result hash is expected for getting a block hash',
|
|
128
|
+
error: [503, 'ExpectedBlockHashInGetBlockHashResponse'],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
args: {
|
|
132
|
+
id: Buffer.alloc(32).toString('hex'),
|
|
133
|
+
lnd: {
|
|
134
|
+
blocks: {
|
|
135
|
+
getBlock: ({}, cbk) => cbk({details: '-5: Block not found'}),
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
description: 'An error is returned when a block is not found',
|
|
140
|
+
error: [404, 'BlockNotFound'],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
args: {
|
|
144
|
+
id: Buffer.alloc(32).toString('hex'),
|
|
145
|
+
lnd: {
|
|
146
|
+
blocks: {
|
|
147
|
+
getBlock: ({}, cbk) => cbk({
|
|
148
|
+
details: 'unknown service chainrpc.ChainKit',
|
|
149
|
+
}),
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
description: 'An error is returned when the method is not supported',
|
|
154
|
+
error: [501, 'GetBlockMethodNotSupported'],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
args: {
|
|
158
|
+
id: Buffer.alloc(32).toString('hex'),
|
|
159
|
+
lnd: {blocks: {getBlock: ({}, cbk) => cbk('err')}},
|
|
160
|
+
},
|
|
161
|
+
description: 'An error is returned',
|
|
162
|
+
error: [503, 'UnexpectedErrorWhenGettingChainBlock', {err: 'err'}],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
args: {
|
|
166
|
+
id: Buffer.alloc(32).toString('hex'),
|
|
167
|
+
lnd: {blocks: {getBlock: ({}, cbk) => cbk()}},
|
|
168
|
+
},
|
|
169
|
+
description: 'A result is expected',
|
|
170
|
+
error: [503, 'ExpectedResponseForChainBlockRequest'],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
args: {
|
|
174
|
+
id: Buffer.alloc(32).toString('hex'),
|
|
175
|
+
lnd: {blocks: {getBlock: ({}, cbk) => cbk(null, {})}},
|
|
176
|
+
},
|
|
177
|
+
description: 'A resulting block is expected',
|
|
178
|
+
error: [503, 'ExpectedRawBlockInChainBlockResponse'],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
args: {
|
|
182
|
+
lnd: {
|
|
183
|
+
blocks: {
|
|
184
|
+
getBestBlock: ({}, cbk) => cbk(null, {block_hash: Buffer.alloc(1)}),
|
|
185
|
+
getBlock: ({}, cbk) => cbk(null, {raw_block: Buffer.alloc(1)}),
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
description: 'The chain tip block is returned',
|
|
190
|
+
expected: {block: '00'},
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
args: {
|
|
194
|
+
height: 1,
|
|
195
|
+
lnd: {
|
|
196
|
+
blocks: {
|
|
197
|
+
getBlock: ({}, cbk) => cbk(null, {raw_block: Buffer.alloc(1)}),
|
|
198
|
+
getBlockHash: ({}, cbk) => cbk(null, {block_hash: Buffer.alloc(1)}),
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
description: 'A block at a height is returned',
|
|
203
|
+
expected: {block: '00'},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
args: {
|
|
207
|
+
id: Buffer.alloc(32).toString('hex'),
|
|
208
|
+
lnd: {
|
|
209
|
+
blocks: {
|
|
210
|
+
getBlock: ({}, cbk) => cbk(null, {raw_block: Buffer.alloc(1)}),
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
description: 'A block is returned',
|
|
215
|
+
expected: {block: '00'},
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
220
|
+
return test(description, async ({deepEqual, end, rejects, strictSame}) => {
|
|
221
|
+
if (!!error) {
|
|
222
|
+
await rejects(() => getBlock(args), error, 'Got expected error');
|
|
223
|
+
} else {
|
|
224
|
+
const res = await getBlock(args);
|
|
225
|
+
|
|
226
|
+
strictSame(res, expected, 'Got expected result');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return end();
|
|
230
|
+
});
|
|
231
|
+
});
|
package/typescript/shared.d.ts
CHANGED
|
@@ -94,3 +94,10 @@ export type PaginationArgs = MergeExclusive<
|
|
|
94
94
|
token?: string;
|
|
95
95
|
}
|
|
96
96
|
>;
|
|
97
|
+
|
|
98
|
+
export type DateRangeFilterArgs = {
|
|
99
|
+
/** Creation Date After or Equal to ISO 8601 Date String */
|
|
100
|
+
created_after?: string;
|
|
101
|
+
/** Creation Date Before or Equal to ISO 8601 Date String */
|
|
102
|
+
created_before?: string;
|
|
103
|
+
};
|