input/output consistency. misc.
This commit is contained in:
parent
6b10fabc5f
commit
314c14f422
@ -174,7 +174,12 @@ Chain.prototype._addIndex = function _addIndex(entry, save) {
|
|||||||
// could be used if you want to be on the overly
|
// could be used if you want to be on the overly
|
||||||
// safe (see: paranoid) side.
|
// safe (see: paranoid) side.
|
||||||
// this.resetLastCheckpoint(entry.height);
|
// this.resetLastCheckpoint(entry.height);
|
||||||
this.emit('fork', entry.height, entry.hash, checkpoint);
|
this.emit('fork', {
|
||||||
|
height: entry.height,
|
||||||
|
expected: checkpoint,
|
||||||
|
received: entry.hash,
|
||||||
|
checkpoint: true
|
||||||
|
});
|
||||||
return Chain.codes.badCheckpoint;
|
return Chain.codes.badCheckpoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,7 +364,8 @@ Chain.prototype.add = function add(block, peer) {
|
|||||||
this.resetHeight(entry.height - 1);
|
this.resetHeight(entry.height - 1);
|
||||||
this.emit('fork', {
|
this.emit('fork', {
|
||||||
height: prevHeight + 1,
|
height: prevHeight + 1,
|
||||||
blocks: [tip.hash, entry.hash],
|
expected: tip.hash,
|
||||||
|
received: entry.hash,
|
||||||
checkpoint: null
|
checkpoint: null
|
||||||
});
|
});
|
||||||
code = Chain.codes.forked;
|
code = Chain.codes.forked;
|
||||||
|
|||||||
@ -202,7 +202,7 @@ HDPrivateKey.prototype._normalize = function _normalize(data, version) {
|
|||||||
if (data.privateKey.getPrivate)
|
if (data.privateKey.getPrivate)
|
||||||
data.privateKey = data.privateKey.getPrivate().toArray();
|
data.privateKey = data.privateKey.getPrivate().toArray();
|
||||||
else if (typeof data.privateKey === 'string')
|
else if (typeof data.privateKey === 'string')
|
||||||
data.privateKey = utils.toKeyArray(data.privateKey);
|
data.privateKey = utils.toBuffer(data.privateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public key = 33 bytes
|
// public key = 33 bytes
|
||||||
@ -210,7 +210,7 @@ HDPrivateKey.prototype._normalize = function _normalize(data, version) {
|
|||||||
if (data.publicKey.getPublic)
|
if (data.publicKey.getPublic)
|
||||||
data.publicKey = data.privateKey.getPublic(true, 'array');
|
data.publicKey = data.privateKey.getPublic(true, 'array');
|
||||||
else if (typeof data.publicKey === 'string')
|
else if (typeof data.publicKey === 'string')
|
||||||
data.publicKey = utils.toKeyArray(data.publicKey);
|
data.publicKey = utils.toBuffer(data.publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// checksum = 4 bytes
|
// checksum = 4 bytes
|
||||||
|
|||||||
@ -68,40 +68,40 @@ Input.prototype.__defineGetter__('type', function() {
|
|||||||
return this.data.type;
|
return this.data.type;
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('sig', function() {
|
Input.prototype.__defineGetter__('signature', function() {
|
||||||
return this.sigs[0];
|
return this.signatures[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('pub', function() {
|
Input.prototype.__defineGetter__('key', function() {
|
||||||
return this.data.redeem || this.pubs[0];
|
return this.data.redeem || this.keys[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('hash', function() {
|
Input.prototype.__defineGetter__('hash', function() {
|
||||||
return this.data.scripthash || this.hashes[0];
|
return this.data.scripthash || this.hashes[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('addr', function() {
|
Input.prototype.__defineGetter__('address', function() {
|
||||||
return this.data.scriptaddr || this.addrs[0] || this._id;
|
return this.data.scriptaddress || this.addresses[0] || this._id;
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('sigs', function() {
|
Input.prototype.__defineGetter__('signatures', function() {
|
||||||
return this.data.sigs || [];
|
return this.data.signatures || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('pubs', function() {
|
Input.prototype.__defineGetter__('keys', function() {
|
||||||
return this.data.pubs || [];
|
return this.data.keys || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('hashes', function() {
|
Input.prototype.__defineGetter__('hashes', function() {
|
||||||
return this.data.hashes || [];
|
return this.data.hashes || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('addrs', function() {
|
Input.prototype.__defineGetter__('addresses', function() {
|
||||||
return this.data.addrs || [];
|
return this.data.addresses || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('scriptaddr', function() {
|
Input.prototype.__defineGetter__('scriptaddress', function() {
|
||||||
return this.data.scriptaddr;
|
return this.data.scriptaddress;
|
||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype.__defineGetter__('m', function() {
|
Input.prototype.__defineGetter__('m', function() {
|
||||||
@ -149,17 +149,45 @@ Input.prototype.__defineGetter__('_id', function() {
|
|||||||
return '[' + this.type + ':' + hash.slice(0, 7) + ']';
|
return '[' + this.type + ':' + hash.slice(0, 7) + ']';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Input.prototype.__defineGetter__('addr', function() {
|
||||||
|
return this.address;
|
||||||
|
});
|
||||||
|
|
||||||
|
Input.prototype.__defineGetter__('addrs', function() {
|
||||||
|
return this.addresses;
|
||||||
|
});
|
||||||
|
|
||||||
|
Input.prototype.__defineGetter__('pub', function() {
|
||||||
|
return this.key;
|
||||||
|
});
|
||||||
|
|
||||||
|
Input.prototype.__defineGetter__('pubs', function() {
|
||||||
|
return this.keys;
|
||||||
|
});
|
||||||
|
|
||||||
|
Input.prototype.__defineGetter__('sig', function() {
|
||||||
|
return this.signature;
|
||||||
|
});
|
||||||
|
|
||||||
|
Input.prototype.__defineGetter__('sigs', function() {
|
||||||
|
return this.signatures;
|
||||||
|
});
|
||||||
|
|
||||||
|
Input.prototype.__defineGetter__('scriptaddr', function() {
|
||||||
|
return this.scriptaddress;
|
||||||
|
});
|
||||||
|
|
||||||
// Schema and defaults for data object:
|
// Schema and defaults for data object:
|
||||||
// {
|
// {
|
||||||
// type: null,
|
// type: null,
|
||||||
// side: 'input',
|
// side: 'input',
|
||||||
// sigs: [],
|
// signatures: [],
|
||||||
// pubs: [],
|
// keys: [],
|
||||||
// hashes: [],
|
// hashes: [],
|
||||||
// addrs: [],
|
// addresses: [],
|
||||||
// redeem: null,
|
// redeem: null,
|
||||||
// scripthash: null,
|
// scripthash: null,
|
||||||
// scriptaddr: null,
|
// scriptaddress: null,
|
||||||
// m: 0,
|
// m: 0,
|
||||||
// n: 0,
|
// n: 0,
|
||||||
// height: -1,
|
// height: -1,
|
||||||
@ -176,12 +204,25 @@ Input.prototype.__defineGetter__('_id', function() {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
Input.getData = function getData(input) {
|
Input.getData = function getData(input) {
|
||||||
|
var s, sub, def, signature, key, hash, address, redeem, data, output, val;
|
||||||
|
|
||||||
|
if (Array.isArray(input)) {
|
||||||
|
input = {
|
||||||
|
out: {
|
||||||
|
tx: null,
|
||||||
|
hash: utils.toHex(constants.oneHash),
|
||||||
|
index: 0
|
||||||
|
},
|
||||||
|
script: input,
|
||||||
|
seq: 0xffffffff
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!input || !input.script)
|
if (!input || !input.script)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var s = input.script;
|
s = input.script;
|
||||||
var sub = bcoin.script.subscript(input.script);
|
sub = bcoin.script.subscript(input.script);
|
||||||
var def, sig, pub, hash, addr, redeem, data, output, val;
|
|
||||||
|
|
||||||
def = {
|
def = {
|
||||||
side: 'input',
|
side: 'input',
|
||||||
@ -213,12 +254,12 @@ Input.getData = function getData(input) {
|
|||||||
output = input.out.tx.outputs[input.out.index];
|
output = input.out.tx.outputs[input.out.index];
|
||||||
data = bcoin.output.getData(output);
|
data = bcoin.output.getData(output);
|
||||||
if (data.type === 'pubkey' ) {
|
if (data.type === 'pubkey' ) {
|
||||||
data.sigs = [sub[0]];
|
data.signatures = [sub[0]];
|
||||||
} else if (data.type === 'pubkeyhash') {
|
} else if (data.type === 'pubkeyhash') {
|
||||||
data.sigs = [sub[0]];
|
data.signatures = [sub[0]];
|
||||||
data.pubs = [sub[1]];
|
data.keys = [sub[1]];
|
||||||
} else if (data.type === 'multisig') {
|
} else if (data.type === 'multisig') {
|
||||||
data.sigs = sub.slice(1);
|
data.signatures = sub.slice(1);
|
||||||
} else if (data.type === 'scripthash') {
|
} else if (data.type === 'scripthash') {
|
||||||
// We work backwards here: scripthash is one of the few cases
|
// We work backwards here: scripthash is one of the few cases
|
||||||
// where we get more data from the input than the output.
|
// where we get more data from the input than the output.
|
||||||
@ -243,39 +284,39 @@ Input.getData = function getData(input) {
|
|||||||
if (bcoin.script.isPubkeyInput(s)) {
|
if (bcoin.script.isPubkeyInput(s)) {
|
||||||
return utils.merge(def, {
|
return utils.merge(def, {
|
||||||
type: 'pubkey',
|
type: 'pubkey',
|
||||||
sigs: [sub[0]],
|
signatures: [sub[0]],
|
||||||
none: true
|
none: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bcoin.script.isPubkeyhashInput(s)) {
|
if (bcoin.script.isPubkeyhashInput(s)) {
|
||||||
pub = sub[1];
|
key = sub[1];
|
||||||
hash = utils.ripesha(pub);
|
hash = utils.ripesha(key);
|
||||||
addr = bcoin.wallet.hash2addr(hash);
|
address = bcoin.wallet.hash2addr(hash);
|
||||||
return utils.merge(def, {
|
return utils.merge(def, {
|
||||||
type: 'pubkeyhash',
|
type: 'pubkeyhash',
|
||||||
sigs: [sub[0]],
|
signatures: [sub[0]],
|
||||||
pubs: [pub],
|
keys: [key],
|
||||||
hashes: [hash],
|
hashes: [hash],
|
||||||
addrs: [addr]
|
addresses: [address]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bcoin.script.isMultisigInput(s)) {
|
if (bcoin.script.isMultisigInput(s)) {
|
||||||
sig = sub.slice(1);
|
signature = sub.slice(1);
|
||||||
return utils.merge(def, {
|
return utils.merge(def, {
|
||||||
type: 'multisig',
|
type: 'multisig',
|
||||||
sigs: sig,
|
signatures: signature,
|
||||||
m: sig.length,
|
m: signature.length,
|
||||||
none: true
|
none: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bcoin.script.isScripthashInput(s)) {
|
if (bcoin.script.isScripthashInput(s)) {
|
||||||
sig = sub.slice(1, -1);
|
signature = sub.slice(1, -1);
|
||||||
redeem = sub[sub.length - 1];
|
redeem = sub[sub.length - 1];
|
||||||
hash = utils.ripesha(redeem);
|
hash = utils.ripesha(redeem);
|
||||||
addr = bcoin.wallet.hash2addr(hash, 'scripthash');
|
address = bcoin.wallet.hash2addr(hash, 'scripthash');
|
||||||
redeem = bcoin.script.decode(redeem);
|
redeem = bcoin.script.decode(redeem);
|
||||||
data = bcoin.output.getData({
|
data = bcoin.output.getData({
|
||||||
script: redeem,
|
script: redeem,
|
||||||
@ -284,10 +325,10 @@ Input.getData = function getData(input) {
|
|||||||
return utils.merge(data, {
|
return utils.merge(data, {
|
||||||
type: 'scripthash',
|
type: 'scripthash',
|
||||||
side: 'input',
|
side: 'input',
|
||||||
sigs: sig,
|
signatures: signature,
|
||||||
redeem: redeem,
|
redeem: redeem,
|
||||||
scripthash: hash,
|
scripthash: hash,
|
||||||
scriptaddr: addr,
|
scriptaddress: address,
|
||||||
script: s,
|
script: s,
|
||||||
seq: input.seq
|
seq: input.seq
|
||||||
});
|
});
|
||||||
@ -310,9 +351,9 @@ Input.prototype.inspect = function inspect() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: this.type,
|
type: this.type,
|
||||||
addr: this.addr,
|
address: this.address,
|
||||||
sigs: this.sigs.map(utils.toHex),
|
signatures: this.signatures.map(utils.toHex),
|
||||||
pubs: this.pubs.map(utils.toHex),
|
keys: this.keys.map(utils.toHex),
|
||||||
text: this.text,
|
text: this.text,
|
||||||
lock: this.lock,
|
lock: this.lock,
|
||||||
value: utils.btc(output.value),
|
value: utils.btc(output.value),
|
||||||
|
|||||||
@ -52,40 +52,40 @@ Output.prototype.__defineGetter__('type', function() {
|
|||||||
return this.data.type;
|
return this.data.type;
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('sig', function() {
|
Output.prototype.__defineGetter__('signature', function() {
|
||||||
return this.sigs[0];
|
return this.signatures[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('pub', function() {
|
Output.prototype.__defineGetter__('key', function() {
|
||||||
return this.data.redeem || this.pubs[0];
|
return this.data.redeem || this.keys[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('hash', function() {
|
Output.prototype.__defineGetter__('hash', function() {
|
||||||
return this.data.scripthash || this.hashes[0];
|
return this.data.scripthash || this.hashes[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('addr', function() {
|
Output.prototype.__defineGetter__('address', function() {
|
||||||
return this.data.scriptaddr || this.addrs[0] || this._id;
|
return this.data.scriptaddress || this.addresses[0] || this._id;
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('sigs', function() {
|
Output.prototype.__defineGetter__('signatures', function() {
|
||||||
return this.data.sigs || [];
|
return this.data.signatures || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('pubs', function() {
|
Output.prototype.__defineGetter__('keys', function() {
|
||||||
return this.data.pubs || [];
|
return this.data.keys || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('hashes', function() {
|
Output.prototype.__defineGetter__('hashes', function() {
|
||||||
return this.data.hashes || [];
|
return this.data.hashes || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('addrs', function() {
|
Output.prototype.__defineGetter__('addresses', function() {
|
||||||
return this.data.addrs || [];
|
return this.data.addresses || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('scriptaddr', function() {
|
Output.prototype.__defineGetter__('scriptaddress', function() {
|
||||||
return this.data.scriptaddr;
|
return this.data.scriptaddress;
|
||||||
});
|
});
|
||||||
|
|
||||||
Output.prototype.__defineGetter__('m', function() {
|
Output.prototype.__defineGetter__('m', function() {
|
||||||
@ -116,17 +116,45 @@ Output.prototype.__defineGetter__('_id', function() {
|
|||||||
return '[' + this.type + ':' + hash.slice(0, 7) + ']';
|
return '[' + this.type + ':' + hash.slice(0, 7) + ']';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Output.prototype.__defineGetter__('addr', function() {
|
||||||
|
return this.address;
|
||||||
|
});
|
||||||
|
|
||||||
|
Output.prototype.__defineGetter__('addrs', function() {
|
||||||
|
return this.addresses;
|
||||||
|
});
|
||||||
|
|
||||||
|
Output.prototype.__defineGetter__('pub', function() {
|
||||||
|
return this.key;
|
||||||
|
});
|
||||||
|
|
||||||
|
Output.prototype.__defineGetter__('pubs', function() {
|
||||||
|
return this.keys;
|
||||||
|
});
|
||||||
|
|
||||||
|
Output.prototype.__defineGetter__('sig', function() {
|
||||||
|
return this.signature;
|
||||||
|
});
|
||||||
|
|
||||||
|
Output.prototype.__defineGetter__('sigs', function() {
|
||||||
|
return this.signatures;
|
||||||
|
});
|
||||||
|
|
||||||
|
Output.prototype.__defineGetter__('scriptaddr', function() {
|
||||||
|
return this.scriptaddress;
|
||||||
|
});
|
||||||
|
|
||||||
// Schema and defaults for data object:
|
// Schema and defaults for data object:
|
||||||
// {
|
// {
|
||||||
// type: null,
|
// type: null,
|
||||||
// side: 'output',
|
// side: 'output',
|
||||||
// sigs: [],
|
// signatures: [],
|
||||||
// pubs: [],
|
// keys: [],
|
||||||
// hashes: [],
|
// hashes: [],
|
||||||
// addrs: [],
|
// addresses: [],
|
||||||
// redeem: null,
|
// redeem: null,
|
||||||
// scripthash: null,
|
// scripthash: null,
|
||||||
// scriptaddr: null,
|
// scriptaddress: null,
|
||||||
// m: 0,
|
// m: 0,
|
||||||
// n: 0,
|
// n: 0,
|
||||||
// height: -1,
|
// height: -1,
|
||||||
@ -143,13 +171,21 @@ Output.prototype.__defineGetter__('_id', function() {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
Output.getData = function getData(output) {
|
Output.getData = function getData(output) {
|
||||||
|
var s, sub, lock, def, key, hash, address, keys, data;
|
||||||
|
|
||||||
|
if (Array.isArray(output)) {
|
||||||
|
output = {
|
||||||
|
script: output,
|
||||||
|
value: new bn(0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!output || !output.script)
|
if (!output || !output.script)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var s = output.script;
|
s = output.script;
|
||||||
var sub = bcoin.script.subscript(output.script);
|
sub = bcoin.script.subscript(output.script);
|
||||||
var lock = bcoin.script.lockTime(s);
|
lock = bcoin.script.lockTime(s);
|
||||||
var def, pub, hash, addr, pubs, data;
|
|
||||||
|
|
||||||
def = {
|
def = {
|
||||||
side: 'output',
|
side: 'output',
|
||||||
@ -163,41 +199,41 @@ Output.getData = function getData(output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bcoin.script.isPubkey(s)) {
|
if (bcoin.script.isPubkey(s)) {
|
||||||
pub = sub[0];
|
key = sub[0];
|
||||||
hash = utils.ripesha(pub);
|
hash = utils.ripesha(key);
|
||||||
addr = bcoin.wallet.hash2addr(hash);
|
address = bcoin.wallet.hash2addr(hash);
|
||||||
return utils.merge(def, {
|
return utils.merge(def, {
|
||||||
type: 'pubkey',
|
type: 'pubkey',
|
||||||
pubs: [pub],
|
keys: [key],
|
||||||
hashes: [hash],
|
hashes: [hash],
|
||||||
addrs: [addr]
|
addresses: [address]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bcoin.script.isPubkeyhash(s)) {
|
if (bcoin.script.isPubkeyhash(s)) {
|
||||||
hash = sub[2];
|
hash = sub[2];
|
||||||
addr = bcoin.wallet.hash2addr(hash);
|
address = bcoin.wallet.hash2addr(hash);
|
||||||
return utils.merge(def, {
|
return utils.merge(def, {
|
||||||
type: 'pubkeyhash',
|
type: 'pubkeyhash',
|
||||||
side: 'output',
|
side: 'output',
|
||||||
hashes: [hash],
|
hashes: [hash],
|
||||||
addrs: [addr]
|
addresses: [address]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pubs = bcoin.script.isMultisig(s);
|
keys = bcoin.script.isMultisig(s);
|
||||||
if (pubs) {
|
if (keys) {
|
||||||
hash = pubs.map(function(key) {
|
hash = keys.map(function(key) {
|
||||||
return utils.ripesha(key);
|
return utils.ripesha(key);
|
||||||
});
|
});
|
||||||
addr = hash.map(function(hash) {
|
address = hash.map(function(hash) {
|
||||||
return bcoin.wallet.hash2addr(hash);
|
return bcoin.wallet.hash2addr(hash);
|
||||||
});
|
});
|
||||||
return utils.merge(def, {
|
return utils.merge(def, {
|
||||||
type: 'multisig',
|
type: 'multisig',
|
||||||
pubs: pubs,
|
keys: keys,
|
||||||
hashes: hash,
|
hashes: hash,
|
||||||
addrs: addr,
|
addresses: address,
|
||||||
m: new bn(sub[0]).toNumber(),
|
m: new bn(sub[0]).toNumber(),
|
||||||
n: new bn(sub[sub.length - 2]).toNumber()
|
n: new bn(sub[sub.length - 2]).toNumber()
|
||||||
});
|
});
|
||||||
@ -205,11 +241,11 @@ Output.getData = function getData(output) {
|
|||||||
|
|
||||||
if (bcoin.script.isScripthash(s)) {
|
if (bcoin.script.isScripthash(s)) {
|
||||||
hash = sub[1];
|
hash = sub[1];
|
||||||
addr = bcoin.wallet.hash2addr(hash, 'scripthash');
|
address = bcoin.wallet.hash2addr(hash, 'scripthash');
|
||||||
return utils.merge(def, {
|
return utils.merge(def, {
|
||||||
type: 'scripthash',
|
type: 'scripthash',
|
||||||
scripthash: hash,
|
scripthash: hash,
|
||||||
scriptaddr: addr
|
scriptaddress: address
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,10 +268,10 @@ Output.getData = function getData(output) {
|
|||||||
Output.prototype.inspect = function inspect() {
|
Output.prototype.inspect = function inspect() {
|
||||||
return {
|
return {
|
||||||
type: this.type,
|
type: this.type,
|
||||||
addr: this.addr,
|
address: this.address,
|
||||||
pubs: this.pubs.map(utils.toHex),
|
keys: this.keys.map(utils.toHex),
|
||||||
hashes: this.hashes.map(utils.toHex),
|
hashes: this.hashes.map(utils.toHex),
|
||||||
addrs: this.addrs,
|
addresses: this.addresses,
|
||||||
redeem: this.type === 'scripthash'
|
redeem: this.type === 'scripthash'
|
||||||
? bcoin.script.format(this.data.redeem)[0]
|
? bcoin.script.format(this.data.redeem)[0]
|
||||||
: null,
|
: null,
|
||||||
|
|||||||
@ -173,10 +173,16 @@ Pool.prototype._init = function _init() {
|
|||||||
self.emit('block', block, peer);
|
self.emit('block', block, peer);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chain.on('fork', function(height, hash, checkpoint) {
|
this.chain.on('fork', function(data) {
|
||||||
var peer = self.peers.load;
|
var peer = self.peers.load;
|
||||||
|
|
||||||
this.emit('debug', 'Checkpoint %s failed at height %d', hash, height);
|
this.emit('debug',
|
||||||
|
'Fork at height %d: expected=%s received=%s checkpoint=%s',
|
||||||
|
data.height,
|
||||||
|
utils.revHex(data.expected),
|
||||||
|
utils.revHex(data.received),
|
||||||
|
data.checkpoint
|
||||||
|
);
|
||||||
|
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return;
|
return;
|
||||||
@ -498,13 +504,18 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
|||||||
|
|
||||||
// Make sure the block is valid
|
// Make sure the block is valid
|
||||||
if (!block.verify()) {
|
if (!block.verify()) {
|
||||||
this.emit('debug', 'Block verification failed for %s (%s)', block.rhash, peer.host);
|
this.emit('debug',
|
||||||
|
'Block verification failed for %s (%s)',
|
||||||
|
block.rhash, peer.host);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Someone is sending us blocks without us requesting them.
|
// Someone is sending us blocks without us requesting them.
|
||||||
if (!requested)
|
if (!requested) {
|
||||||
this.emit('debug', 'Recieved unrequested block: %s (%s)', block.rhash, peer.host);
|
this.emit('debug',
|
||||||
|
'Recieved unrequested block: %s (%s)',
|
||||||
|
block.rhash, peer.host);
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve orphan chain
|
// Resolve orphan chain
|
||||||
if (!this.options.headers) {
|
if (!this.options.headers) {
|
||||||
|
|||||||
@ -372,7 +372,7 @@ TX.prototype.out = TX.prototype.output;
|
|||||||
|
|
||||||
TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
||||||
var script = output.script;
|
var script = output.script;
|
||||||
var keys, m, n, hash, locktime;
|
var keys, m, n, hash, locktime, flags;
|
||||||
|
|
||||||
options = options || output;
|
options = options || output;
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.color) {
|
if (options.color) {
|
||||||
options.nulldata = options.color;
|
options.flags = options.color;
|
||||||
delete options.color;
|
delete options.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,18 +414,14 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(options.keys)) {
|
if (Array.isArray(options.keys)) {
|
||||||
// Raw multisig transaction
|
// Bare Multisig Transaction
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0010.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0010.mediawiki
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0011.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0011.mediawiki
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0019.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0019.mediawiki
|
||||||
// [required-sigs] [pubkey-hash1] [pubkey-hash2] ... [number-of-keys] checkmultisig
|
// m [key1] [key2] ... n checkmultisig
|
||||||
keys = options.keys;
|
keys = options.keys;
|
||||||
|
|
||||||
keys = keys.map(function(key) {
|
keys = keys.map(utils.toBuffer);
|
||||||
if (typeof key === 'string')
|
|
||||||
return utils.toKeyArray(key);
|
|
||||||
return key;
|
|
||||||
});
|
|
||||||
|
|
||||||
m = options.m || keys.length;
|
m = options.m || keys.length;
|
||||||
n = options.n || keys.length;
|
n = options.n || keys.length;
|
||||||
@ -438,7 +434,8 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
|||||||
|
|
||||||
script = bcoin.script.redeem(keys, m, n);
|
script = bcoin.script.redeem(keys, m, n);
|
||||||
|
|
||||||
// make it p2sh
|
// P2SH Transaction
|
||||||
|
// hash160 [hash] eq
|
||||||
if (options.scripthash) {
|
if (options.scripthash) {
|
||||||
hash = utils.ripesha(bcoin.script.encode(script));
|
hash = utils.ripesha(bcoin.script.encode(script));
|
||||||
script = [
|
script = [
|
||||||
@ -448,7 +445,7 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
} else if (bcoin.wallet.validateAddress(options.address, 'scripthash')) {
|
} else if (bcoin.wallet.validateAddress(options.address, 'scripthash')) {
|
||||||
// p2sh transaction
|
// P2SH Transaction
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki
|
||||||
// hash160 [20-byte-redeemscript-hash] equal
|
// hash160 [20-byte-redeemscript-hash] equal
|
||||||
script = [
|
script = [
|
||||||
@ -457,7 +454,7 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
|||||||
'eq'
|
'eq'
|
||||||
];
|
];
|
||||||
} else if (options.address) {
|
} else if (options.address) {
|
||||||
// p2pkh transaction
|
// P2PKH Transaction
|
||||||
// dup hash160 [pubkey-hash] equalverify checksig
|
// dup hash160 [pubkey-hash] equalverify checksig
|
||||||
script = [
|
script = [
|
||||||
'dup',
|
'dup',
|
||||||
@ -466,14 +463,24 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
|||||||
'eqverify',
|
'eqverify',
|
||||||
'checksig'
|
'checksig'
|
||||||
];
|
];
|
||||||
} else if (options.nulldata) {
|
} else if (options.key) {
|
||||||
nulldata = options.nulldata;
|
// P2PK Transaction
|
||||||
if (typeof nulldata === 'string')
|
// [pubkey] checksig
|
||||||
nulldata = utils.ascii2array(nulldata);
|
script = [
|
||||||
assert(nulldata.length <= constants.script.maxOpReturn);
|
utils.toBuffer(options.key),
|
||||||
|
'checksig'
|
||||||
|
];
|
||||||
|
} else if (options.flags) {
|
||||||
|
// Nulldata Transaction
|
||||||
|
// ret [data]
|
||||||
|
flags = options.flags;
|
||||||
|
if (typeof flags === 'string')
|
||||||
|
flags = utils.ascii2array(flags);
|
||||||
|
assert(utils.isBuffer(flags));
|
||||||
|
assert(flags.length <= constants.script.maxOpReturn);
|
||||||
script = [
|
script = [
|
||||||
'ret',
|
'ret',
|
||||||
nulldata
|
flags
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,7 +770,7 @@ TX.prototype.fillUnspent = function fillUnspent(unspent, changeAddress) {
|
|||||||
|
|
||||||
this.changeAddress = changeAddress
|
this.changeAddress = changeAddress
|
||||||
|| this.changeAddress
|
|| this.changeAddress
|
||||||
|| result.inputs[0].output.addr;
|
|| result.inputs[0].output.address;
|
||||||
|
|
||||||
result.inputs.forEach(function(input) {
|
result.inputs.forEach(function(input) {
|
||||||
this.input(input);
|
this.input(input);
|
||||||
|
|||||||
@ -683,7 +683,7 @@ utils.isBuffer = function isBuffer(msg) {
|
|||||||
return Array.isArray(msg);
|
return Array.isArray(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.toKeyArray = function toKeyArray(msg) {
|
utils.toBuffer = function toBuffer(msg) {
|
||||||
if (Array.isArray(msg))
|
if (Array.isArray(msg))
|
||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
@ -696,7 +696,7 @@ utils.toKeyArray = function toKeyArray(msg) {
|
|||||||
if (utils.isBase58(msg))
|
if (utils.isBase58(msg))
|
||||||
return utils.fromBase58(msg);
|
return utils.fromBase58(msg);
|
||||||
|
|
||||||
throw new Error('Cannot ensure array');
|
throw new Error('Cannot ensure buffer');
|
||||||
};
|
};
|
||||||
|
|
||||||
utils._inspect = function inspect(obj) {
|
utils._inspect = function inspect(obj) {
|
||||||
|
|||||||
@ -165,7 +165,7 @@ Wallet.prototype.multisig = function multisig(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.addKey = function addKey(key) {
|
Wallet.prototype.addKey = function addKey(key) {
|
||||||
key = utils.toKeyArray(key);
|
key = utils.toBuffer(key);
|
||||||
|
|
||||||
var has = this.keys.some(function(k) {
|
var has = this.keys.some(function(k) {
|
||||||
return utils.isEqual(k, key);
|
return utils.isEqual(k, key);
|
||||||
@ -180,7 +180,7 @@ Wallet.prototype.addKey = function addKey(key) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.removeKey = function removeKey(key) {
|
Wallet.prototype.removeKey = function removeKey(key) {
|
||||||
key = utils.toKeyArray(key);
|
key = utils.toBuffer(key);
|
||||||
|
|
||||||
var index = this.keys.map(function(key, i) {
|
var index = this.keys.map(function(key, i) {
|
||||||
return utils.isEqual(key, pub) ? i : null;
|
return utils.isEqual(key, pub) ? i : null;
|
||||||
@ -294,8 +294,7 @@ Wallet.prototype.getAddress = function getAddress() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Wallet.key2hash = function key2hash(key) {
|
Wallet.key2hash = function key2hash(key) {
|
||||||
if (typeof key === 'string')
|
key = utils.toBuffer(key);
|
||||||
key = utils.toKeyArray(key);
|
|
||||||
return utils.ripesha(key);
|
return utils.ripesha(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -347,7 +346,7 @@ Wallet.addr2hash = function addr2hash(addr, prefix) {
|
|||||||
return addr.slice(1, -4);
|
return addr.slice(1, -4);
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.validateAddress = function validateAddress(addr, prefix) {
|
Wallet.validateAddress = function validateAddress(addr, prefix) {
|
||||||
if (!addr)
|
if (!addr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -356,8 +355,6 @@ Wallet.prototype.validateAddress = function validateAddress(addr, prefix) {
|
|||||||
return p.length !== 0;
|
return p.length !== 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.validateAddress = Wallet.prototype.validateAddress;
|
|
||||||
|
|
||||||
Wallet.prototype.ownOutput = function ownOutput(tx, index) {
|
Wallet.prototype.ownOutput = function ownOutput(tx, index) {
|
||||||
var scriptHash = this.getFullHash();
|
var scriptHash = this.getFullHash();
|
||||||
var hash = this.getOwnHash();
|
var hash = this.getOwnHash();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user