UNPKG

@bsv/overlay

Version:
42 lines 1.57 kB
export class BASMRemote { endpoint; topic; fetchImpl; constructor(endpoint, topic, fetchImpl = fetch.bind(globalThis)) { this.endpoint = endpoint; this.topic = topic; this.fetchImpl = fetchImpl; } async requestTopicAnchorTip() { return await this.post('/requestTopicAnchorTip', {}); } async requestTopicAnchorRange(fromHeight, toHeight) { return await this.post('/requestTopicAnchorRange', { fromHeight, toHeight }); } async requestAdmittedList(blockHeight, blockHash) { return await this.post('/requestAdmittedList', { blockHeight, blockHash }); } async requestCompoundMerklePath(blockHeight, txids) { return await this.post('/requestCompoundMerklePath', { blockHeight, txids }); } async requestRawTransactions(txids) { return await this.post('/requestRawTransactions', { txids }); } async post(path, body) { const response = await this.fetchImpl(new URL(path, this.endpoint).toString(), { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'x-bsv-topic': this.topic }, body: JSON.stringify(body) }); const text = await response.text(); if (!response.ok) { throw new Error(`BASM peer ${this.endpoint} returned ${response.status}: ${text}`); } return (text.length === 0 ? {} : JSON.parse(text)); } } //# sourceMappingURL=BASMRemote.js.map