ln-service 57.0.1 → 57.1.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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Versions
2
2
 
3
+ ## 57.1.0
4
+
5
+ - `getBlockHeader`: Add method to get the header portion of a block
6
+
3
7
  ## 57.0.1
4
8
 
5
9
  - Add support for LND 0.17.0
package/README.md CHANGED
@@ -175,6 +175,7 @@ for `unlocker` methods.
175
175
  - [getBackup](#getbackup) - Get a backup of a channel
176
176
  - [getBackups](#getbackups) - Get a backup for all channels
177
177
  - [getBlock](#getblock) - Get the raw block data given a block id in the chain
178
+ - [getBlockHeader](#getblockheader) - Get the raw block header for a block
178
179
  - [getChainAddresses](#getchainaddresses) - Get created chain addresses
179
180
  - [getChainBalance](#getchainbalance) - Get the confirmed chain balance
180
181
  - [getChainFeeEstimate](#getchainfeeestimate) - Get a chain fee estimate
@@ -1465,7 +1466,7 @@ const {backup} = await getBackups({lnd});
1465
1466
 
1466
1467
  Get a block in the chain
1467
1468
 
1468
- This method requires LND built with `chainkit` build tag
1469
+ This method requires LND built with `chainrpc` build tag
1469
1470
 
1470
1471
  Requires `onchain:read` permission
1471
1472
 
@@ -1494,6 +1495,39 @@ const {block} = await getBlock({lnd, id: chain.current_block_hash});
1494
1495
  const lastBlockSize = Buffer.from(block, 'hex').byteLength();
1495
1496
  ```
1496
1497
 
1498
+ ### getBlockHeader
1499
+
1500
+ Get a block header in the best chain
1501
+
1502
+ This method requires LND built with `chainrpc` build tag
1503
+
1504
+ Requires `onchain:read` permission
1505
+
1506
+ This method is not supported on LND 0.17.0 and below
1507
+
1508
+ {
1509
+ [height]: <Block Height Number>
1510
+ [id]: <Block Hash Hex String>
1511
+ lnd: <Authenticated LND API Object>
1512
+ }
1513
+
1514
+ @returns via cbk or Promise
1515
+ {
1516
+ header: <Raw Block Header Bytes Hex String>
1517
+ }
1518
+
1519
+ Example:
1520
+
1521
+ ```node
1522
+ const {getBlockHeader, getHeight} = require('ln-service');
1523
+
1524
+ const chain = await getHeight({lnd});
1525
+
1526
+ const {header} = await getBlockHeader({lnd, id: chain.current_block_hash});
1527
+
1528
+ const lastBlockHeader = Buffer.from(header, 'hex');
1529
+ ```
1530
+
1497
1531
  ### getChainAddresses
1498
1532
 
1499
1533
  Get the wallet chain addresses
package/index.js CHANGED
@@ -34,6 +34,7 @@ const {getAutopilot} = require('lightning');
34
34
  const {getBackup} = require('lightning');
35
35
  const {getBackups} = require('lightning');
36
36
  const {getBlock} = require('lightning');
37
+ const {getBlockHeader} = require('lightning');
37
38
  const {getChainAddresses} = require('lightning');
38
39
  const {getChainBalance} = require('lightning');
39
40
  const {getChainFeeEstimate} = require('lightning');
@@ -190,6 +191,7 @@ module.exports = {
190
191
  getBackup,
191
192
  getBackups,
192
193
  getBlock,
194
+ getBlockHeader,
193
195
  getChainAddresses,
194
196
  getChainBalance,
195
197
  getChainFeeEstimate,
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "dependencies": {
10
10
  "bolt07": "1.8.4",
11
11
  "invoices": "3.0.0",
12
- "lightning": "10.0.1",
12
+ "lightning": "10.1.0",
13
13
  "macaroon": "3.0.4"
14
14
  },
15
15
  "description": "Interaction helper for your Lightning Network daemon",
@@ -24,7 +24,7 @@
24
24
  "bn.js": "5.2.1",
25
25
  "bs58check": "3.0.1",
26
26
  "ecpair": "2.1.0",
27
- "ln-docker-daemons": "6.0.1",
27
+ "ln-docker-daemons": "6.0.3",
28
28
  "p2tr": "2.0.0",
29
29
  "portfinder": "1.0.32",
30
30
  "psbt": "3.0.0",
@@ -66,5 +66,5 @@
66
66
  "integration-test-0.14.4": "DOCKER_LND_VERSION=v0.14.4-beta npm run test",
67
67
  "test": "echo $DOCKER_LND_VERSION && node test/runner"
68
68
  },
69
- "version": "57.0.1"
69
+ "version": "57.1.0"
70
70
  }
@@ -0,0 +1,62 @@
1
+ const {strictEqual} = require('node:assert').strict;
2
+ const test = require('node:test');
3
+
4
+ const {spawnLightningCluster} = require('ln-docker-daemons');
5
+
6
+ const {getBlockHeader} = require('./../../');
7
+ const {getHeight} = require('./../../');
8
+
9
+ const headerHexLength = 80 * 2;
10
+
11
+ // Get block header should return the block header
12
+ test(`Get block header`, async () => {
13
+ const {nodes} = await spawnLightningCluster({});
14
+
15
+ const [{chain, generate, kill, lnd}] = nodes;
16
+
17
+ const blockchain = await getHeight({lnd});
18
+
19
+ const hash = blockchain.current_block_hash;
20
+ const height = blockchain.current_block_height;
21
+
22
+ // Try getting a block header by the hash
23
+ try {
24
+ const {header} = await getBlockHeader({
25
+ lnd,
26
+ id: blockchain.current_block_hash,
27
+ });
28
+
29
+ strictEqual(header.length, headerHexLength, 'Got header');
30
+ } catch (err) {
31
+ const [code, message] = err;
32
+
33
+ strictEqual(code, 501, 'Got expected code');
34
+ strictEqual(message, 'GetBlockHeaderMethodNotSupported', 'Got error');
35
+
36
+ await kill({});
37
+
38
+ return;
39
+ }
40
+
41
+ // Try getting a block header by the height
42
+ try {
43
+ const {header} = await getBlockHeader({height, lnd});
44
+
45
+ strictEqual(header.length, headerHexLength, 'Got header');
46
+ } catch (err) {
47
+ strictEqual(err, null, 'Expected no error');
48
+ }
49
+
50
+ // Try getting the chain tip block header
51
+ try {
52
+ const {header} = await getBlockHeader({lnd});
53
+
54
+ strictEqual(header.length, headerHexLength, 'Got header');
55
+ } catch (err) {
56
+ strictEqual(err, null, 'Expected no error');
57
+ }
58
+
59
+ await kill({});
60
+
61
+ return;
62
+ });