refactor script and wallet. better redeem script error.
This commit is contained in:
parent
c0d0423f14
commit
87d4d4b0ad
@ -844,9 +844,9 @@ script.exec = function exec(input, output, tx, i, recurse) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
script.multisig = function multisig(keys, m, n) {
|
script.redeem = function redeem(keys, m, n) {
|
||||||
if (keys.length !== n)
|
if (keys.length !== n)
|
||||||
throw new Error('Wrong amount of pubkeys for multisig script');
|
throw new Error(n + ' keys are required to generate redeem script');
|
||||||
|
|
||||||
assert(m >= 1 && m <= n);
|
assert(m >= 1 && m <= n);
|
||||||
assert(n >= 1 && n <= 15);
|
assert(n >= 1 && n <= 15);
|
||||||
@ -1079,7 +1079,7 @@ script.isMultisigInput = function isMultisigInput(s, pubs, tx, i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pubs && pubs.length >= 2) {
|
if (pubs && pubs.length >= 2) {
|
||||||
o = script.multisig(pubs, 2, pubs.length);
|
o = script.redeem(pubs, 2, pubs.length);
|
||||||
return script.exec(s, o, tx, i);
|
return script.exec(s, o, tx, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -486,7 +486,7 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
|||||||
else
|
else
|
||||||
assert(n >= 1 && n <= 3);
|
assert(n >= 1 && n <= 3);
|
||||||
|
|
||||||
script = bcoin.script.multisig(keys, m, n);
|
script = bcoin.script.redeem(keys, m, n);
|
||||||
|
|
||||||
// make it p2sh
|
// make it p2sh
|
||||||
if (options.scripthash) {
|
if (options.scripthash) {
|
||||||
|
|||||||
@ -35,9 +35,7 @@ function Wallet(options, passphrase) {
|
|||||||
options = {};
|
options = {};
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.compressed = typeof options.compressed !== 'undefined'
|
this.compressed = options.compressed !== false;
|
||||||
? options.compressed
|
|
||||||
: true;
|
|
||||||
this.storage = options.storage;
|
this.storage = options.storage;
|
||||||
this.label = options.label || '';
|
this.label = options.label || '';
|
||||||
this.key = null;
|
this.key = null;
|
||||||
@ -160,9 +158,6 @@ Wallet.prototype.multisig = function multisig(options) {
|
|||||||
|
|
||||||
if (this.n < 1 || this.n > this.nmax)
|
if (this.n < 1 || this.n > this.nmax)
|
||||||
throw new Error('n ranges between 1 and ' + this.nmax);
|
throw new Error('n ranges between 1 and ' + this.nmax);
|
||||||
|
|
||||||
if (this.keys.length > this.n)
|
|
||||||
throw new Error('No more than ' + this.n + ' keys are necessary');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.addKey = function addKey(key) {
|
Wallet.prototype.addKey = function addKey(key) {
|
||||||
@ -177,9 +172,6 @@ Wallet.prototype.addKey = function addKey(key) {
|
|||||||
|
|
||||||
this.keys.push(key);
|
this.keys.push(key);
|
||||||
|
|
||||||
if (this.keys.length > this.n)
|
|
||||||
throw new Error('No more than ' + this.n + ' keys are necessary');
|
|
||||||
|
|
||||||
this.keys = utils.sortKeys(this.keys);
|
this.keys = utils.sortKeys(this.keys);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -215,11 +207,11 @@ Wallet.prototype.getPrivateKey = function getPrivateKey(enc) {
|
|||||||
var priv = this.key.getPrivate();
|
var priv = this.key.getPrivate();
|
||||||
var arr, chk;
|
var arr, chk;
|
||||||
|
|
||||||
if (priv)
|
if (!priv)
|
||||||
priv = priv.toArray();
|
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
priv = priv.toArray();
|
||||||
|
|
||||||
if (!enc)
|
if (!enc)
|
||||||
return priv;
|
return priv;
|
||||||
|
|
||||||
@ -247,12 +239,8 @@ Wallet.prototype.getPrivateKey = function getPrivateKey(enc) {
|
|||||||
Wallet.prototype.getFullPublicKey = function getFullPublicKey(enc) {
|
Wallet.prototype.getFullPublicKey = function getFullPublicKey(enc) {
|
||||||
var pub = this.getOwnPublicKey();
|
var pub = this.getOwnPublicKey();
|
||||||
|
|
||||||
if (this.type === 'scripthash') {
|
if (this.type === 'scripthash')
|
||||||
if (this.n !== this.keys.length)
|
pub = bcoin.script.encode(bcoin.script.redeem(this.keys, this.m, this.n));
|
||||||
throw new Error('Not enough keys to generate address');
|
|
||||||
|
|
||||||
pub = bcoin.script.encode(bcoin.script.multisig(this.keys, this.m, this.n));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enc === 'base58')
|
if (enc === 'base58')
|
||||||
return utils.toBase58(pub);
|
return utils.toBase58(pub);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user