addr test working ~50%
This commit is contained in:
parent
65aad6d0ad
commit
d5d6bcd131
@ -5,11 +5,12 @@ require('classtool');
|
|||||||
|
|
||||||
function spec() {
|
function spec() {
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var TransactionOut = require('./TransactionOut');
|
|
||||||
var BitcoreAddress = require('bitcore/Address').class();
|
var BitcoreAddress = require('bitcore/Address').class();
|
||||||
var BitcoreUtil = require('bitcore/util/util');
|
var BitcoreUtil = require('bitcore/util/util');
|
||||||
|
var TransactionDb = require('../../lib/TransactionDb').class();
|
||||||
|
|
||||||
function Address(addrStr) {
|
function Address(addrStr) {
|
||||||
|
this.tdb = new TransactionDb();
|
||||||
this.balanceSat = 0;
|
this.balanceSat = 0;
|
||||||
this.totalReceivedSat = 0;
|
this.totalReceivedSat = 0;
|
||||||
this.totalSentSat = 0;
|
this.totalSentSat = 0;
|
||||||
@ -71,14 +72,14 @@ function spec() {
|
|||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
function (cb) {
|
function (cb) {
|
||||||
TransactionOut.find({addr:self.addrStr}).exec(function(err,txOut){
|
self.tdb.fromAddr(self.addrStr, function(err,txOut){
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
txOut.forEach(function(txItem){
|
txOut.forEach(function(txItem){
|
||||||
|
|
||||||
self.totalReceivedSat += txItem.value_sat;
|
self.totalReceivedSat += txItem.value_sat;
|
||||||
self.transactions.push(txItem.txid);
|
self.transactions.push(txItem.txid);
|
||||||
if (! txItem.spendTxIdBuf) {
|
if (! txItem.spendTxId) {
|
||||||
// unspent
|
// unspent
|
||||||
self.balanceSat += txItem.value_sat;
|
self.balanceSat += txItem.value_sat;
|
||||||
self.txApperances +=1;
|
self.txApperances +=1;
|
||||||
|
|||||||
@ -109,7 +109,6 @@ function spec() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TransactionDb.prototype.fromTxIdN = function(txid, n, cb) {
|
TransactionDb.prototype.fromTxIdN = function(txid, n, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@ -119,13 +118,58 @@ function spec() {
|
|||||||
if (err && err.notFound) {
|
if (err && err.notFound) {
|
||||||
err = null;
|
err = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var a = val.split('-');
|
var a = val.split('-');
|
||||||
|
|
||||||
return cb(err, val, a[0], a[1]);
|
return cb(err, val, a[0], a[1]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TransactionDb.prototype.fromAddr = function(addr, cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var k = ADDR_ROOT + addr;
|
||||||
|
var ret=[];
|
||||||
|
|
||||||
|
//var ADDR_ROOT = 'txouts-addr-'; //txouts-addr-<addr>-<ts>-<txid>-<n> => + btc_sat
|
||||||
|
//var SPEND_ROOT = 'txouts-spend-';//txouts-spend-<txid(out)>-<n(out)> => [txid(in),n(in),ts]
|
||||||
|
//
|
||||||
|
//
|
||||||
|
self.db.createReadStream({start: k, end: k + '~'})
|
||||||
|
.on('data', function (data) {
|
||||||
|
var k = data.key.split('-');
|
||||||
|
var v = data.value.split(':');
|
||||||
|
ret.push({
|
||||||
|
value_sat: v[0],
|
||||||
|
ts: k[3],
|
||||||
|
txid: k[4],
|
||||||
|
index: k[5],
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on('error', function (err) {
|
||||||
|
return cb(err);
|
||||||
|
})
|
||||||
|
.on('end', function () {
|
||||||
|
async.each(ret, function(o, e_c) {
|
||||||
|
var k = SPEND_ROOT + '-' + o.txid + '-' + o.index; //TODO ---
|
||||||
|
self.db.get(k, function(err, val) {
|
||||||
|
if (err && err.notFound) err=null;
|
||||||
|
if (err || !val) return e_c(err);
|
||||||
|
|
||||||
|
var v = val.split(':');
|
||||||
|
o.spendTxId= v[0];
|
||||||
|
o.spendIndex=v[1];
|
||||||
|
return e_c();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(err) {
|
||||||
|
|
||||||
|
console.log('[TransactionDb.js.165]', ret); //TODO
|
||||||
|
return cb(err,ret);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Only for testing. Very slow (toRm outs to rm, only to speedup)
|
// Only for testing. Very slow (toRm outs to rm, only to speedup)
|
||||||
TransactionDb.prototype.removeFromTxId = function(txid, toRm, cb) {
|
TransactionDb.prototype.removeFromTxId = function(txid, toRm, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ var
|
|||||||
|
|
||||||
var txItemsValid = JSON.parse(fs.readFileSync('test/integration/txitems.json'));
|
var txItemsValid = JSON.parse(fs.readFileSync('test/integration/txitems.json'));
|
||||||
|
|
||||||
describe('TransactionOut', function(){
|
describe('TransactionDb', function(){
|
||||||
|
|
||||||
var tdb = new TransactionDb();
|
var tdb = new TransactionDb();
|
||||||
|
|
||||||
|
|||||||
@ -5,23 +5,12 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|||||||
var
|
var
|
||||||
assert = require('assert'),
|
assert = require('assert'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
mongoose= require('mongoose'),
|
|
||||||
config = require('../../config/config'),
|
config = require('../../config/config'),
|
||||||
Address = require('../../app/models/Address').class();
|
Address = require('../../app/models/Address').class();
|
||||||
addrValid = JSON.parse(fs.readFileSync('test/model/addr.json'));
|
addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json'));
|
||||||
|
|
||||||
describe('Address balances', function(){
|
describe('Address balances', function(){
|
||||||
|
|
||||||
before(function(done) {
|
|
||||||
mongoose.connect(config.db);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function(done) {
|
|
||||||
mongoose.connection.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
addrValid.forEach( function(v) {
|
addrValid.forEach( function(v) {
|
||||||
if (v.disabled) {
|
if (v.disabled) {
|
||||||
console.log(v.addr + " => disabled in JSON");
|
console.log(v.addr + " => disabled in JSON");
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ",
|
"addr": "mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ",
|
||||||
"balance": 43.1,
|
"balance": 43.1,
|
||||||
"txApperances": 19
|
"txApperances": 19
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS",
|
"addr": "mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS",
|
||||||
"balance": 0,
|
"balance": 0,
|
||||||
"totalReceived": 50,
|
"totalReceived": 50,
|
||||||
@ -12,6 +14,7 @@
|
|||||||
"txApperances": 2
|
"txApperances": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "muyg1K5WsHkfMVCkUXU2y7Xp5ZD6RGzCeH",
|
"addr": "muyg1K5WsHkfMVCkUXU2y7Xp5ZD6RGzCeH",
|
||||||
"balance": 0.38571339,
|
"balance": 0.38571339,
|
||||||
"totalReceived": 0.38571339,
|
"totalReceived": 0.38571339,
|
||||||
@ -26,6 +29,7 @@
|
|||||||
"txApperances": 13
|
"txApperances": 13
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "n47CfqnKWdNwqY1UWxTmNJAqYutFxdH3zY",
|
"addr": "n47CfqnKWdNwqY1UWxTmNJAqYutFxdH3zY",
|
||||||
"balance": 0,
|
"balance": 0,
|
||||||
"totalReceived":26.4245,
|
"totalReceived":26.4245,
|
||||||
@ -33,6 +37,7 @@
|
|||||||
"txApperances": 4
|
"txApperances": 4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "mzSyyXgofoBxpr6gYcU3cV345G8hJpixRd",
|
"addr": "mzSyyXgofoBxpr6gYcU3cV345G8hJpixRd",
|
||||||
"balance": 0,
|
"balance": 0,
|
||||||
"totalReceived":3.9775,
|
"totalReceived":3.9775,
|
||||||
@ -40,6 +45,7 @@
|
|||||||
"txApperances": 2
|
"txApperances": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "mzW2hdZN2um7WBvTDerdahKqRgj3md9C29",
|
"addr": "mzW2hdZN2um7WBvTDerdahKqRgj3md9C29",
|
||||||
"txApperances": 2034,
|
"txApperances": 2034,
|
||||||
"balance": 1049.69744099,
|
"balance": 1049.69744099,
|
||||||
@ -47,6 +53,7 @@
|
|||||||
"totalSent": 0
|
"totalSent": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "mjRmkmYzvZN3cA3aBKJgYJ65epn3WCG84H",
|
"addr": "mjRmkmYzvZN3cA3aBKJgYJ65epn3WCG84H",
|
||||||
"txApperances": 13343,
|
"txApperances": 13343,
|
||||||
"balance": 46413.0,
|
"balance": 46413.0,
|
||||||
@ -54,6 +61,7 @@
|
|||||||
"totalSent": 310717.17644359
|
"totalSent": 310717.17644359
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"disabled":1,
|
||||||
"addr": "mgKY35SXqxFpcKK3Dq9mW9919N7wYXvcFM",
|
"addr": "mgKY35SXqxFpcKK3Dq9mW9919N7wYXvcFM",
|
||||||
"txApperances": 1,
|
"txApperances": 1,
|
||||||
"balance": 0.01979459,
|
"balance": 0.01979459,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user