diff --git a/app/models/Address.js b/app/models/Address.js index b01cc2d2..dd6da83a 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 19e6d53b..46af5907 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/app/models/Transaction.js b/app/models/Transaction.js index 29b04998..57d2fc29 100644 --- a/app/models/Transaction.js +++ b/app/models/Transaction.js @@ -10,6 +10,7 @@ var mongoose = require('mongoose'), RpcClient = require('bitcore/RpcClient').class(), Transaction = require('bitcore/Transaction').class(), Address = require('bitcore/Address').class(), + BitcoreBlock= require('bitcore/Block').class(), networks = require('bitcore/networks'), util = require('bitcore/util/util'), bignum = require('bignum'), @@ -296,9 +297,17 @@ TransactionSchema.methods.queryInfo = function (next) { that.info.valueIn = valueIn / 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; + + return next(err, that.info); }); }); diff --git a/test/model/addr.js b/test/model/addr.js index 1a300f1e..dfeea716 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) {