rpc: refactor some calls.
This commit is contained in:
parent
8110c73b17
commit
0a065be686
@ -1485,15 +1485,6 @@ RPC.prototype.setGenerate = co(function* setGenerate(args, help) {
|
||||
});
|
||||
|
||||
RPC.prototype.generate = co(function* generate(args, help) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
return yield this._generate(args);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
RPC.prototype._generate = co(function* generate(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.u32(0, 1);
|
||||
var tries = valid.u32(1);
|
||||
@ -1504,19 +1495,11 @@ RPC.prototype._generate = co(function* generate(args, help) {
|
||||
return yield this.mineBlocks(blocks, null, tries);
|
||||
});
|
||||
|
||||
RPC.prototype.generateToAddress = co(function* generateToAddress(args, help) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
return yield this._generateToAddress(args);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
RPC.prototype._generateToAddress = co(function* _generateToAddress(args, help) {
|
||||
RPC.prototype.generateToAddress = co(function* _generateToAddress(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.u32(0, 1);
|
||||
var addr = valid.str(1, '');
|
||||
var tries = valid.u32(2);
|
||||
|
||||
if (help || args.length < 2 || args.length > 3) {
|
||||
throw new RPCError(errs.MISC_ERROR,
|
||||
@ -1525,7 +1508,7 @@ RPC.prototype._generateToAddress = co(function* _generateToAddress(args, help) {
|
||||
|
||||
addr = parseAddress(addr, this.network);
|
||||
|
||||
return yield this.mineBlocks(blocks, addr);
|
||||
return yield this.mineBlocks(blocks, addr, tries);
|
||||
});
|
||||
|
||||
/*
|
||||
@ -1716,7 +1699,15 @@ RPC.prototype.sendRawTransaction = co(function* sendRawTransaction(args, help) {
|
||||
RPC.prototype.signRawTransaction = co(function* signRawTransaction(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var tx;
|
||||
var prevout = valid.array(1);
|
||||
var secrets = valid.array(2);
|
||||
var sighash = valid.str(3);
|
||||
var type = Script.hashType.ALL;
|
||||
var keys = [];
|
||||
var map = {};
|
||||
var i, j, tx, secret, key, coin;
|
||||
var hash, index, script, value;
|
||||
var prev, redeem, op, parts;
|
||||
|
||||
if (help || args.length < 1 || args.length > 4) {
|
||||
throw new RPCError(errs.MISC_ERROR,
|
||||
@ -1736,22 +1727,6 @@ RPC.prototype.signRawTransaction = co(function* signRawTransaction(args, help) {
|
||||
tx = MTX.fromRaw(data);
|
||||
tx.view = yield this.mempool.getSpentView(tx);
|
||||
|
||||
return yield this._signRawTransaction(tx, args);
|
||||
});
|
||||
|
||||
RPC.prototype._signRawTransaction = co(function* _signRawTransaction(tx, args) {
|
||||
var valid = new Validator([args]);
|
||||
var prevout = valid.array(1);
|
||||
var secrets = valid.array(2);
|
||||
var sighash = valid.str(3);
|
||||
var type = Script.hashType.ALL;
|
||||
var keys = [];
|
||||
var map = {};
|
||||
var i, j, secret, key;
|
||||
var coin, prev;
|
||||
var hash, index, script, value;
|
||||
var redeem, op, parts;
|
||||
|
||||
if (secrets) {
|
||||
valid = new Validator([secrets]);
|
||||
for (i = 0; i < secrets.length; i++) {
|
||||
@ -1789,6 +1764,11 @@ RPC.prototype._signRawTransaction = co(function* _signRawTransaction(tx, args) {
|
||||
if (!script.isScripthash() && !script.isWitnessScripthash())
|
||||
continue;
|
||||
|
||||
if (!redeem) {
|
||||
throw new RPCError(errs.INVALID_PARAMETER,
|
||||
'P2SH requires redeem script.');
|
||||
}
|
||||
|
||||
redeem = Script.fromRaw(redeem);
|
||||
|
||||
for (j = 0; j < redeem.code.length; j++) {
|
||||
@ -2446,6 +2426,15 @@ RPC.prototype.getHashRate = co(function* getHashRate(lookup, height) {
|
||||
});
|
||||
|
||||
RPC.prototype.mineBlocks = co(function* mineBlocks(blocks, address, tries) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
return yield this._mineBlocks(blocks, address, tries);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
RPC.prototype._mineBlocks = co(function* _mineBlocks(blocks, address, tries) {
|
||||
var hashes = [];
|
||||
var i, block;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user