input and output getters.

This commit is contained in:
Christopher Jeffrey 2015-12-24 12:15:30 -08:00
parent 6ceeb6800b
commit 1f8bf8c377
2 changed files with 14 additions and 18 deletions

View File

@ -73,17 +73,15 @@ Input.prototype.__defineGetter__('sig', function() {
});
Input.prototype.__defineGetter__('pub', function() {
return this.pubs[0];
return this.data.redeem || this.pubs[0];
});
Input.prototype.__defineGetter__('hash', function() {
return this.hashes[0];
return this.data.scripthash || this.hashes[0];
});
Input.prototype.__defineGetter__('addr', function() {
return this.data.scriptaddr
|| this.addrs[0]
|| this._id(this.type);
return this.data.scriptaddr || this.addrs[0] || this._id;
});
Input.prototype.__defineGetter__('sigs', function() {
@ -107,7 +105,7 @@ Input.prototype.__defineGetter__('m', function() {
});
Input.prototype.__defineGetter__('n', function() {
return this.data.n || this.data.m || 1;
return this.data.n || this.data.m;
});
Input.prototype.__defineGetter__('lock', function() {
@ -136,7 +134,7 @@ Input.prototype.__defineGetter__('tx', function() {
return this.out.tx;
});
Input.prototype._id = function _id(prefix) {
Input.prototype.__defineGetter__('_id', function() {
var data = [].concat(
this.out.hash,
this.out.index,
@ -144,8 +142,8 @@ Input.prototype._id = function _id(prefix) {
this.seq
);
var hash = utils.toHex(utils.dsha256(data));
return '[' + prefix + ':' + hash.slice(0, 7) + ']';
};
return '[' + this.type + ':' + hash.slice(0, 7) + ']';
});
// Schema and defaults for data object:
// {

View File

@ -57,17 +57,15 @@ Output.prototype.__defineGetter__('sig', function() {
});
Output.prototype.__defineGetter__('pub', function() {
return this.pubs[0];
return this.data.redeem || this.pubs[0];
});
Output.prototype.__defineGetter__('hash', function() {
return this.hashes[0];
return this.data.scripthash || this.hashes[0];
});
Output.prototype.__defineGetter__('addr', function() {
return this.data.scriptaddr
|| this.addrs[0]
|| this._id(this.type);
return this.data.scriptaddr || this.addrs[0] || this._id;
});
Output.prototype.__defineGetter__('sigs', function() {
@ -91,7 +89,7 @@ Output.prototype.__defineGetter__('m', function() {
});
Output.prototype.__defineGetter__('n', function() {
return this.data.n || this.data.m || 1;
return this.data.n || this.data.m;
});
Output.prototype.__defineGetter__('lock', function() {
@ -105,14 +103,14 @@ Output.prototype.__defineGetter__('text', function() {
return this.data.text;
});
Output.prototype._id = function _id(prefix) {
Output.prototype.__defineGetter__('_id', function() {
var data = [].concat(
this.value.toArray(),
bcoin.script.encode(this.script)
);
var hash = utils.toHex(utils.dsha256(data));
return '[' + prefix + ':' + hash.slice(0, 7) + ']';
};
return '[' + this.type + ':' + hash.slice(0, 7) + ']';
});
// Schema and defaults for data object:
// {