expose zapping.

This commit is contained in:
Christopher Jeffrey 2016-03-31 16:32:09 -07:00
parent 8346cccbcb
commit 819c63b9b7
6 changed files with 71 additions and 3 deletions

View File

@ -504,6 +504,24 @@ Client.prototype.walletSend = function walletSend(id, options, callback) {
});
};
Client.prototype.zapWallet = function zapWallet(id, now, age, callback) {
var body = {
now: now,
age: age
};
assert(utils.isFinite(now));
assert(utils.isFinite(age));
assert(now >= age);
callback = utils.ensure(callback);
return this._post('/wallet/' + id + '/zap', body, function(err) {
if (err)
return callback(err);
return callback();
});
};
/**
* Expose

View File

@ -125,6 +125,10 @@ Provider.prototype.sync = function sync(wallet, address) {
});
};
Provider.prototype.zap = function zap(now, age, callback) {
return this.client.zapWallet(this.id, now, age, callback);
};
/**
* Expose
*/

View File

@ -276,6 +276,19 @@ NodeServer.prototype._init = function _init() {
});
});
this.post('/wallet/:id/zap', function(req, res, next, send) {
var id = req.options.id;
var now = req.options.now;
var age = req.options.age;
self.walletdb.zapWallet(id, now, age, function(err, wallet) {
if (err)
return next(err);
send(200, { success: true });
});
});
// Update wallet / sync address depth
this.put('/wallet/:id', function(req, res, next, send) {
var id = req.options.id;

View File

@ -1728,16 +1728,28 @@ TXPool.prototype.removeUnchecked = function removeUnchecked(hash, callback, forc
});
};
TXPool.prototype.zap = function zap(now, age, callback, force) {
TXPool.prototype.zap = function zap(address, now, age, callback, force) {
var self = this;
var unlock = this._lock(zap, [tip, callback], force);
if (typeof address !== 'string') {
force = callback;
callback = age;
age = now;
now = address;
address = null;
}
var unlock = this._lock(zap, [address, now, age, callback], force);
if (!unlock)
return;
callback = utils.wrap(callback, unlock);
return this.getRange(null, {
assert(utils.isFinite(now));
assert(utils.isFinite(age));
assert(now >= age);
return this.getRange(address, {
start: 0,
end: now - age
}, function(err, txs) {

View File

@ -735,6 +735,14 @@ Wallet.prototype.getRedeem = function getRedeem(hash, prefix) {
return address.script;
};
Wallet.prototype.zap = function zap(now, age, callback) {
if (!this.provider.zap) {
return utils.asyncify(callback)(
new Error('Provider does not support zapping.'));
}
return this.provider.zap(now, age, callback);
};
Wallet.prototype.scan = function scan(txByAddress, callback) {
var self = this;
var res = false;

View File

@ -586,6 +586,15 @@ WalletDB.prototype.removeBlock = function removeBlock(block, callback) {
}, callback);
};
WalletDB.prototype.zap = function zap(now, age, callback) {
return this.tx.zap(now, age, callback);
};
WalletDB.prototype.zapWallet = function zapWallet(id, now, age, callback) {
id = id.id || id;
return this.tx.zap(id, now, age, callback);
};
/**
* Provider
*/
@ -740,6 +749,10 @@ Provider.prototype.update = function update(wallet, address) {
return this.db.update(wallet, address);
};
Provider.prototype.zap = function zap(wallet, address) {
return this.db.zapWallet(wallet, address);
};
/**
* Expose
*/