fix confirmed balance

This commit is contained in:
Matias Alejo Garcia 2014-05-27 18:02:42 -03:00
parent c90e7cef8a
commit 3da0779d70
5 changed files with 47 additions and 96 deletions

25
dev-util/getAddr.js Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env node
'use strict';
var util = require('util'),
config = require('../config/config');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var A = require('../app/models/Address');
// var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';
var hash = process.argv[2] || 'mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS';
var a= new A(hash);
a.update(function(err) {
console.log('Err:');
console.log(err);
console.log('Ret:');
console.log(util.inspect(a,{depth:null}));
})

View File

@ -1,41 +0,0 @@
#!/usr/bin/env node
'use strict';
var util = require('util');
var mongoose= require('mongoose'),
config = require('../config/config');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var T = require('../app/models/TransactionOut');
// var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';
var hash = process.argv[2] || 'e2253359458db3e732c82a43fc62f56979ff59928f25a2df34dfa443e9a41160';
mongoose.connect(config.db);
mongoose.connection.on('error', function(err) { console.log(err); });
mongoose.connection.on('open', function() {
var b = new Buffer(hash,'hex');
T.find({txidBuf: b}, function(err, ret) {
console.log('Err:');
console.log(err);
console.log('Ret:');
console.log(util.inspect(ret,{depth:null}));
mongoose.connection.close();
});
});

View File

@ -1,39 +0,0 @@
#!/usr/bin/env node
'use strict';
var util = require('util');
var mongoose= require('mongoose'),
config = require('../config/config');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var T = require('../app/models/TransactionOut');
// var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';
var hash = process.argv[2] || 'mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS';
mongoose.connect(config.db);
mongoose.connection.on('error', function(err) { console.log(err); });
mongoose.connection.on('open', function() {
T.find({addr: hash}, function(err, ret) {
console.log('Err:');
console.log(err);
console.log('Ret:');
console.log(util.inspect(ret,{depth:null}));
mongoose.connection.close();
});
});

View File

@ -142,16 +142,10 @@ BlockDb.prototype.setBlockNotMain = function(hash, cb) {
// the block prev to the new block, nor TIP pointer
//
BlockDb.prototype.add = function(b, height, cb) {
d('adding block %s #d', b,height);
var txs = typeof b.tx[0] === 'string' ? b.tx : b.tx.map( function(o){ return o.txid; });
var dbScript = this._addBlockScript(b,height);
dbScript = dbScript.concat(this._addTxsScript(
b.tx.map(
function(o){
return o.txid;
}),
b.hash,
height
));
dbScript = dbScript.concat(this._addTxsScript(txs, b.hash, height));
this.txDb.addMany(b.tx, function(err) {
if (err) return cb(err);
db.batch(dbScript,cb);
@ -328,6 +322,7 @@ BlockDb.prototype.blockIndex = function(height, cb) {
BlockDb.prototype._fillConfirmationsOneSpent = function(o, chainHeight, cb) {
var self = this;
if (!o.spentTxId) return cb();
if (o.multipleSpentAttempts) {
async.eachLimit(o.multipleSpentAttempts, CONCURRENCY,
function(oi, e_c) {
@ -336,7 +331,7 @@ BlockDb.prototype._fillConfirmationsOneSpent = function(o, chainHeight, cb) {
if (height>=0) {
o.spentTxId = oi.spentTxId;
o.index = oi.index;
o.spentIsConfirmed = chainHeight - height >= self.safeConfirmations ? 1 : 0;
o.spentIsConfirmed = chainHeight >= height;
o.spentConfirmations = chainHeight - height;
}
return e_c();
@ -345,8 +340,10 @@ BlockDb.prototype._fillConfirmationsOneSpent = function(o, chainHeight, cb) {
} else {
self.getBlockForTx(o.spentTxId, function(err, hash, height) {
if (err) return cb(err);
o.spentIsConfirmed = chainHeight - height >= self.safeConfirmations ? 1 : 0;
o.spentConfirmations = chainHeight - height;
if (height >=0 ) {
o.spentIsConfirmed = chainHeight >= height;
o.spentConfirmations = chainHeight - height;
}
return cb();
});
}
@ -356,9 +353,12 @@ BlockDb.prototype._fillConfirmationsOne = function(o, chainHeight, cb) {
var self = this;
self.getBlockForTx(o.txid, function(err, hash, height) {
if (err) return cb(err);
o.isConfirmed = chainHeight - height >= self.safeConfirmations ? 1 : 0;
o.confirmations = chainHeight - height;
return self._fillConfirmationsOneSpent(o,chainHeight,cb);
if (height>=0) {
o.isConfirmed = chainHeight >= height;
o.confirmations = chainHeight - height;
return self._fillConfirmationsOneSpent(o,chainHeight,cb);
}
else return cb();
});
};
@ -369,6 +369,7 @@ BlockDb.prototype.fillConfirmations = function(txouts, cb) {
return !x.spentIsConfirmedCached // not 100%cached
&& !(x.isConfirmedCached && !x.spentTxId); // and not 50%cached but not spent
});
async.eachLimit(txs, CONCURRENCY, function(txout, e_c) {
if(txout.isConfirmedCached) {
self._fillConfirmationsOneSpent(txout,height, e_c);
@ -394,7 +395,6 @@ BlockDb.prototype.migrateV02 = function(cb) {
};
BlockDb.prototype.migrateV02cleanup = function(cb) {
var self = this;
console.log('## deleting txb- from txs db'); //todo

View File

@ -1,4 +1,10 @@
[
{
"addr": "mm8CDNJnk8PtQPEtTns2ah5nmxN63ENHtY",
"balance": 1.401,
"txApperances": 2
},
{
"addr": "mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS",
"balance": 0,