brk-client 0.3.0-beta.9 → 0.3.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/index.js +101 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -281,6 +281,54 @@ Matches mempool.space/bitcoin-cli behavior.
|
|
|
281
281
|
* @property {(Height|null)=} height - Block height (only if in best chain)
|
|
282
282
|
* @property {(BlockHash|null)=} nextBest - Hash of the next block in the best chain (null if tip)
|
|
283
283
|
*/
|
|
284
|
+
/**
|
|
285
|
+
* Projected next-block contents from Bitcoin Core's `getblocktemplate`
|
|
286
|
+
* (block 0 of the snapshot). Returned by
|
|
287
|
+
* `GET /api/v1/mempool/block-template`.
|
|
288
|
+
*
|
|
289
|
+
* @typedef {Object} BlockTemplate
|
|
290
|
+
* @property {NextBlockHash} hash - Pass back as `<hash>` on
|
|
291
|
+
`/api/v1/mempool/block-template/diff/{hash}` to fetch deltas.
|
|
292
|
+
* @property {MempoolBlock} stats - Aggregate stats for this block (size, vsize, fee range, ...).
|
|
293
|
+
* @property {Transaction[]} transactions - Full transaction bodies in `getblocktemplate` order.
|
|
294
|
+
*/
|
|
295
|
+
/**
|
|
296
|
+
* Delta between the current `getblocktemplate` projection and a prior
|
|
297
|
+
* one identified by `since`. Returned by
|
|
298
|
+
* `GET /api/v1/mempool/block-template/diff/{hash}`.
|
|
299
|
+
*
|
|
300
|
+
* `order` carries the full new template in template order: each entry
|
|
301
|
+
* is either a `Retained(idx)` pointing into the prior template (which
|
|
302
|
+
* the client cached at `since`) or a `New(tx)` inline body. Walk it
|
|
303
|
+
* once to rebuild the new template; no separate `added` array to
|
|
304
|
+
* cross-reference.
|
|
305
|
+
*
|
|
306
|
+
* `removed` is redundant (computable from `order` by collecting prior
|
|
307
|
+
* indices that don't appear) but shipped for cache-eviction ergonomics.
|
|
308
|
+
*
|
|
309
|
+
* @typedef {Object} BlockTemplateDiff
|
|
310
|
+
* @property {NextBlockHash} hash - Current next-block hash. Use as `since` on the next diff call.
|
|
311
|
+
* @property {NextBlockHash} since - Echoed prior hash the diff was computed against.
|
|
312
|
+
* @property {BlockTemplateDiffEntry[]} order - New template in order. Each entry is either an index into the
|
|
313
|
+
prior template's transactions or a full transaction body.
|
|
314
|
+
* @property {Txid[]} removed - Txids that left the projected next block since `since`
|
|
315
|
+
(confirmed, evicted, replaced, or pushed past block 0).
|
|
316
|
+
*/
|
|
317
|
+
/**
|
|
318
|
+
* One slot of the new template in a `BlockTemplateDiff`.
|
|
319
|
+
*
|
|
320
|
+
* Untagged on the wire so JSON type disambiguates the variants:
|
|
321
|
+
* - `Retained(idx)` serializes as a bare integer - index into the
|
|
322
|
+
* transactions of the prior template (which the client cached at
|
|
323
|
+
* `since`).
|
|
324
|
+
* - `New(tx)` serializes as a transaction object - a body that was
|
|
325
|
+
* not in the prior template and must be added at this position.
|
|
326
|
+
*
|
|
327
|
+
* Reconstruction is a single pass: for each entry, either copy
|
|
328
|
+
* `prior[idx]` or append the inline body.
|
|
329
|
+
*
|
|
330
|
+
* @typedef {(number|Transaction)} BlockTemplateDiffEntry
|
|
331
|
+
*/
|
|
284
332
|
/**
|
|
285
333
|
* Block information returned for timestamp queries
|
|
286
334
|
*
|
|
@@ -711,6 +759,20 @@ ancestors and no descendants (matches mempool.space).
|
|
|
711
759
|
/** @typedef {number} Month1 */
|
|
712
760
|
/** @typedef {number} Month3 */
|
|
713
761
|
/** @typedef {number} Month6 */
|
|
762
|
+
/**
|
|
763
|
+
* Content hash of the projected next block (block 0 of the mempool
|
|
764
|
+
* snapshot). Same value as the mempool ETag. Opaque token: pass back
|
|
765
|
+
* as `since` on `/api/v1/mempool/block-template/diff/{hash}` to fetch
|
|
766
|
+
* deltas.
|
|
767
|
+
*
|
|
768
|
+
* @typedef {number} NextBlockHash
|
|
769
|
+
*/
|
|
770
|
+
/**
|
|
771
|
+
* `since` hash for `/api/v1/mempool/block-template/diff/{hash}`.
|
|
772
|
+
*
|
|
773
|
+
* @typedef {Object} NextBlockHashParam
|
|
774
|
+
* @property {NextBlockHash} hash
|
|
775
|
+
*/
|
|
714
776
|
/**
|
|
715
777
|
* OHLC (Open, High, Low, Close) data in cents
|
|
716
778
|
*
|
|
@@ -7499,7 +7561,7 @@ function createTransferPattern(client, acc) {
|
|
|
7499
7561
|
* @extends BrkClientBase
|
|
7500
7562
|
*/
|
|
7501
7563
|
class BrkClient extends BrkClientBase {
|
|
7502
|
-
VERSION = "v0.3.0
|
|
7564
|
+
VERSION = "v0.3.0";
|
|
7503
7565
|
|
|
7504
7566
|
INDEXES = /** @type {const} */ ([
|
|
7505
7567
|
"minute10",
|
|
@@ -10473,7 +10535,7 @@ class BrkClient extends BrkClientBase {
|
|
|
10473
10535
|
/**
|
|
10474
10536
|
* Health check
|
|
10475
10537
|
*
|
|
10476
|
-
* Returns
|
|
10538
|
+
* Liveness probe. Returns server identity, uptime, and indexed/computed heights from local state only (no bitcoind round-trip). For real chain-tip catch-up, see `/api/server/sync`.
|
|
10477
10539
|
*
|
|
10478
10540
|
* Endpoint: `GET /health`
|
|
10479
10541
|
* @param {{ signal?: AbortSignal, onValue?: (value: Health) => void }} [options]
|
|
@@ -10912,7 +10974,7 @@ class BrkClient extends BrkClientBase {
|
|
|
10912
10974
|
/**
|
|
10913
10975
|
* Address transactions
|
|
10914
10976
|
*
|
|
10915
|
-
* Get transaction history for an address,
|
|
10977
|
+
* Get transaction history for an address, newest first. Returns up to 50 mempool transactions plus a confirmed page sized to fill the response to 50 total (chain floor of 25, so 25-50 confirmed depending on mempool weight). To paginate further confirmed history, use `/address/{address}/txs/chain/{last_seen_txid}`.
|
|
10916
10978
|
*
|
|
10917
10979
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-address-transactions)*
|
|
10918
10980
|
*
|
|
@@ -11620,7 +11682,7 @@ class BrkClient extends BrkClientBase {
|
|
|
11620
11682
|
/**
|
|
11621
11683
|
* Projected mempool blocks
|
|
11622
11684
|
*
|
|
11623
|
-
*
|
|
11685
|
+
* Projected blocks for fee estimation. Block 0 reflects Bitcoin Core's actual next-block selection; blocks 1+ are a fee-tier approximation.
|
|
11624
11686
|
*
|
|
11625
11687
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-mempool-blocks-fees)*
|
|
11626
11688
|
*
|
|
@@ -11636,7 +11698,7 @@ class BrkClient extends BrkClientBase {
|
|
|
11636
11698
|
/**
|
|
11637
11699
|
* Recommended fees
|
|
11638
11700
|
*
|
|
11639
|
-
*
|
|
11701
|
+
* Recommended fee rates by confirmation target.
|
|
11640
11702
|
*
|
|
11641
11703
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-recommended-fees)*
|
|
11642
11704
|
*
|
|
@@ -11652,7 +11714,7 @@ class BrkClient extends BrkClientBase {
|
|
|
11652
11714
|
/**
|
|
11653
11715
|
* Precise recommended fees
|
|
11654
11716
|
*
|
|
11655
|
-
*
|
|
11717
|
+
* Recommended fee rates with sub-integer precision.
|
|
11656
11718
|
*
|
|
11657
11719
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-recommended-fees-precise)*
|
|
11658
11720
|
*
|
|
@@ -11684,11 +11746,11 @@ class BrkClient extends BrkClientBase {
|
|
|
11684
11746
|
/**
|
|
11685
11747
|
* Mempool content hash
|
|
11686
11748
|
*
|
|
11687
|
-
* Returns an opaque
|
|
11749
|
+
* Returns an opaque hash that changes whenever the projected next block changes. Same value as the mempool ETag. Useful as a freshness/liveness signal: if it stays constant for tens of seconds on a live network, the mempool sync loop has stalled.
|
|
11688
11750
|
*
|
|
11689
11751
|
* Endpoint: `GET /api/mempool/hash`
|
|
11690
|
-
* @param {{ signal?: AbortSignal, onValue?: (value:
|
|
11691
|
-
* @returns {Promise<
|
|
11752
|
+
* @param {{ signal?: AbortSignal, onValue?: (value: NextBlockHash) => void }} [options]
|
|
11753
|
+
* @returns {Promise<NextBlockHash>}
|
|
11692
11754
|
*/
|
|
11693
11755
|
async getMempoolHash({ signal, onValue } = {}) {
|
|
11694
11756
|
const path = `/api/mempool/hash`;
|
|
@@ -11759,6 +11821,36 @@ class BrkClient extends BrkClientBase {
|
|
|
11759
11821
|
return this.getJson(path, { signal, onValue });
|
|
11760
11822
|
}
|
|
11761
11823
|
|
|
11824
|
+
/**
|
|
11825
|
+
* Projected next block template
|
|
11826
|
+
*
|
|
11827
|
+
* Bitcoin Core's `getblocktemplate` selection: full transaction bodies in GBT order with aggregate stats. The returned `hash` is an opaque content token; pass it as `<hash>` on `/api/v1/mempool/block-template/diff/{hash}` to fetch deltas instead of refetching the whole template.
|
|
11828
|
+
*
|
|
11829
|
+
* Endpoint: `GET /api/v1/mempool/block-template`
|
|
11830
|
+
* @param {{ signal?: AbortSignal, onValue?: (value: BlockTemplate) => void }} [options]
|
|
11831
|
+
* @returns {Promise<BlockTemplate>}
|
|
11832
|
+
*/
|
|
11833
|
+
async getBlockTemplate({ signal, onValue } = {}) {
|
|
11834
|
+
const path = `/api/v1/mempool/block-template`;
|
|
11835
|
+
return this.getJson(path, { signal, onValue });
|
|
11836
|
+
}
|
|
11837
|
+
|
|
11838
|
+
/**
|
|
11839
|
+
* Block template diff since hash
|
|
11840
|
+
*
|
|
11841
|
+
* Delta of the projected next block since `<hash>`. `order` is the full new template in order: each entry is either a number (index into the prior template the client cached at `<hash>`) or a transaction object (new body to insert at this position). Walk `order` once to rebuild; `removed` is a convenience list of txids that left so clients can evict cached bodies. After applying, use the response `hash` as `<hash>` on the next call to keep iterating. Returns `404` when `<hash>` has aged out of server history; clients should fall back to `/api/v1/mempool/block-template`.
|
|
11842
|
+
*
|
|
11843
|
+
* Endpoint: `GET /api/v1/mempool/block-template/diff/{hash}`
|
|
11844
|
+
*
|
|
11845
|
+
* @param {NextBlockHash} hash
|
|
11846
|
+
* @param {{ signal?: AbortSignal, onValue?: (value: BlockTemplateDiff) => void }} [options]
|
|
11847
|
+
* @returns {Promise<BlockTemplateDiff>}
|
|
11848
|
+
*/
|
|
11849
|
+
async getBlockTemplateDiff(hash, { signal, onValue } = {}) {
|
|
11850
|
+
const path = `/api/v1/mempool/block-template/diff/${hash}`;
|
|
11851
|
+
return this.getJson(path, { signal, onValue });
|
|
11852
|
+
}
|
|
11853
|
+
|
|
11762
11854
|
/**
|
|
11763
11855
|
* Live BTC/USD price
|
|
11764
11856
|
*
|
package/package.json
CHANGED