add reward to block api
This commit is contained in:
parent
524792b1f0
commit
d13f9ce3bd
|
@ -31,6 +31,10 @@ exports.address = function(req, res, next, addr) {
|
||||||
*/
|
*/
|
||||||
exports.show = function(req, res) {
|
exports.show = function(req, res) {
|
||||||
if (req.address) {
|
if (req.address) {
|
||||||
|
|
||||||
|
console.log(req.address);
|
||||||
|
console.log(req.address.totalSent);
|
||||||
|
console.log(JSON.stringify(req.address));
|
||||||
res.jsonp(req.address);
|
res.jsonp(req.address);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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