Rename UTXO to Transaction.UnspentOutput

This commit is contained in:
Esteban Ordano 2014-12-31 01:29:36 -03:00
parent 1cf108ab47
commit 11975bc0df
6 changed files with 35 additions and 35 deletions

View File

@ -45,7 +45,6 @@ bitcore.Script = require('./lib/script');
bitcore.Transaction = require('./lib/transaction');
bitcore.URI = require('./lib/uri');
bitcore.Unit = require('./lib/unit');
bitcore.UTXO = require('./lib/utxo');
// dependencies, subject to change
bitcore.deps = {};

View File

@ -6,7 +6,7 @@ var $ = require('../util/preconditions');
var _ = require('lodash');
var Address = require('../address');
var Transaction = require('../transaction');
var UTXO = require('../utxo');
var UnspentOutput = Transaction.UnspentOutput;
var request = require('request');
@ -44,7 +44,7 @@ Insight.prototype.getUnspentUtxos = function(addresses, callback) {
if (err || res.statusCode !== 200) {
return callback(err || res);
}
unspent = _.map(unspent, UTXO);
unspent = _.map(unspent, UnspentOutput);
return callback(null, unspent);
});

View File

@ -2,3 +2,4 @@ module.exports = require('./transaction');
module.exports.Input = require('./input');
module.exports.Output = require('./output');
module.exports.UnspentOutput = require('./unspentoutput');

View File

@ -15,7 +15,7 @@ var Signature = require('../crypto/signature');
var Sighash = require('./sighash');
var Address = require('../address');
var UTXO = require('../utxo');
var UnspentOutput = require('./unspentoutput');
var Input = require('./input');
var PublicKeyHashInput = Input.PublicKeyHash;
var MultiSigScriptHashInput = Input.MultiSigScriptHash;
@ -309,7 +309,7 @@ Transaction.prototype.from = function(utxo, pubkeys, threshold) {
};
Transaction.prototype._fromNonP2SH = function(utxo) {
utxo = new UTXO(utxo);
utxo = new UnspentOutput(utxo);
this.inputs.push(new PublicKeyHashInput({
output: new Output({
script: utxo.script,
@ -324,7 +324,7 @@ Transaction.prototype._fromNonP2SH = function(utxo) {
};
Transaction.prototype._fromMultisigUtxo = function(utxo, pubkeys, threshold) {
utxo = new UTXO(utxo);
utxo = new UnspentOutput(utxo);
this.addInput(new MultiSigScriptHashInput({
output: new Output({
script: utxo.script,

View File

@ -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;

View File

@ -6,9 +6,9 @@ var should = chai.should();
var expect = chai.expect;
var bitcore = require('..');
var UTXO = bitcore.UTXO;
var UnspentOutput = bitcore.Transaction.UnspentOutput;
describe('UTXO', function() {
describe('UnspentOutput', function() {
var sampleData1 = {
'address': 'mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1',
@ -26,16 +26,16 @@ describe('UTXO', function() {
};
it('roundtrip from raw data', function() {
expect(UTXO(sampleData2).toObject()).to.deep.equal(sampleData2);
expect(UnspentOutput(sampleData2).toObject()).to.deep.equal(sampleData2);
});
it('can be created without "new" operand', function() {
expect(UTXO(sampleData1) instanceof UTXO).to.equal(true);
expect(UnspentOutput(sampleData1) instanceof UnspentOutput).to.equal(true);
});
it('fails if no tx id is provided', function() {
expect(function() {
return new UTXO({});
return new UnspentOutput({});
}).to.throw();
});
@ -43,28 +43,28 @@ describe('UTXO', function() {
var sample = _.cloneDeep(sampleData2);
sample.vout = '1';
expect(function() {
return new UTXO(sample);
return new UnspentOutput(sample);
}).to.throw();
});
it('displays nicely on the console', function() {
var expected = '<UTXO: a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458:0' +
var expected = '<UnspentOutput: a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458:0' +
', satoshis: 1020000, address: mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1>';
expect(new UTXO(sampleData1).inspect()).to.equal(expected);
expect(new UnspentOutput(sampleData1).inspect()).to.equal(expected);
});
it('toString returns txid:vout', function() {
var expected = 'a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458:0';
expect(new UTXO(sampleData1).toString()).to.equal(expected);
expect(new UnspentOutput(sampleData1).toString()).to.equal(expected);
});
it('to/from JSON roundtrip', function() {
var utxo = new UTXO(sampleData2);
var utxo = new UnspentOutput(sampleData2);
expect(
JSON.parse(
UTXO.fromJSON(
UTXO.fromObject(
UTXO.fromJSON(
UnspentOutput.fromJSON(
UnspentOutput.fromObject(
UnspentOutput.fromJSON(
utxo.toJSON()
).toObject()
).toJSON()