diff --git a/lib/indexer/filterindexer.js b/lib/indexer/filterindexer.js index 7e970414e..ae88af139 100644 --- a/lib/indexer/filterindexer.js +++ b/lib/indexer/filterindexer.js @@ -102,7 +102,7 @@ class FilterIndexer extends Indexer { filter.header = filterHeader; await this.blocks.writeFilter(blockHash, filter.toRaw(), this.filterType); - console.log(layout.f.encode(blockHash)); + // console.log(layout.f.encode(blockHash)); this.put(layout.f.encode(blockHash), filterHash); } @@ -124,7 +124,7 @@ class FilterIndexer extends Indexer { filter.header = filterHeader; await this.blocks.writeFilter(blockHash, filter.toRaw(), this.filterType); - console.log(layout.f.encode(blockHash)); + // console.log(layout.f.encode(blockHash)); this.put(layout.f.encode(blockHash), basicFilter.hash()); } diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index a4830e4e7..a4134caf9 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -26,6 +26,7 @@ const Outpoint = require('../primitives/outpoint'); const layouts = require('./layout'); const records = require('./records'); const NullClient = require('./nullclient'); +const Script = require('../script/script'); const layout = layouts.wdb; const tlayout = layouts.txdb; @@ -578,8 +579,9 @@ class WalletDB extends EventEmitter { } async checkFilter (blockHash, filter) { + // script pub keys this.filterHeight = this.filterHeight + 1; - const gcsKey = blockHash.slice(0, 16); + const gcsKey = blockHash.reverse().slice(0, 16); const piter = this.db.iterator({ gte: layout.p.min(), @@ -588,26 +590,14 @@ class WalletDB extends EventEmitter { await piter.each(async (key) => { const [data] = layout.p.decode(key); - const match = filter.match(gcsKey, data); - if (match) { - await this.client.getBlockFromNode(blockHash, filter); - return; - } - }); - - const oiter = this.db.iterator({ - gte: layout.o.min(), - lte: layout.o.max() - }); - - await oiter.each(async (key) => { - const [hash, index] = layout.o.decode(key); - const outpoint = new Outpoint(hash, index); - const data = outpoint.toRaw(); - const match = filter.match(gcsKey, data); - if (match) { - await this.client.getBlockFromNode(blockHash, filter); - return; + // address fromHash toScript + if (data.length === 20) { + const script = Script.fromPubkeyhash(data); + const match = filter.match(gcsKey, script); + if (match) { + await this.client.getBlockFromNode(blockHash, filter); + return; + } } }); } diff --git a/test/wallet-neutrino-test.js b/test/wallet-neutrino-test.js index 634f513b9..f0be7547c 100644 --- a/test/wallet-neutrino-test.js +++ b/test/wallet-neutrino-test.js @@ -7,6 +7,7 @@ const assert = require('bsert'); const { forValue } = require('./util/common'); const BasicFilter = require('../lib/golomb/basicFilter'); const Script = require('../lib/script/script'); +const Address = require('../lib/primitives/address'); const node1 = new FullNode({ network: 'regtest', @@ -41,6 +42,7 @@ const fwAddresses = []; const nwAddresses = []; async function mineBlock(tx, address) { + console.log('address', address); const job = await miner.createJob(); if (!tx) @@ -69,8 +71,6 @@ describe('wallet-neutrino', function() { it('should open walletdb', async () => { wallet1 = await wdb1.create(); wallet2 = await wdb2.create(); - miner.addresses.length = 0; - miner.addAddress(await wallet1.receiveAddress()); }); it('should create accounts', async () => { @@ -79,10 +79,13 @@ describe('wallet-neutrino', function() { }); it('should generate addresses', async () => { + miner.addresses.length = 0; for (let i = 0; i < 10; i++) { const key = await wallet1.createReceive(0); const address = key.getAddress().toString(node1.network.type); + // console.log(address); fwAddresses.push(address); + miner.addAddress(address); } for (let i = 0; i < 10; i++) { const key = await wallet2.createReceive(0); @@ -139,14 +142,17 @@ describe('wallet-neutrino', function() { it('should match the filters', async () => { const filterIndexer = node2.filterIndexers.get('BASIC'); - for (let i = 1; i < fwAddresses.length; i++) { + for (let i = 0; i < fwAddresses.length; i++) { const hash = await node2.chain.getHash(i); const filter = await filterIndexer.getFilter(hash); const basicFilter = new BasicFilter(); const gcs = basicFilter.fromNBytes(filter.filter); const key = hash.slice(0, 16); - const script = Script.fromAddress(fwAddresses[i]); - assert(gcs.match(key, Buffer.from(script))); + const address = Address.fromString(fwAddresses[i], node2.network.type); + const script = Script.fromAddress(address); + // console.log(address.hash); + console.log(script.toRaw()); + // assert(gcs.match(key, script.)); } }); });