@bsv/wallet-toolbox-client
Version:
Client only Wallet Storage
71 lines • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskCheckNoSends = void 0;
const Monitor_1 = require("../Monitor");
const TaskCheckForProofs_1 = require("./TaskCheckForProofs");
const WalletMonitorTask_1 = require("./WalletMonitorTask");
/**
* `TaskCheckNoSends` is a WalletMonitor task that retreives merkle proofs for
* 'nosend' transactions that MAY have been shared externally.
*
* Unlike intentionally processed transactions, 'nosend' transactions are fully valid
* transactions which have not been processed by the wallet.
*
* By default, this task runs once a day to check if any 'nosend' transaction has
* managed to get mined by some external process.
*
* If a proof is obtained and validated, a new ProvenTx record is created and
* the original ProvenTxReq status is advanced to 'notifying'.
*/
class TaskCheckNoSends extends WalletMonitorTask_1.WalletMonitorTask {
constructor(monitor, triggerMsecs = Monitor_1.Monitor.oneDay * 1) {
super(monitor, TaskCheckNoSends.taskName);
this.triggerMsecs = triggerMsecs;
}
/**
* Normally triggered by checkNow getting set by new block header found event from chaintracks
*/
trigger(nowMsecsSinceEpoch) {
return {
run: TaskCheckNoSends.checkNow ||
(this.triggerMsecs > 0 && nowMsecsSinceEpoch - this.lastRunMsecsSinceEpoch > this.triggerMsecs)
};
}
async runTask() {
var _a;
let log = '';
const countsAsAttempt = TaskCheckNoSends.checkNow;
TaskCheckNoSends.checkNow = false;
const maxAcceptableHeight = (_a = this.monitor.lastNewHeader) === null || _a === void 0 ? void 0 : _a.height;
if (maxAcceptableHeight === undefined) {
return log;
}
const limit = 100;
let offset = 0;
for (;;) {
const reqs = await this.storage.findProvenTxReqs({
partial: {},
status: ['nosend'],
paged: { limit, offset }
});
if (reqs.length === 0)
break;
log += `${reqs.length} reqs with status 'nosend'\n`;
const r = await (0, TaskCheckForProofs_1.getProofs)(this, reqs, 2, countsAsAttempt, false, maxAcceptableHeight);
log += `${r.log}\n`;
//console.log(log);
if (reqs.length < limit)
break;
offset += limit;
}
return log;
}
}
exports.TaskCheckNoSends = TaskCheckNoSends;
TaskCheckNoSends.taskName = 'CheckNoSends';
/**
* An external service such as the chaintracks new block header
* listener can set this true to cause
*/
TaskCheckNoSends.checkNow = false;
//# sourceMappingURL=TaskCheckNoSends.js.map