UNPKG

@samouraiwallet/one-dollar-fee-estimator

Version:

A script estimating the minimum feerate required for the inclusion of a bitcoin transaction into the next block.

44 lines 1.41 kB
import { TypedEventEmitter } from "./typesafe-event-emitter.js"; import { initEstimator } from "./estimator-worker.js"; export class FeeEstimator extends TypedEventEmitter { constructor(options) { super(); this.onWorkerMessage = (data) => { this._data = data; this.emit("data", data); }; this.onWorkerError = (error) => { this.emit("error", error); }; this.onWorkerExit = (code) => { if (code !== 0) { this.emit("error", new Error(`FeeEstimator worker stopped with ${code} exit code`)); } }; this.stop = () => { this.estimator.postMessage("stop"); }; this._data = { ready: false, lastBlock: null, fees: { "0.1": 1, "0.2": 1, "0.5": 1, "0.9": 1, "0.99": 1, "0.999": 1, }, }; this.estimator = initEstimator(options); this.estimator.on("message", this.onWorkerMessage); this.estimator.on("error", this.onWorkerError); this.estimator.on("exit", this.onWorkerExit); process.on("SIGINT", () => this.stop()); process.on("SIGTERM", () => this.stop()); } get data() { return this._data; } } //# sourceMappingURL=estimator.js.map