rpc: fundrawtransaction.

This commit is contained in:
Christopher Jeffrey 2016-08-10 18:50:32 -07:00
parent 1fca8fe645
commit f0c9f1ba81
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1933,7 +1933,46 @@ function mergeSigs(a, b) {
}
RPC.prototype.fundrawtransaction = function fundrawtransaction(args, callback) {
callback(new Error('Not implemented.'));
var tx, options, changeAddress, feeRate;
if (args.help || args.length < 1 || args.length > 2) {
return callback(new RPCError('fundrawtransaction'
+ ' "hexstring" ( options )'));
}
if (!utils.isHex(args[0]))
return callback(new RPCError('Invalid parameter.'));
tx = bcoin.mtx.fromRaw(args[0], 'hex');
if (tx.outputs.length === 0)
return callback(new RPCError('TX must have at least one output.'));
if (args.length === 2 && args[1]) {
options = args[1];
changeAddress = options.changeAddress;
if (changeAddress)
changeAddress = bcoin.address.fromBase58(String(changeAddress));
feeRate = options.feeRate;
if (feeRate != null)
feeRate = utils.satoshi(feeRate + '');
}
options = {
rate: feeRate,
changeAddress: changeAddress
};
this.wallet.fund(tx, options, function(err) {
if (err)
return callback(err);
callback(null, {
hex: tx.toRaw().toString('hex'),
changepos: tx.changeIndex,
fee: +utils.btc(tx.getFee())
});
});
};
RPC.prototype._createRedeem = function _createRedeem(args, callback) {