new txout-spend- schema
This commit is contained in:
parent
9910fa4d40
commit
8b892edfbc
|
@ -16,7 +16,7 @@ function spec(b) {
|
|||
|
||||
// to sum up addr balance
|
||||
var ADDR_PREFIX = 'txouts-addr-'; //txouts-addr-<addr>-<ts>-<txid>-<n> => + btc_sat
|
||||
var SPEND_PREFIX = 'txouts-spend-';//txouts-spend-<txid(out)>-<n(out)> => [txid(in),n(in),ts]
|
||||
var SPEND_PREFIX = 'txouts-spend-';//txouts-spend-<txid(out)>-<n(out)>-<txid(in)>-<n(in)> = ts
|
||||
|
||||
// TODO: use bitcore networks module
|
||||
var genesisTXID = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b';
|
||||
|
@ -97,7 +97,6 @@ function spec(b) {
|
|||
db.createReadStream({start: k, end: k + '~'})
|
||||
.on('data', function (data) {
|
||||
var k = data.key.split('-');
|
||||
var v = data.value.split(':');
|
||||
var j = idx[parseInt(k[3])];
|
||||
|
||||
assert(typeof j !== 'undefined','Spent could not be stored: tx ' + txid +
|
||||
|
@ -109,8 +108,8 @@ function spec(b) {
|
|||
assert(0);
|
||||
}
|
||||
else {
|
||||
ret[j].spendTxId = v[0];
|
||||
ret[j].spendIndex = parseInt(v[1]);
|
||||
ret[j].spendTxId = k[4];
|
||||
ret[j].spendIndex = parseInt(k[5]);
|
||||
}
|
||||
})
|
||||
.on('error', function (err) {
|
||||
|
@ -236,16 +235,26 @@ function spec(b) {
|
|||
|
||||
async.each(ret, function(o, e_c) {
|
||||
var k = SPEND_PREFIX + o.txid + '-' + o.index;
|
||||
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=parseInt(v[1]);
|
||||
o.spendTs=parseInt(v[2]);
|
||||
return e_c();
|
||||
});
|
||||
db.createReadStream({start: k, end: k + '~'})
|
||||
.on('data', function (data) {
|
||||
var k = data.key.split('-');
|
||||
var v = data.value;
|
||||
if (o.spendTxId) {
|
||||
// double spend!
|
||||
assert(0);
|
||||
}
|
||||
else {
|
||||
o.spendTxId = k[4];
|
||||
o.spendIndex = parseInt(k[5]);
|
||||
o.spendTs = parseInt(v);
|
||||
}
|
||||
})
|
||||
.on('error', function (err) {
|
||||
return e_c(err);
|
||||
})
|
||||
.on('end', function (err) {
|
||||
return e_c(err);
|
||||
});
|
||||
},
|
||||
function() {
|
||||
async.each(ret, function(o, e_c){
|
||||
|
@ -341,8 +350,7 @@ function spec(b) {
|
|||
async.forEachLimit(tx.vin, CONCURRENCY,
|
||||
function(i, next_out) {
|
||||
db.batch()
|
||||
.put( SPEND_PREFIX + i.txid + '-' + i.vout ,
|
||||
tx.txid + ':' + i.n + ':' + ts)
|
||||
.put( SPEND_PREFIX + i.txid + '-' + i.vout + '-' + tx.txid + '-' + i.n, ts)
|
||||
.write(next_out);
|
||||
},
|
||||
function (err) {
|
||||
|
|
Loading…
Reference in New Issue