more http api.

This commit is contained in:
Christopher Jeffrey 2016-06-02 11:44:27 -07:00
parent dd9fb535fa
commit e330317b5c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 52 additions and 3 deletions

View File

@ -317,7 +317,7 @@ function zap(callback) {
client.walletZap(id, argv.account, age, function(err) {
if (err)
return callback(err);
utils.print('zapped');
utils.print('Zapped!');
callback();
});
}
@ -335,8 +335,12 @@ function broadcast(callback) {
function view(callback) {
var tx = bcoin.tx.fromRaw(argv.args[0] || argv.tx, 'hex');
utils.print(tx);
callback();
client.walletFill(tx, function(err, tx) {
if (err)
return callback(err);
utils.print(tx);
callback();
});
}
function main(callback) {

View File

@ -911,6 +911,31 @@ HTTPClient.prototype.walletSign = function walletCreate(id, tx, options, callbac
});
};
/**
* Fill a transaction with coins.
* @param {TX} tx
* @param {Function} callback - Returns [Error, {@link TX}].
*/
HTTPClient.prototype.walletFill = function walletFill(tx, callback) {
var body = { tx: tx.toRaw('hex') };
callback = utils.ensure(callback);
return this._post('/wallet/_/fill', body, function(err, body) {
if (err)
return callback(err);
try {
body = bcoin.tx.fromJSON(body);
} catch (e) {
return callback(e);
}
return callback(null, body);
});
};
/**
* @param {WalletID} id
* @param {Number} now - Current time.

View File

@ -466,6 +466,18 @@ HTTPServer.prototype._init = function _init() {
});
});
// Fill TX
this.post('/wallet/:id/fill', function(req, res, next, send) {
var tx = req.options.tx;
self.walletdb.fillHistory(tx, function(err) {
if (err)
return next(err);
send(200, tx.toJSON());
});
});
// Zap Wallet TXs
this.post('/wallet/:id/zap', function(req, res, next, send) {
var id = req.options.id;

View File

@ -193,6 +193,14 @@ HTTPWallet.prototype.sign = function sign(tx, options, callback) {
return this.client.walletSign(this.id, tx, options, callback);
};
/**
* @see Wallet#fillCoins
*/
HTTPWallet.prototype.fillCoins = function fillCoins(tx, callback) {
return this.client.walletFill(tx, callback);
};
/**
* @see HTTPClient#getWallet
*/