brk-client 0.3.0-beta.8 → 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 -12
- 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
|
*
|
|
@@ -930,9 +992,6 @@ ancestors and no descendants (matches mempool.space).
|
|
|
930
992
|
* @property {boolean} rbf - BIP-125 signaling: at least one input has sequence < 0xffffffff-1.
|
|
931
993
|
* @property {?boolean=} fullRbf - Only populated on the root `tx` of an RBF response. `true` iff
|
|
932
994
|
this tx displaced at least one non-signaling predecessor.
|
|
933
|
-
* @property {?boolean=} mined - `Some(true)` iff the tx is currently confirmed in the indexed
|
|
934
|
-
chain. Absent on serialization when the tx is still pending or
|
|
935
|
-
has been evicted without confirming.
|
|
936
995
|
*/
|
|
937
996
|
/**
|
|
938
997
|
* Recommended fee rates in sat/vB
|
|
@@ -7502,7 +7561,7 @@ function createTransferPattern(client, acc) {
|
|
|
7502
7561
|
* @extends BrkClientBase
|
|
7503
7562
|
*/
|
|
7504
7563
|
class BrkClient extends BrkClientBase {
|
|
7505
|
-
VERSION = "v0.3.0
|
|
7564
|
+
VERSION = "v0.3.0";
|
|
7506
7565
|
|
|
7507
7566
|
INDEXES = /** @type {const} */ ([
|
|
7508
7567
|
"minute10",
|
|
@@ -10476,7 +10535,7 @@ class BrkClient extends BrkClientBase {
|
|
|
10476
10535
|
/**
|
|
10477
10536
|
* Health check
|
|
10478
10537
|
*
|
|
10479
|
-
* 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`.
|
|
10480
10539
|
*
|
|
10481
10540
|
* Endpoint: `GET /health`
|
|
10482
10541
|
* @param {{ signal?: AbortSignal, onValue?: (value: Health) => void }} [options]
|
|
@@ -10915,7 +10974,7 @@ class BrkClient extends BrkClientBase {
|
|
|
10915
10974
|
/**
|
|
10916
10975
|
* Address transactions
|
|
10917
10976
|
*
|
|
10918
|
-
* 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}`.
|
|
10919
10978
|
*
|
|
10920
10979
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-address-transactions)*
|
|
10921
10980
|
*
|
|
@@ -11623,7 +11682,7 @@ class BrkClient extends BrkClientBase {
|
|
|
11623
11682
|
/**
|
|
11624
11683
|
* Projected mempool blocks
|
|
11625
11684
|
*
|
|
11626
|
-
*
|
|
11685
|
+
* Projected blocks for fee estimation. Block 0 reflects Bitcoin Core's actual next-block selection; blocks 1+ are a fee-tier approximation.
|
|
11627
11686
|
*
|
|
11628
11687
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-mempool-blocks-fees)*
|
|
11629
11688
|
*
|
|
@@ -11639,7 +11698,7 @@ class BrkClient extends BrkClientBase {
|
|
|
11639
11698
|
/**
|
|
11640
11699
|
* Recommended fees
|
|
11641
11700
|
*
|
|
11642
|
-
*
|
|
11701
|
+
* Recommended fee rates by confirmation target.
|
|
11643
11702
|
*
|
|
11644
11703
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-recommended-fees)*
|
|
11645
11704
|
*
|
|
@@ -11655,7 +11714,7 @@ class BrkClient extends BrkClientBase {
|
|
|
11655
11714
|
/**
|
|
11656
11715
|
* Precise recommended fees
|
|
11657
11716
|
*
|
|
11658
|
-
*
|
|
11717
|
+
* Recommended fee rates with sub-integer precision.
|
|
11659
11718
|
*
|
|
11660
11719
|
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-recommended-fees-precise)*
|
|
11661
11720
|
*
|
|
@@ -11687,11 +11746,11 @@ class BrkClient extends BrkClientBase {
|
|
|
11687
11746
|
/**
|
|
11688
11747
|
* Mempool content hash
|
|
11689
11748
|
*
|
|
11690
|
-
* 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.
|
|
11691
11750
|
*
|
|
11692
11751
|
* Endpoint: `GET /api/mempool/hash`
|
|
11693
|
-
* @param {{ signal?: AbortSignal, onValue?: (value:
|
|
11694
|
-
* @returns {Promise<
|
|
11752
|
+
* @param {{ signal?: AbortSignal, onValue?: (value: NextBlockHash) => void }} [options]
|
|
11753
|
+
* @returns {Promise<NextBlockHash>}
|
|
11695
11754
|
*/
|
|
11696
11755
|
async getMempoolHash({ signal, onValue } = {}) {
|
|
11697
11756
|
const path = `/api/mempool/hash`;
|
|
@@ -11762,6 +11821,36 @@ class BrkClient extends BrkClientBase {
|
|
|
11762
11821
|
return this.getJson(path, { signal, onValue });
|
|
11763
11822
|
}
|
|
11764
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
|
+
|
|
11765
11854
|
/**
|
|
11766
11855
|
* Live BTC/USD price
|
|
11767
11856
|
*
|
package/package.json
CHANGED