diff --git a/bin/cli b/bin/cli index b4b81243..4312e664 100755 --- a/bin/cli +++ b/bin/cli @@ -303,6 +303,16 @@ CLI.prototype.rescan = co(function* rescan() { this.log('Rescanning...'); }); +CLI.prototype.resend = co(function* resend() { + yield this.client.resend(); + this.log('Resending...'); +}); + +CLI.prototype.resendWallet = co(function* resendWallet() { + yield this.wallet.resend(); + this.log('Resending...'); +}); + CLI.prototype.zap = co(function* zap() { var age = +this.argv[0] || 72 * 3600; yield this.client.zap(age); @@ -441,6 +451,8 @@ CLI.prototype.handleWallet = co(function* handleWallet() { return yield this.lock(); case 'unlock': return yield this.unlock(); + case 'resend': + return yield this.resendWallet(); default: this.log('Unrecognized command.'); this.log('Commands:'); @@ -466,6 +478,7 @@ CLI.prototype.handleWallet = co(function* handleWallet() { this.log(' $ watch [address]: Import an address.'); this.log(' $ lock: Lock wallet.'); this.log(' $ unlock [passphrase] [timeout?]: Unlock wallet.'); + this.log(' $ resend: Resend pending transactions.'); this.log('Other Options:'); this.log(' --passphrase [passphrase]: For signing and account creation.'); this.log(' --account [account-name]: Account name.'); @@ -499,6 +512,8 @@ CLI.prototype.handleNode = co(function* handleNode() { return yield this.getBlock(); case 'rescan': return yield this.rescan(); + case 'resend': + return yield this.resend(); case 'zap': return yield this.zap(); case 'backup': @@ -515,6 +530,7 @@ CLI.prototype.handleNode = co(function* handleNode() { this.log(' $ coin [hash+index/address]: View coins.'); this.log(' $ block [hash/height]: View block.'); this.log(' $ rescan [height/hash]: Rescan for transactions.'); + this.log(' $ resend: Resend pending transactions.'); this.log(' $ zap [age?]: Zap stale transactions from walletdb.'); this.log(' $ backup [path]: Backup the wallet db.'); this.log(' $ rpc [command] [args]: Execute RPC command.'); diff --git a/lib/http/client.js b/lib/http/client.js index af8b435f..0294b6b3 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -353,6 +353,15 @@ HTTPClient.prototype.rescan = function rescan(hash) { return this._post('/rescan', options); }; +/** + * Resend pending transactions. + * @returns {Promise} + */ + +HTTPClient.prototype.resend = function resend() { + return this._post('/resend', {}); +}; + /** * Zap stale transactions. * @param {Number} age @@ -806,6 +815,15 @@ HTTPClient.prototype.unlock = function unlock(id, passphrase, timeout) { return this._post('/wallet/' + id + '/unlock', options); }; +/** + * Resend pending wallet transactions. + * @returns {Promise} + */ + +HTTPClient.prototype.resendWallet = function resendWallet(id) { + return this._post('/wallet/' + id + '/resend', {}); +}; + /** * Get wallet accounts. * @param {WalletID} id diff --git a/lib/http/server.js b/lib/http/server.js index f1fdb23c..bf93bfc8 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -698,6 +698,11 @@ HTTPServer.prototype._init = function _init() { yield this.node.scan(height); })); + // Resend + this.post('/resend', con(function* (req, res, send, next) { + yield this.walletdb.resend(); + })); + // Zap this.post('/zap', con(function* (req, res, send, next) { var options = req.options; @@ -1065,6 +1070,11 @@ HTTPServer.prototype._init = function _init() { send(200, details.toJSON()); })); + // Resend + this.post('/wallet/:id/resend', con(function* (req, res, send, next) { + yield req.wallet.resend(); + })); + this.server.on('error', function(err) { self.emit('error', err); }); diff --git a/lib/http/wallet.js b/lib/http/wallet.js index 57e70e9b..5520d2c6 100644 --- a/lib/http/wallet.js +++ b/lib/http/wallet.js @@ -316,7 +316,7 @@ HTTPWallet.prototype.retoken = co(function* retoken(passphrase) { * @returns {Promise} */ -HTTPWallet.prototype.importPrivate = function importPrivate(id, account, key) { +HTTPWallet.prototype.importPrivate = function importPrivate(account, key) { return this.client.importPrivate(this.id, account, key); }; @@ -327,7 +327,7 @@ HTTPWallet.prototype.importPrivate = function importPrivate(id, account, key) { * @returns {Promise} */ -HTTPWallet.prototype.importPublic = function importPublic(id, account, key) { +HTTPWallet.prototype.importPublic = function importPublic(account, key) { return this.client.importPublic(this.id, account, key); }; @@ -338,7 +338,7 @@ HTTPWallet.prototype.importPublic = function importPublic(id, account, key) { * @returns {Promise} */ -HTTPWallet.prototype.importAddress = function importAddress(id, account, address) { +HTTPWallet.prototype.importAddress = function importAddress(account, address) { return this.client.importAddress(this.id, account, address); }; @@ -349,7 +349,7 @@ HTTPWallet.prototype.importAddress = function importAddress(id, account, address * @returns {Promise} */ -HTTPWallet.prototype.lockCoin = function lockCoin(id, hash, index) { +HTTPWallet.prototype.lockCoin = function lockCoin(hash, index) { return this.client.lockCoin(this.id, hash, index); }; @@ -360,7 +360,7 @@ HTTPWallet.prototype.lockCoin = function lockCoin(id, hash, index) { * @returns {Promise} */ -HTTPWallet.prototype.unlockCoin = function unlockCoin(id, hash, index) { +HTTPWallet.prototype.unlockCoin = function unlockCoin(hash, index) { return this.client.unlockCoin(this.id, hash, index); }; @@ -369,7 +369,7 @@ HTTPWallet.prototype.unlockCoin = function unlockCoin(id, hash, index) { * @returns {Promise} */ -HTTPWallet.prototype.getLocked = function getLocked(id) { +HTTPWallet.prototype.getLocked = function getLocked() { return this.client.getLocked(this.id); }; @@ -378,7 +378,7 @@ HTTPWallet.prototype.getLocked = function getLocked(id) { * @returns {Promise} */ -HTTPWallet.prototype.lock = function lock(id) { +HTTPWallet.prototype.lock = function lock() { return this.client.lock(this.id); }; @@ -389,10 +389,19 @@ HTTPWallet.prototype.lock = function lock(id) { * @returns {Promise} */ -HTTPWallet.prototype.unlock = function unlock(id, passphrase, timeout) { +HTTPWallet.prototype.unlock = function unlock(passphrase, timeout) { return this.client.unlock(this.id, passphrase, timeout); }; +/** + * Resend wallet transactions. + * @returns {Promise} + */ + +HTTPWallet.prototype.resend = function resend() { + return this.client.resendWallet(this.id); +}; + /* * Expose */