add ids to inputs and outputs without addresses.
This commit is contained in:
parent
f3ae1c517a
commit
cf9e11e356
@ -98,6 +98,17 @@ Input.prototype.__defineGetter__('tx', function() {
|
|||||||
return this.out.tx;
|
return this.out.tx;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Input.prototype._id = function _id(prefix) {
|
||||||
|
var data = [].concat(
|
||||||
|
this.out.hash,
|
||||||
|
this.out.index,
|
||||||
|
bcoin.script.encode(this.script),
|
||||||
|
this.seq
|
||||||
|
);
|
||||||
|
var hash = utils.toHex(utils.dsha256(data));
|
||||||
|
return '[' + prefix + ':' + hash.slice(0, 7) + ']';
|
||||||
|
};
|
||||||
|
|
||||||
Input.getData = function getData(input) {
|
Input.getData = function getData(input) {
|
||||||
if (!input || !input.script)
|
if (!input || !input.script)
|
||||||
return;
|
return;
|
||||||
@ -136,7 +147,7 @@ Input.getData = function getData(input) {
|
|||||||
if (!input.out) {
|
if (!input.out) {
|
||||||
return utils.merge(schema, {
|
return utils.merge(schema, {
|
||||||
type: 'unknown',
|
type: 'unknown',
|
||||||
addr: '[unknown]',
|
addr: input._id('unknown'),
|
||||||
none: true
|
none: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -147,7 +158,7 @@ Input.getData = function getData(input) {
|
|||||||
type: 'coinbase',
|
type: 'coinbase',
|
||||||
coinbase: data,
|
coinbase: data,
|
||||||
height: data.height || -1,
|
height: data.height || -1,
|
||||||
addr: '[coinbase]',
|
addr: input._id('coinbase'),
|
||||||
flags: data.flags,
|
flags: data.flags,
|
||||||
text: data.text.join(''),
|
text: data.text.join(''),
|
||||||
none: true
|
none: true
|
||||||
@ -179,7 +190,7 @@ Input.getData = function getData(input) {
|
|||||||
return utils.merge(schema, {
|
return utils.merge(schema, {
|
||||||
type: 'pubkey',
|
type: 'pubkey',
|
||||||
sig: sub[0],
|
sig: sub[0],
|
||||||
addr: '[unknown]',
|
addr: input._id('unknown'),
|
||||||
none: true
|
none: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -225,7 +236,7 @@ Input.getData = function getData(input) {
|
|||||||
return utils.merge(schema, {
|
return utils.merge(schema, {
|
||||||
type: 'multisig',
|
type: 'multisig',
|
||||||
sig: sub[0],
|
sig: sub[0],
|
||||||
addr: '[unknown]',
|
addr: input._id('unknown'),
|
||||||
multisig: {
|
multisig: {
|
||||||
m: sig.length,
|
m: sig.length,
|
||||||
n: null,
|
n: null,
|
||||||
@ -240,7 +251,7 @@ Input.getData = function getData(input) {
|
|||||||
|
|
||||||
return utils.merge(schema, {
|
return utils.merge(schema, {
|
||||||
type: 'unknown',
|
type: 'unknown',
|
||||||
addr: '[unknown]',
|
addr: input._id('unknown'),
|
||||||
none: true
|
none: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -67,6 +67,15 @@ Output.prototype.__defineGetter__('text', function() {
|
|||||||
return this.data.text;
|
return this.data.text;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Output.prototype._id = function _id(prefix) {
|
||||||
|
var data = [].concat(
|
||||||
|
this.value.toArray(),
|
||||||
|
bcoin.script.encode(this.script)
|
||||||
|
);
|
||||||
|
var hash = utils.toHex(utils.dsha256(data));
|
||||||
|
return '[' + prefix + ':' + hash.slice(0, 7) + ']';
|
||||||
|
};
|
||||||
|
|
||||||
Output.getData = function getData(output) {
|
Output.getData = function getData(output) {
|
||||||
if (!output || !output.script)
|
if (!output || !output.script)
|
||||||
return;
|
return;
|
||||||
@ -178,7 +187,7 @@ Output.getData = function getData(output) {
|
|||||||
ret = bcoin.script.colored(s);
|
ret = bcoin.script.colored(s);
|
||||||
return utils.merge(schema, {
|
return utils.merge(schema, {
|
||||||
type: 'colored',
|
type: 'colored',
|
||||||
addr: '[colored]',
|
addr: output._id('colored'),
|
||||||
flags: ret,
|
flags: ret,
|
||||||
text: utils.array2utf8(ret),
|
text: utils.array2utf8(ret),
|
||||||
value: output.value,
|
value: output.value,
|
||||||
@ -188,7 +197,7 @@ Output.getData = function getData(output) {
|
|||||||
|
|
||||||
return utils.merge(schema, {
|
return utils.merge(schema, {
|
||||||
type: 'unknown',
|
type: 'unknown',
|
||||||
addr: '[unknown]',
|
addr: output._id('unknown'),
|
||||||
none: true
|
none: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user