61 lines
1.2 KiB
JavaScript
61 lines
1.2 KiB
JavaScript
/**
|
|
* output.js - output object for bcoin
|
|
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
|
* https://github.com/indutny/bcoin
|
|
*/
|
|
|
|
var bn = require('bn.js');
|
|
var bcoin = require('../bcoin');
|
|
var utils = bcoin.utils;
|
|
|
|
/**
|
|
* Output
|
|
*/
|
|
|
|
function Output(options) {
|
|
var tx = options.tx;
|
|
var value;
|
|
|
|
if (!(this instanceof Output))
|
|
return new Output(options);
|
|
|
|
if (!tx)
|
|
throw new Error('No TX passed into Input.');
|
|
|
|
value = options.value;
|
|
|
|
if (typeof value === 'number' && (value | 0) === value)
|
|
value = new bn(value);
|
|
|
|
this.value = utils.satoshi(value || new bn(0));
|
|
this.script = options.script ? options.script.slice() : [];
|
|
|
|
if (options.script && options.script._raw)
|
|
utils.hidden(this.script, '_raw', options.script._raw);
|
|
}
|
|
|
|
Output.prototype.__defineGetter__('data', function() {
|
|
return bcoin.tx.getOutputData(this);
|
|
});
|
|
|
|
Output.prototype.__defineGetter__('addr', function() {
|
|
return this.data.addr;
|
|
});
|
|
|
|
Output.prototype.__defineGetter__('type', function() {
|
|
return this.data.type;
|
|
});
|
|
|
|
Output.prototype.__defineGetter__('lock', function() {
|
|
var lock = bcoin.script.lockTime(this.script);
|
|
if (!lock)
|
|
return;
|
|
return lock.toNumber();
|
|
});
|
|
|
|
/**
|
|
* Expose
|
|
*/
|
|
|
|
module.exports = Output;
|