Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
manavdesai27 committed Jul 7, 2023
1 parent 46f3e9e commit 8163811
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
4 changes: 2 additions & 2 deletions lib/indexer/filterindexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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());
}

Expand Down
32 changes: 11 additions & 21 deletions lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand All @@ -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;
}
}
});
}
Expand Down
16 changes: 11 additions & 5 deletions test/wallet-neutrino-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -41,6 +42,7 @@ const fwAddresses = [];
const nwAddresses = [];

async function mineBlock(tx, address) {
console.log('address', address);
const job = await miner.createJob();

if (!tx)
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Check failure on line 149 in test/wallet-neutrino-test.js

View workflow job for this annotation

GitHub Actions / Lint

'gcs' is assigned a value but never used
const key = hash.slice(0, 16);

Check failure on line 150 in test/wallet-neutrino-test.js

View workflow job for this annotation

GitHub Actions / Lint

'key' is assigned a value but never used
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.));
}
});
});

0 comments on commit 8163811

Please sign in to comment.