rpc: fundrawtransaction.
This commit is contained in:
parent
1fca8fe645
commit
f0c9f1ba81
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user