diff --git a/app/controllers/addresses.js b/app/controllers/addresses.js index e13000c..09dd17c 100644 --- a/app/controllers/addresses.js +++ b/app/controllers/addresses.js @@ -31,6 +31,10 @@ exports.address = function(req, res, next, addr) { */ exports.show = function(req, res) { if (req.address) { + +console.log(req.address); +console.log(req.address.totalSent); +console.log(JSON.stringify(req.address)); res.jsonp(req.address); } }; diff --git a/app/models/Address.js b/app/models/Address.js index b01cc2d..dd6da83 100644 --- a/app/models/Address.js +++ b/app/models/Address.js @@ -24,25 +24,39 @@ function spec() { this.addrStr = addrStr; } 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) { if (! this.addrStr) { diff --git a/app/models/Block.js b/app/models/Block.js index 19e6d53..46af590 100644 --- a/app/models/Block.js +++ b/app/models/Block.js @@ -5,7 +5,10 @@ */ var mongoose = require('mongoose'), Schema = mongoose.Schema, + bignum = require('bignum'), RpcClient = require('bitcore/RpcClient').class(), + util = require('bitcore/util/util'), + BitcoreBlock= require('bitcore/Block').class(), config = require('../../config/config') ; @@ -26,7 +29,6 @@ var BlockSchema = new Schema({ fromP2P: Boolean, }); - /** * Validations */ @@ -82,6 +84,8 @@ BlockSchema.methods.getInfo = function (next) { that.info = blockInfo.result; + that.info.reward = BitcoreBlock.getBlockValue(that.info.height) / util.COIN ; + //console.log("THAT", that); return next(null, that.info); }); diff --git a/test/model/addr.js b/test/model/addr.js index 1a300f1..dfeea71 100644 --- a/test/model/addr.js +++ b/test/model/addr.js @@ -40,6 +40,8 @@ describe('Address balances', function(){ if (v.balance) assert.equal(v.balance, a.balance); if (v.totalReceived) assert.equal(v.totalReceived, a.totalReceived); if (v.totalSent) assert.equal(v.totalSent, a.totalSent); + + if (v.transactions) { v.transactions.forEach( function(tx) {