Merge pull request #37 from matiu/feature/complete-api
Feature/complete api
This commit is contained in:
commit
886ca83c3c
|
@ -24,25 +24,39 @@ function spec() {
|
||||||
this.addrStr = addrStr;
|
this.addrStr = addrStr;
|
||||||
} catch(e){
|
} catch(e){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Object.defineProperty(this, "totalSent", {
|
||||||
|
get: function() {
|
||||||
|
return parseFloat(this.totalSentSat) / parseFloat(BitcoreUtil.COIN);
|
||||||
|
},
|
||||||
|
set: function(i) {
|
||||||
|
totalSentSat = i * BitcoreUtil.COIN;
|
||||||
|
},
|
||||||
|
enumerable: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(this, "balance", {
|
||||||
|
get: function() {
|
||||||
|
return parseFloat(this.balanceSat) / parseFloat(BitcoreUtil.COIN);
|
||||||
|
},
|
||||||
|
set: function(i) {
|
||||||
|
balance = i * BitcoreUtil.COIN;
|
||||||
|
},
|
||||||
|
enumerable: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(this, "totalReceived", {
|
||||||
|
get: function() {
|
||||||
|
return parseFloat(this.totalReceivedSat) / parseFloat(BitcoreUtil.COIN);
|
||||||
|
},
|
||||||
|
set: function(i) {
|
||||||
|
totalReceived = i * BitcoreUtil.COIN;
|
||||||
|
},
|
||||||
|
enumerable: 1,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Address.prototype.__defineGetter__('balance', function(){
|
|
||||||
return parseFloat(this.balanceSat) / parseFloat(BitcoreUtil.COIN);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Address.prototype.__defineGetter__('totalReceived', function(){
|
|
||||||
return parseFloat(this.totalReceivedSat) / parseFloat(BitcoreUtil.COIN);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Address.prototype.__defineGetter__('totalSent', function(){
|
|
||||||
return parseFloat(this.totalSentSat) / parseFloat(BitcoreUtil.COIN);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Address.prototype.update = function(next) {
|
Address.prototype.update = function(next) {
|
||||||
|
|
||||||
if (! this.addrStr) {
|
if (! this.addrStr) {
|
||||||
|
|
|
@ -5,7 +5,10 @@
|
||||||
*/
|
*/
|
||||||
var mongoose = require('mongoose'),
|
var mongoose = require('mongoose'),
|
||||||
Schema = mongoose.Schema,
|
Schema = mongoose.Schema,
|
||||||
|
bignum = require('bignum'),
|
||||||
RpcClient = require('bitcore/RpcClient').class(),
|
RpcClient = require('bitcore/RpcClient').class(),
|
||||||
|
util = require('bitcore/util/util'),
|
||||||
|
BitcoreBlock= require('bitcore/Block').class(),
|
||||||
config = require('../../config/config')
|
config = require('../../config/config')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -26,7 +29,6 @@ var BlockSchema = new Schema({
|
||||||
fromP2P: Boolean,
|
fromP2P: Boolean,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validations
|
* Validations
|
||||||
*/
|
*/
|
||||||
|
@ -82,6 +84,8 @@ BlockSchema.methods.getInfo = function (next) {
|
||||||
|
|
||||||
that.info = blockInfo.result;
|
that.info = blockInfo.result;
|
||||||
|
|
||||||
|
that.info.reward = BitcoreBlock.getBlockValue(that.info.height) / util.COIN ;
|
||||||
|
|
||||||
//console.log("THAT", that);
|
//console.log("THAT", that);
|
||||||
return next(null, that.info);
|
return next(null, that.info);
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,7 @@ var mongoose = require('mongoose'),
|
||||||
RpcClient = require('bitcore/RpcClient').class(),
|
RpcClient = require('bitcore/RpcClient').class(),
|
||||||
Transaction = require('bitcore/Transaction').class(),
|
Transaction = require('bitcore/Transaction').class(),
|
||||||
Address = require('bitcore/Address').class(),
|
Address = require('bitcore/Address').class(),
|
||||||
|
BitcoreBlock= require('bitcore/Block').class(),
|
||||||
networks = require('bitcore/networks'),
|
networks = require('bitcore/networks'),
|
||||||
util = require('bitcore/util/util'),
|
util = require('bitcore/util/util'),
|
||||||
bignum = require('bignum'),
|
bignum = require('bignum'),
|
||||||
|
@ -296,9 +297,17 @@ TransactionSchema.methods.queryInfo = function (next) {
|
||||||
that.info.valueIn = valueIn / util.COIN;
|
that.info.valueIn = valueIn / util.COIN;
|
||||||
that.info.feeds = (valueIn - valueOut) / util.COIN;
|
that.info.feeds = (valueIn - valueOut) / util.COIN;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var reward = BitcoreBlock.getBlockValue(that.info.height) / util.COIN;
|
||||||
|
that.info.vin[0].reward = reward;
|
||||||
|
that.info.valueIn = reward;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
that.info.size = b.length;
|
that.info.size = b.length;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return next(err, that.info);
|
return next(err, that.info);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,6 +40,8 @@ describe('Address balances', function(){
|
||||||
if (v.balance) assert.equal(v.balance, a.balance);
|
if (v.balance) assert.equal(v.balance, a.balance);
|
||||||
if (v.totalReceived) assert.equal(v.totalReceived, a.totalReceived);
|
if (v.totalReceived) assert.equal(v.totalReceived, a.totalReceived);
|
||||||
if (v.totalSent) assert.equal(v.totalSent, a.totalSent);
|
if (v.totalSent) assert.equal(v.totalSent, a.totalSent);
|
||||||
|
|
||||||
|
|
||||||
if (v.transactions) {
|
if (v.transactions) {
|
||||||
|
|
||||||
v.transactions.forEach( function(tx) {
|
v.transactions.forEach( function(tx) {
|
||||||
|
|
Loading…
Reference in New Issue