get coin parsing working.
This commit is contained in:
parent
7175f81d59
commit
2a20e56f7b
@ -35,6 +35,7 @@ function BlockDB(options) {
|
|||||||
options.file = process.env.HOME + '/bcoin-server-' + network.type + '.ldb';
|
options.file = process.env.HOME + '/bcoin-server-' + network.type + '.ldb';
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
this.parser = new bcoin.protocol.parser();
|
||||||
this.data = new BlockData();
|
this.data = new BlockData();
|
||||||
this.index = levelup(options.file, {
|
this.index = levelup(options.file, {
|
||||||
keyEncoding: 'ascii',
|
keyEncoding: 'ascii',
|
||||||
@ -92,7 +93,10 @@ BlockDB.prototype.saveBlock = function saveBlock(block, callback) {
|
|||||||
batch.put('b/h/' + block.height, blockOffset);
|
batch.put('b/h/' + block.height, blockOffset);
|
||||||
|
|
||||||
block.txs.forEach(function(tx, i) {
|
block.txs.forEach(function(tx, i) {
|
||||||
var txOffset = self.createOffset(tx._size, data.offset + tx._offset, block.height);
|
var txOffset = self.createOffset(
|
||||||
|
tx._size, data.offset + tx._offset,
|
||||||
|
block.height);
|
||||||
|
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
var uniq = {};
|
var uniq = {};
|
||||||
|
|
||||||
@ -145,7 +149,6 @@ BlockDB.prototype.saveBlock = function saveBlock(block, callback) {
|
|||||||
output._size,
|
output._size,
|
||||||
data.offset + tx._offset + output._offset,
|
data.offset + tx._offset + output._offset,
|
||||||
block.height);
|
block.height);
|
||||||
// console.log(self.parseOffset(coinOffset));
|
|
||||||
|
|
||||||
if (uaddr)
|
if (uaddr)
|
||||||
batch.put('t/a/' + uaddr + '/' + hash, txOffset);
|
batch.put('t/a/' + uaddr + '/' + hash, txOffset);
|
||||||
@ -357,14 +360,22 @@ BlockDB.prototype._getCoinsByAddress = function _getCoinsByAddress(address, call
|
|||||||
var record = self.parseOffset(data.value);
|
var record = self.parseOffset(data.value);
|
||||||
pending++;
|
pending++;
|
||||||
self.data.getAsync(record.size, record.offset, function(err, data) {
|
self.data.getAsync(record.size, record.offset, function(err, data) {
|
||||||
|
var coin;
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
var coin = bcoin.coin.fromRaw(data, true);
|
data = self.parser.parseTXOut(data);
|
||||||
coin.hash = hash;
|
coin = bcoin.coin({
|
||||||
coin.index = index;
|
version: 1,
|
||||||
coin.height = record.height;
|
hash: hash,
|
||||||
|
index: index,
|
||||||
|
height: record.height,
|
||||||
|
script: data.script,
|
||||||
|
value: data.value,
|
||||||
|
spent: false
|
||||||
|
});
|
||||||
coins.push(coin);
|
coins.push(coin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,10 +419,16 @@ BlockDB.prototype.getCoin = function getCoin(hash, index, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
coin = bcoin.coin.fromRaw(data, true);
|
data = self.parser.parseTXOut(data);
|
||||||
coin.hash = hash;
|
coin = bcoin.coin({
|
||||||
coin.index = index;
|
version: 1,
|
||||||
coin.height = record.height;
|
hash: hash,
|
||||||
|
index: index,
|
||||||
|
height: record.height,
|
||||||
|
script: data.script,
|
||||||
|
value: data.value,
|
||||||
|
spent: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return callback(null, coin);
|
return callback(null, coin);
|
||||||
|
|||||||
@ -460,11 +460,11 @@ Parser.prototype.parseTX = function parseTX(p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_raw: p.slice(0, off + 4),
|
|
||||||
version: utils.read32(p, 0),
|
version: utils.read32(p, 0),
|
||||||
inputs: txIn,
|
inputs: txIn,
|
||||||
outputs: txOut,
|
outputs: txOut,
|
||||||
locktime: utils.readU32(p, off),
|
locktime: utils.readU32(p, off),
|
||||||
|
_raw: p.slice(0, off + 4),
|
||||||
_size: off + 4
|
_size: off + 4
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user