fix timestamp and rounding in TXs
This commit is contained in:
parent
71b27aede0
commit
e4095cbf8e
|
@ -9,8 +9,8 @@ function spec() {
|
|||
var BitcoreUtil = require('bitcore/util/util');
|
||||
var TransactionDb = require('../../lib/TransactionDb').class();
|
||||
|
||||
function Address(addrStr) {
|
||||
this.tdb = new TransactionDb();
|
||||
function Address(addrStr, txDb) {
|
||||
this.txDb = txDb || new TransactionDb();
|
||||
this.balanceSat = 0;
|
||||
this.totalReceivedSat = 0;
|
||||
this.totalSentSat = 0;
|
||||
|
@ -58,35 +58,24 @@ function spec() {
|
|||
Address.prototype.update = function(next) {
|
||||
var self = this;
|
||||
async.series([
|
||||
/* function (cb) {
|
||||
TransactionIn.find({addr:self.addrStr}).exec(function(err,txIn){
|
||||
if (err) return cb(err);
|
||||
|
||||
txIn.forEach(function(txItem){
|
||||
|
||||
self.balanceSat += txItem.value_sat;
|
||||
self.totalReceivedSat += txItem.value_sat;
|
||||
});
|
||||
return cb();
|
||||
});
|
||||
},
|
||||
*/
|
||||
function (cb) {
|
||||
self.tdb.fromAddr(self.addrStr, function(err,txOut){
|
||||
self.txDb.fromAddr(self.addrStr, function(err,txOut){
|
||||
if (err) return cb(err);
|
||||
|
||||
txOut.forEach(function(txItem){
|
||||
|
||||
self.totalReceivedSat += txItem.value_sat;
|
||||
var v = parseInt(txItem.value_sat);
|
||||
|
||||
self.totalReceivedSat += v;
|
||||
self.transactions.push(txItem.txid);
|
||||
if (! txItem.spendTxId) {
|
||||
// unspent
|
||||
self.balanceSat += txItem.value_sat;
|
||||
self.balanceSat += v;
|
||||
self.txApperances +=1;
|
||||
}
|
||||
else {
|
||||
// spent
|
||||
self.totalSentSat += txItem.value_sat;
|
||||
self.totalSentSat += v;
|
||||
self.transactions.push(txItem.spendTxid);
|
||||
self.txApperances +=2;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var T = require('../app/models/Transaction').class();
|
||||
var mongoose= require('mongoose'),
|
||||
config = require('../config/config');
|
||||
var T = require('../lib/TransactionDb').class();
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
|
@ -14,21 +12,15 @@ var hash = process.argv[2] || 'e2253359458db3e732c82a43fc62f56979ff59928f25a2df3
|
|||
|
||||
|
||||
|
||||
var t = new T();
|
||||
t.fromIdWithInfo(hash, function(err, ret) {
|
||||
|
||||
mongoose.connect(config.db);
|
||||
mongoose.connection.on('error', function(err) { console.log('error!', err); });
|
||||
mongoose.connection.on('open', function() {
|
||||
|
||||
T.fromIdWithInfo(hash, function(err, ret) {
|
||||
|
||||
console.log('Err:');
|
||||
console.log(err);
|
||||
console.log('Err:');
|
||||
console.log(err);
|
||||
|
||||
|
||||
console.log('Ret:');
|
||||
console.log(util.inspect(ret,{depth:null}));
|
||||
mongoose.connection.close();
|
||||
});
|
||||
console.log('Ret:');
|
||||
console.log(util.inspect(ret,{depth:null}));
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
var Sync = require('../lib/Sync').class();
|
||||
|
||||
|
||||
var s = new Sync();
|
||||
|
||||
|
||||
s.setOrphan(
|
||||
'0000000000c2b1e8dab92a72741289e5ef0d4f375fd1b26f729da2ba979c028a',
|
||||
'000000000228f9d02654459e09998c7557afa9082784c11226853f5feb805df9',
|
||||
function (err) {
|
||||
console.log('[sync-level.js.15]',err); //TODO
|
||||
});
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var
|
||||
config = require('../config/config'),
|
||||
levelup = require('levelup');
|
||||
|
||||
|
||||
db = levelup(config.leveldb + '/txs');
|
||||
|
||||
var s = 'txouts-addr-mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ';
|
||||
db.createReadStream({start: s, end: s+'~'})
|
||||
.on('data', function (data) {
|
||||
console.log('[block-level.js.11:data:]',data); //TODO
|
||||
if (data==false) c++;
|
||||
})
|
||||
.on('end', function () {
|
||||
});
|
||||
|
||||
|
|
@ -278,7 +278,13 @@ function spec() {
|
|||
var ti=0;
|
||||
// Get TX Address
|
||||
b.txs.forEach(function(t) {
|
||||
|
||||
|
||||
var objTx = blockInfo.tx[ti++];
|
||||
|
||||
//add time from block
|
||||
objTx.time = blockInfo.time;
|
||||
|
||||
var to=0;
|
||||
t.outs.forEach( function(o) {
|
||||
|
||||
|
|
|
@ -221,7 +221,6 @@ function spec() {
|
|||
});
|
||||
},
|
||||
function(err) {
|
||||
|
||||
console.log('[TransactionDb.js.165]', ret); //TODO
|
||||
return cb(err,ret);
|
||||
});
|
||||
|
@ -341,7 +340,7 @@ console.log('[TransactionDb.js.165]', ret); //TODO
|
|||
// }
|
||||
|
||||
var addr = o.scriptPubKey.addresses[0];
|
||||
var sat = o.value * util.COIN;
|
||||
var sat = Math.round(o.value * util.COIN);
|
||||
self.db.batch()
|
||||
.put( OUTS_ROOT + tx.txid + '-' + o.n, addr + ':' + sat)
|
||||
.put( ADDR_ROOT + addr + '-' + ts + '-' + tx.txid +
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var
|
||||
assert = require('assert'),
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
config = require('../../config/config'),
|
||||
Address = require('../../app/models/Address').class();
|
||||
Address = require('../../app/models/Address').class(),
|
||||
TransactionDb = require('../../lib/TransactionDb').class(),
|
||||
addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json'));
|
||||
|
||||
var txDb;
|
||||
describe('Address balances', function(){
|
||||
|
||||
before(function(c) {
|
||||
txDb = new TransactionDb();
|
||||
return c();
|
||||
});
|
||||
|
||||
|
||||
addrValid.forEach( function(v) {
|
||||
if (v.disabled) {
|
||||
console.log(v.addr + " => disabled in JSON");
|
||||
|
@ -19,7 +26,7 @@ describe('Address balances', function(){
|
|||
it('Info for: ' + v.addr, function(done) {
|
||||
this.timeout(5000);
|
||||
|
||||
var a = new Address(v.addr);
|
||||
var a = new Address(v.addr, txDb);
|
||||
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
[
|
||||
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ",
|
||||
"balance": 43.1,
|
||||
"txApperances": 19
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS",
|
||||
"balance": 0,
|
||||
"totalReceived": 50,
|
||||
|
@ -14,7 +8,6 @@
|
|||
"txApperances": 2
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "muyg1K5WsHkfMVCkUXU2y7Xp5ZD6RGzCeH",
|
||||
"balance": 0.38571339,
|
||||
"totalReceived": 0.38571339,
|
||||
|
@ -29,7 +22,6 @@
|
|||
"txApperances": 13
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "n47CfqnKWdNwqY1UWxTmNJAqYutFxdH3zY",
|
||||
"balance": 0,
|
||||
"totalReceived":26.4245,
|
||||
|
@ -37,7 +29,6 @@
|
|||
"txApperances": 4
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mzSyyXgofoBxpr6gYcU3cV345G8hJpixRd",
|
||||
"balance": 0,
|
||||
"totalReceived":3.9775,
|
||||
|
@ -45,7 +36,11 @@
|
|||
"txApperances": 2
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ",
|
||||
"balance": 43.1,
|
||||
"txApperances": 19
|
||||
},
|
||||
{
|
||||
"addr": "mzW2hdZN2um7WBvTDerdahKqRgj3md9C29",
|
||||
"txApperances": 2034,
|
||||
"balance": 1049.69744099,
|
||||
|
@ -53,7 +48,6 @@
|
|||
"totalSent": 0
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mjRmkmYzvZN3cA3aBKJgYJ65epn3WCG84H",
|
||||
"txApperances": 13343,
|
||||
"balance": 46413.0,
|
||||
|
@ -61,7 +55,6 @@
|
|||
"totalSent": 310717.17644359
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mgKY35SXqxFpcKK3Dq9mW9919N7wYXvcFM",
|
||||
"txApperances": 1,
|
||||
"balance": 0.01979459,
|
||||
|
@ -70,7 +63,6 @@
|
|||
"transactions": [ "91800d80bb4c69b238c9bfd94eb5155ab821e6b25cae5c79903d12853bbb4ed5" ]
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mmvP3mTe53qxHdPqXEvdu8WdC7GfQ2vmx5",
|
||||
"balance": 10580.50027254,
|
||||
"totalReceived": 12157.65075053,
|
||||
|
|
Loading…
Reference in New Issue