add ids to inputs and outputs without addresses.

This commit is contained in:
Christopher Jeffrey 2015-12-23 20:09:14 -08:00
parent f3ae1c517a
commit cf9e11e356
2 changed files with 27 additions and 7 deletions

View File

@ -98,6 +98,17 @@ Input.prototype.__defineGetter__('tx', function() {
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) {
if (!input || !input.script)
return;
@ -136,7 +147,7 @@ Input.getData = function getData(input) {
if (!input.out) {
return utils.merge(schema, {
type: 'unknown',
addr: '[unknown]',
addr: input._id('unknown'),
none: true
});
}
@ -147,7 +158,7 @@ Input.getData = function getData(input) {
type: 'coinbase',
coinbase: data,
height: data.height || -1,
addr: '[coinbase]',
addr: input._id('coinbase'),
flags: data.flags,
text: data.text.join(''),
none: true
@ -179,7 +190,7 @@ Input.getData = function getData(input) {
return utils.merge(schema, {
type: 'pubkey',
sig: sub[0],
addr: '[unknown]',
addr: input._id('unknown'),
none: true
});
}
@ -225,7 +236,7 @@ Input.getData = function getData(input) {
return utils.merge(schema, {
type: 'multisig',
sig: sub[0],
addr: '[unknown]',
addr: input._id('unknown'),
multisig: {
m: sig.length,
n: null,
@ -240,7 +251,7 @@ Input.getData = function getData(input) {
return utils.merge(schema, {
type: 'unknown',
addr: '[unknown]',
addr: input._id('unknown'),
none: true
});
};

View File

@ -67,6 +67,15 @@ Output.prototype.__defineGetter__('text', function() {
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) {
if (!output || !output.script)
return;
@ -178,7 +187,7 @@ Output.getData = function getData(output) {
ret = bcoin.script.colored(s);
return utils.merge(schema, {
type: 'colored',
addr: '[colored]',
addr: output._id('colored'),
flags: ret,
text: utils.array2utf8(ret),
value: output.value,
@ -188,7 +197,7 @@ Output.getData = function getData(output) {
return utils.merge(schema, {
type: 'unknown',
addr: '[unknown]',
addr: output._id('unknown'),
none: true
});
};