more worker serialization.
This commit is contained in:
parent
678da4671a
commit
33d2803d4c
@ -240,6 +240,38 @@ Workers.prototype.verify = function verify(tx, flags, callback) {
|
||||
return this.execute('verify', [tx, flags], -1, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute the tx signing job (default timeout).
|
||||
* @param {KeyRing[]} addresses
|
||||
* @param {HDPrivateKey} master
|
||||
* @param {MTX} tx
|
||||
* @param {Number?} index
|
||||
* @param {SighashType?} type
|
||||
* @param {Function} callback
|
||||
*/
|
||||
|
||||
Workers.prototype.sign = function sign(addresses, master, tx, index, type, callback) {
|
||||
var args = [addresses, master, tx, index, type];
|
||||
var i, input, sig, sigs, total;
|
||||
|
||||
return this.execute('sign', args, -1, function(err, result) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
sigs = result[0];
|
||||
total = result[1];
|
||||
|
||||
for (i = 0; i < sigs.length; i++) {
|
||||
sig = sigs[i];
|
||||
input = tx.inputs[i];
|
||||
input.script = sig[0];
|
||||
input.witness = sig[1];
|
||||
}
|
||||
|
||||
return callback(null, total);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute the mining job (no timeout).
|
||||
* @param {MinerBlock} attempt
|
||||
@ -720,6 +752,29 @@ jobs.verify = function verify(tx, flags) {
|
||||
return tx.verify(flags);
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute Wallet.sign() on worker.
|
||||
* @see Wallet.sign
|
||||
* @param {KeyRing[]} addresses
|
||||
* @param {HDPrivateKey} master
|
||||
* @param {MTX} tx
|
||||
* @param {Number?} index
|
||||
* @param {SighashType?} type
|
||||
*/
|
||||
|
||||
jobs.sign = function sign(addresses, master, tx, index, type) {
|
||||
var total = bcoin.wallet.sign(addresses, master, tx, index, type);
|
||||
var sigs = [];
|
||||
var i, input;
|
||||
|
||||
for (i = 0; i < tx.inputs.length; i++) {
|
||||
input = tx.inputs[i];
|
||||
sigs.push([input.script, input.witness]);
|
||||
}
|
||||
|
||||
return [sigs, total];
|
||||
};
|
||||
|
||||
/**
|
||||
* Mine a block on worker.
|
||||
* @param {Object} attempt - Naked {@link MinerBlock}.
|
||||
@ -814,6 +869,9 @@ Framer.item = function _item(item, writer) {
|
||||
if (item instanceof bcoin.block) {
|
||||
p.writeU8(40);
|
||||
item.toRaw(p);
|
||||
} else if (item instanceof bcoin.mtx) {
|
||||
p.writeU8(46);
|
||||
item.toExtended(true, p);
|
||||
} else if (item instanceof bcoin.tx) {
|
||||
p.writeU8(41);
|
||||
item.toExtended(true, p);
|
||||
@ -829,6 +887,18 @@ Framer.item = function _item(item, writer) {
|
||||
} else if (item instanceof bcoin.minerblock) {
|
||||
p.writeU8(45);
|
||||
item.toRaw(p);
|
||||
} else if (item instanceof bcoin.keyring) {
|
||||
p.writeU8(47);
|
||||
item.toRaw(p);
|
||||
} else if (item instanceof bcoin.hd) {
|
||||
p.writeU8(48);
|
||||
p.writeBytes(item.toRaw());
|
||||
} else if (item instanceof bcoin.script) {
|
||||
p.writeU8(49);
|
||||
p.writeVarBytes(item.toRaw());
|
||||
} else if (item instanceof bcoin.witness) {
|
||||
p.writeU8(50);
|
||||
item.toRaw(p);
|
||||
} else if (bn.isBN(item)) {
|
||||
p.writeU8(10);
|
||||
p.writeVarBytes(item.toArrayLike(Buffer));
|
||||
@ -996,6 +1066,16 @@ Parser.parseItem = function parseItem(data) {
|
||||
return bcoin.mempoolentry.fromRaw(p);
|
||||
case 45:
|
||||
return bcoin.minerblock.fromRaw(p);
|
||||
case 46:
|
||||
return bcoin.mtx.fromExtended(p, true);
|
||||
case 47:
|
||||
return bcoin.keyring.fromRaw(p);
|
||||
case 48:
|
||||
return bcoin.hd.fromRaw(p.readBytes(82));
|
||||
case 49:
|
||||
return bcoin.script.fromRaw(p.readVarBytes());
|
||||
case 50:
|
||||
return bcoin.witness.fromRaw(p);
|
||||
default:
|
||||
throw new Error('Bad type.');
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user