Skip to content

Commit

Permalink
chain: rename scanAction to scanActions.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Oct 14, 2023
1 parent 7b74168 commit 984f3b5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -18,7 +18,7 @@ process and allows parallel rescans.
### Node HTTP Client:
- Introduce `scanInteractive` method that starts interactive rescan.
- expects ws hook for `block rescan interactive` params `rawEntry, rawTXs`
that returns scanAction.
that returns scanAction object.
- expects ws hook for `block rescan interactive abort` param `message`.

### Wallet API:
Expand Down
12 changes: 6 additions & 6 deletions lib/blockchain/chain.js
Expand Up @@ -28,7 +28,7 @@ const {OwnershipProof} = require('../covenants/ownership');
const AirdropProof = require('../primitives/airdropproof');
const {CriticalError} = require('../errors');
const thresholdStates = common.thresholdStates;
const scanAction = common.scanAction;
const scanActions = common.scanActions;
const {states} = NameState;

const {
Expand Down Expand Up @@ -2283,28 +2283,28 @@ class Chain extends AsyncEmitter {
throw new Error('Did not get proper action');

switch (action.type) {
case scanAction.REPEAT: {
case scanActions.REPEAT: {
break;
}
case scanAction.REPEAT_SET: {
case scanActions.REPEAT_SET: {
// try again with updated filter.
filter = action.filter;
break;
}
case scanAction.REPEAT_ADD: {
case scanActions.REPEAT_ADD: {
if (!filter)
throw new Error('No filter set.');

for (const chunk of action.chunks)
filter.add(chunk);
break;
}
case scanAction.NEXT: {
case scanActions.NEXT: {
const next = await this.getNext(entry);
hash = next && next.hash;
break;
}
case scanAction.ABORT: {
case scanActions.ABORT: {
this.logger.info('Scan(interactive) aborted at %x (%d).',
entry.hash, entry.height);
throw new Error('scan request aborted.');
Expand Down
2 changes: 1 addition & 1 deletion lib/blockchain/common.js
Expand Up @@ -76,7 +76,7 @@ exports.flags.DEFAULT_FLAGS = 0
* @default
*/

exports.scanAction = {
exports.scanActions = {
NONE: 0,
ABORT: 1,
NEXT: 2,
Expand Down
16 changes: 8 additions & 8 deletions lib/node/http.js
Expand Up @@ -20,7 +20,7 @@ const TX = require('../primitives/tx');
const Claim = require('../primitives/claim');
const Address = require('../primitives/address');
const Network = require('../protocol/network');
const scanAction = require('../blockchain/common').scanAction;
const scanActions = require('../blockchain/common').scanActions;
const pkg = require('../pkg');

/**
Expand Down Expand Up @@ -832,14 +832,14 @@ class HTTP extends Server {
const actionType = valid.i32('type');

switch (actionType) {
case scanAction.NEXT:
case scanAction.ABORT:
case scanAction.REPEAT: {
case scanActions.NEXT:
case scanActions.ABORT:
case scanActions.REPEAT: {
return {
type: actionType
};
}
case scanAction.REPEAT_SET: {
case scanActions.REPEAT_SET: {
// NOTE: This is operation is on the heavier side,
// because it sends the whole Filter that can be quite
// big depending on the situation.
Expand All @@ -853,11 +853,11 @@ class HTTP extends Server {
filter = BloomFilter.fromRaw(rawFilter);

return {
type: scanAction.REPEAT_SET,
type: scanActions.REPEAT_SET,
filter: filter
};
}
case scanAction.REPEAT_ADD: {
case scanActions.REPEAT_ADD: {
// NOTE: This operation depending on the filter
// that was provided can be either modifying the
// socket.filter or the filter provided by REPEAT_SET.
Expand All @@ -867,7 +867,7 @@ class HTTP extends Server {
throw new Error('Invalid parameter.');

return {
type: scanAction.REPEAT_ADD,
type: scanActions.REPEAT_ADD,
chunks: chunks
};
}
Expand Down
50 changes: 25 additions & 25 deletions test/node-rescan-test.js
Expand Up @@ -5,7 +5,7 @@ const {BufferSet} = require('buffer-map');
const {BloomFilter} = require('@handshake-org/bfilter');
const TX = require('../lib/primitives/tx');
const nodeCommon = require('../lib/blockchain/common');
const {scanAction} = nodeCommon;
const {scanActions} = nodeCommon;
const NodeContext = require('./util/node');
const {forEvent} = require('./util/common');
const MemWallet = require('./util/memwallet');
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('Node Rescan Interactive API', function() {
assert(hashset.has(tx.hash()));

return {
type: scanAction.NEXT
type: scanActions.NEXT
};
});
});
Expand All @@ -194,12 +194,12 @@ describe('Node Rescan Interactive API', function() {

if (count === 5) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

return {
type: scanAction.NEXT
type: scanActions.NEXT
};
};

Expand Down Expand Up @@ -229,12 +229,12 @@ describe('Node Rescan Interactive API', function() {

if (count === 5) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

return {
type: scanAction.REPEAT_SET,
type: scanActions.REPEAT_SET,
filter: test.filter
};
};
Expand Down Expand Up @@ -265,12 +265,12 @@ describe('Node Rescan Interactive API', function() {

if (count === 5) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

return {
type: scanAction.REPEAT
type: scanActions.REPEAT
};
};

Expand Down Expand Up @@ -307,15 +307,15 @@ describe('Node Rescan Interactive API', function() {

if (filterAndTxs.length === 0) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

// next test
test = filterAndTxs.shift();

return {
type: scanAction.REPEAT_SET,
type: scanActions.REPEAT_SET,
filter: test.filter
};
};
Expand Down Expand Up @@ -348,7 +348,7 @@ describe('Node Rescan Interactive API', function() {

if (testTXs.length === 0) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

Expand All @@ -358,7 +358,7 @@ describe('Node Rescan Interactive API', function() {
expected++;

return {
type: scanAction.REPEAT_ADD,
type: scanActions.REPEAT_ADD,
chunks: chunks
};
};
Expand Down Expand Up @@ -388,7 +388,7 @@ describe('Node Rescan Interactive API', function() {
counterObj.count++;

return {
type: scanAction.NEXT
type: scanActions.NEXT
};
};
};
Expand Down Expand Up @@ -447,7 +447,7 @@ describe('Node Rescan Interactive API', function() {
assert(hashset.has(tx.hash()));

return {
type: scanAction.NEXT
type: scanActions.NEXT
};
});

Expand Down Expand Up @@ -486,12 +486,12 @@ describe('Node Rescan Interactive API', function() {

if (count === 5) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

return {
type: scanAction.NEXT
type: scanActions.NEXT
};
});

Expand Down Expand Up @@ -538,12 +538,12 @@ describe('Node Rescan Interactive API', function() {

if (count === 5) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

return {
type: scanAction.REPEAT_SET,
type: scanActions.REPEAT_SET,
filter: test.filter ? test.filter.encode() : null
};
});
Expand Down Expand Up @@ -590,12 +590,12 @@ describe('Node Rescan Interactive API', function() {

if (count === 5) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

return {
type: scanAction.REPEAT,
type: scanActions.REPEAT,
filter: test.filter ? test.filter.encode() : null
};
});
Expand Down Expand Up @@ -646,14 +646,14 @@ describe('Node Rescan Interactive API', function() {

if (filterAndTxs.length === 0) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

test = filterAndTxs.shift();

return {
type: scanAction.REPEAT_SET,
type: scanActions.REPEAT_SET,
filter: test.filter.encode()
};
});
Expand Down Expand Up @@ -691,7 +691,7 @@ describe('Node Rescan Interactive API', function() {

if (testTXs.length === 0) {
return {
type: scanAction.ABORT
type: scanActions.ABORT
};
}

Expand All @@ -701,7 +701,7 @@ describe('Node Rescan Interactive API', function() {
expected++;

return {
type: scanAction.REPEAT_ADD,
type: scanActions.REPEAT_ADD,
chunks: chunks
};
});
Expand Down Expand Up @@ -745,7 +745,7 @@ describe('Node Rescan Interactive API', function() {
counterObj.count++;

return {
type: scanAction.NEXT
type: scanActions.NEXT
};
};
};
Expand Down

0 comments on commit 984f3b5

Please sign in to comment.