@bsv/overlay
Version:
BSV Blockchain Overlay Services Engine
43 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BASMRemote = void 0;
class BASMRemote {
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));
}
}
exports.BASMRemote = BASMRemote;
//# sourceMappingURL=BASMRemote.js.map