Skip to content

Commit

Permalink
wallet: test spv node http endpoints and w/ fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonf committed Nov 21, 2018
1 parent 13502f1 commit 3be3a7d
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 57 deletions.
12 changes: 6 additions & 6 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,21 @@
- Complete API and exposed methods and endpoints
- [x] Expose HTTP endpoints for txs using indexes
- [x] Test full node http endpoints
- [ ] Test spv node http endpoints
- [ ] Calculate specific limits for RPC responses and use shared constant value and
consider having limits be configurable as they could be hardware specific.
- [ ] Add options to limit tx results to a confirmation level
- [x] Test spv node http endpoints

- Cleanup, refactoring and dependencies
- [ ] Test key and address import and rescanning use case. This could cause
a shift in the counts if an address is added that has history before the
existing transactions. It may be necessary to use block height and block
position for the count index, so that transactions can be inserted without
causing shifts.
- [ ] Calculate specific limits for RPC responses and use shared constant value and
consider having limits be configurable as they could be hardware specific.
- [ ] Update references to `mtime` for a transaction.
- [x] Consider dropping index `M[account][time][hash]` as it may not be needed
- [ ] Add a second full or pruned node, with wallet, to the test that will sync
- [x] Add a second full or pruned node, with wallet, to the test that will sync
directly via p2p messages and have a seperate wallet to send from/to.
- [ ] Test spv wallet with pagination.
- [x] Test spv wallet with pagination.
- [ ] Add more assertions to reorg tests.
- [x] Deprecate `listtransactions` and replace with `listhistory` and related methods.
- [x] Deprecate `getHistory` and use `listHistory` and `listUnconfirmedHistory`
Expand All @@ -81,6 +80,7 @@
- [ ] Coinbase transactions during a reorg will become unconfirmed,
these can be cleaned afterwards by using `abandontransaction`. Consider
possible alternatives.
- [ ] Consider adding options to limit tx results to a confirmation level.

- Documentation and upgrading
- [ ] Check that rpc help, docs and jsdocs are correct
Expand Down
26 changes: 20 additions & 6 deletions lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,11 @@ class TXDB {
if (options.limit > 100)
throw new Error('Limit exceeds max of 100.');

const count = await this.getAccountCountForTX(acct, options.txid);
let count = null;
if (acct !== -1)
count = await this.getAccountCountForTX(acct, options.txid);
else
count = await this.getCountForTX(options.txid);

let zopts = {
limit: options.limit,
Expand All @@ -1941,12 +1945,22 @@ class TXDB {
let lesser = options.inclusive ? 'lte' : 'lt';
let greater = options.inclusive ? 'gte' : 'gt';

if (zopts.reverse) {
zopts['gte'] = layout.Z.min(acct);
zopts[lesser] = layout.Z.encode(acct, count);
if (acct !== -1) {
if (zopts.reverse) {
zopts['gte'] = layout.Z.min(acct);
zopts[lesser] = layout.Z.encode(acct, count);
} else {
zopts[greater] = layout.Z.encode(acct, count);
zopts['lte'] = layout.Z.max(acct);
}
} else {
zopts[greater] = layout.Z.encode(acct, count);
zopts['lte'] = layout.Z.max(acct);
if (zopts.reverse) {
zopts['gte'] = layout.z.min();
zopts[lesser] = layout.z.encode(count);
} else {
zopts[greater] = layout.z.encode(count);
zopts['lte'] = layout.z.max();
}
}

const hashes = await this.bucket.values(zopts);
Expand Down
28 changes: 22 additions & 6 deletions test/util/regtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,38 @@ async function generateReorg(depth, nclient, wclient, coinbase) {
}

async function generateTxs(options) {
const {wclient, count, amount} = options;
const {wclient, spvwclient, count, amount} = options;
let addr, txid = null;

await wclient.execute('selectwallet', ['test']);

let txids = [];

for (var i = 0; i < count; i++) {
if (options.gap && !(i % 50))
await sleep(1000);
if (options.gap && !(i % options.gap))
await sleep(options.sleep);

if (spvwclient)
addr = await spvwclient.execute('getnewaddress', ['blue']);
else
addr = await wclient.execute('getnewaddress', ['blue']);

addr = await wclient.execute('getnewaddress', ['blue']);
txid = await wclient.execute('sendtoaddress', [addr, amount]);
txids.push(txid);
}

return txids;
}

async function generateInitialBlocks(options) {
const {nclient, wclient, coinbase, genesisTime} = options;
const {
nclient,
wclient,
spvwclient,
coinbase,
genesisTime
} = options;

let {blocks} = options;

if (!blocks)
Expand Down Expand Up @@ -224,7 +240,7 @@ async function generateInitialBlocks(options) {
// for the block. Additionally the wallet may not be in lockstep
// sync with the chain, so it's necessary to wait a few more blocks.
if (wclient && c > 115)
await generateTxs({wclient: wclient, count: 50, amount: 0.11111111});
await generateTxs({wclient, spvwclient, count: 50, amount: 0.11111111});

const blockhashes = await generateBlocks(1, nclient, coinbase);
const block = await nclient.execute('getblock', [blockhashes[0]]);
Expand Down
Loading

0 comments on commit 3be3a7d

Please sign in to comment.