From e59fe9bf6dc4060ffd512af9c48d9bbe0d779fb1 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 10 Aug 2016 19:47:52 -0700 Subject: [PATCH] rpc: prioritisetransaction. --- lib/bcoin/http/rpc.js | 52 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/lib/bcoin/http/rpc.js b/lib/bcoin/http/rpc.js index a1325e68..eee09b8f 100644 --- a/lib/bcoin/http/rpc.js +++ b/lib/bcoin/http/rpc.js @@ -1550,7 +1550,57 @@ RPC.prototype.getnetworkhashps = function getnetworkhashps(args, callback) { }; RPC.prototype.prioritisetransaction = function prioritisetransaction(args, callback) { - callback(new RPCError('Not implemented.')); + var self = this; + var hash, pri, fee; + + if (args.help || args.length !== 3) { + return callback(new RPCError('prioritisetransaction' + + ' ')); + } + + hash = args[0]; + pri = args[1]; + fee = args[2]; + + if (!utils.isHex(hash) || hash.length !== 64) + return callback(new RPCError('Invalid parameter')); + + if (!utils.isNumber(pri) || !utils.isNumber(fee)) + return callback(new RPCError('Invalid parameter')); + + hash = utils.revHex(hash); + + this.mempool.getEntry(hash, function(err, entry) { + if (err) + return callback(err); + + if (!entry) + return callback(new RPCError('Transaction not in mempool.')); + + entry.priority += pri; + entry.fees += fee; + + if (entry.priority < 0) + entry.priority = 0; + + if (entry.fees < 0) + entry.fees = 0; + + this.mempool.fillAllCoins(entry.tx, function(err) { + if (err) + return callback(err); + + if (!entry.tx.hasCoins()) + return callback(new RPCError('Transaction not in mempool.')); + + self.mempool.addUnchecked(entry, function(err) { + if (err) + return callback(err); + + callback(null, true); + }); + }); + }); }; RPC.prototype.submitblock = function submitblock(args, callback) {