|
|
@ -1,18 +1,18 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
var _ = require('lodash'); |
|
|
|
var $ = require('./util/preconditions'); |
|
|
|
var JSUtil = require('./util/js'); |
|
|
|
var $ = require('../util/preconditions'); |
|
|
|
var JSUtil = require('../util/js'); |
|
|
|
|
|
|
|
var Script = require('./script'); |
|
|
|
var Address = require('./address'); |
|
|
|
var Unit = require('./unit'); |
|
|
|
var Script = require('../script'); |
|
|
|
var Address = require('../address'); |
|
|
|
var Unit = require('../unit'); |
|
|
|
|
|
|
|
function UTXO(data) { |
|
|
|
function UnspentOutput(data) { |
|
|
|
/* jshint maxcomplexity: 20 */ |
|
|
|
/* jshint maxstatements: 20 */ |
|
|
|
if (!(this instanceof UTXO)) { |
|
|
|
return new UTXO(data); |
|
|
|
if (!(this instanceof UnspentOutput)) { |
|
|
|
return new UnspentOutput(data); |
|
|
|
} |
|
|
|
$.checkArgument(_.isObject(data), 'Must provide an object from where to extract data'); |
|
|
|
var address = data.address ? new Address(data.address) : undefined; |
|
|
@ -39,27 +39,27 @@ function UTXO(data) { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
UTXO.prototype.inspect = function() { |
|
|
|
return '<UTXO: ' + this.txId + ':' + this.outputIndex + |
|
|
|
UnspentOutput.prototype.inspect = function() { |
|
|
|
return '<UnspentOutput: ' + this.txId + ':' + this.outputIndex + |
|
|
|
', satoshis: ' + this.satoshis + ', address: ' + this.address + '>'; |
|
|
|
}; |
|
|
|
|
|
|
|
UTXO.prototype.toString = function() { |
|
|
|
UnspentOutput.prototype.toString = function() { |
|
|
|
return this.txId + ':' + this.outputIndex; |
|
|
|
}; |
|
|
|
|
|
|
|
UTXO.fromJSON = UTXO.fromObject = function(data) { |
|
|
|
UnspentOutput.fromJSON = UnspentOutput.fromObject = function(data) { |
|
|
|
if (JSUtil.isValidJSON(data)) { |
|
|
|
data = JSON.parse(data); |
|
|
|
} |
|
|
|
return new UTXO(data); |
|
|
|
return new UnspentOutput(data); |
|
|
|
}; |
|
|
|
|
|
|
|
UTXO.prototype.toJSON = function() { |
|
|
|
UnspentOutput.prototype.toJSON = function() { |
|
|
|
return JSON.stringify(this.toObject()); |
|
|
|
}; |
|
|
|
|
|
|
|
UTXO.prototype.toObject = function() { |
|
|
|
UnspentOutput.prototype.toObject = function() { |
|
|
|
return { |
|
|
|
address: this.address.toString(), |
|
|
|
txid: this.txId, |
|
|
@ -69,4 +69,4 @@ UTXO.prototype.toObject = function() { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = UTXO; |
|
|
|
module.exports = UnspentOutput; |