From 11975bc0df5e2670c944f2ed1bec7c5e3aff7e97 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Wed, 31 Dec 2014 01:29:36 -0300 Subject: [PATCH] Rename UTXO to Transaction.UnspentOutput --- index.js | 1 - lib/explorers/insight.js | 4 +-- lib/transaction/index.js | 1 + lib/transaction/transaction.js | 6 ++-- lib/{utxo.js => transaction/unspentoutput.js} | 32 +++++++++---------- test/utxo.js | 26 +++++++-------- 6 files changed, 35 insertions(+), 35 deletions(-) rename lib/{utxo.js => transaction/unspentoutput.js} (71%) diff --git a/index.js b/index.js index 0194dee21..aeb1df013 100644 --- a/index.js +++ b/index.js @@ -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 = {}; diff --git a/lib/explorers/insight.js b/lib/explorers/insight.js index be8313a74..87da50f5c 100644 --- a/lib/explorers/insight.js +++ b/lib/explorers/insight.js @@ -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); }); diff --git a/lib/transaction/index.js b/lib/transaction/index.js index 55db6e06b..e82663587 100644 --- a/lib/transaction/index.js +++ b/lib/transaction/index.js @@ -2,3 +2,4 @@ module.exports = require('./transaction'); module.exports.Input = require('./input'); module.exports.Output = require('./output'); +module.exports.UnspentOutput = require('./unspentoutput'); diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index 1af6b7f56..5370e2547 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -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, diff --git a/lib/utxo.js b/lib/transaction/unspentoutput.js similarity index 71% rename from lib/utxo.js rename to lib/transaction/unspentoutput.js index f77ddf3bf..3eb7af8d4 100644 --- a/lib/utxo.js +++ b/lib/transaction/unspentoutput.js @@ -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.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; diff --git a/test/utxo.js b/test/utxo.js index a5bd94e81..7c178c333 100644 --- a/test/utxo.js +++ b/test/utxo.js @@ -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 = ''; - 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()