Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

feat!: KeyChainStore, ChainStore, WalletStore and path registration feature #351

Open
wants to merge 40 commits into
base: v0.22-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d8f05d2
feat: introduce KeyChainStore
Alex-Werner Nov 2, 2021
e694a03
feat(KeyChain)!: add watched keys
Alex-Werner Nov 2, 2021
730cb30
feat!: update keychain usage
Alex-Werner Nov 2, 2021
2c55741
feat: add generated address to watched address
Alex-Werner Nov 2, 2021
da0465a
feat: use keychain watched address for address to sync
Alex-Werner Nov 2, 2021
12a94f6
tests(KeyChainStore): update tests
Alex-Werner Nov 5, 2021
afa5c35
feat: added ability to remove keys from watched keys
Alex-Werner Nov 5, 2021
e37e34a
tests(KeyChain): added watched keys tests
Alex-Werner Nov 5, 2021
02f06f6
style: fix lint issue
Alex-Werner Nov 5, 2021
5983f71
tests: fix slow tests by comparing stringified keys instead of object
Alex-Werner Nov 5, 2021
adb19b1
feat: allow to pass network to get watched addresses
Alex-Werner Nov 5, 2021
890924b
feat: ensure gap internal are only generated on HDWallet
Alex-Werner Nov 7, 2021
07690fb
feat: introduce KeyChainStore
Alex-Werner Nov 15, 2021
95526da
tests: update tests
Alex-Werner Nov 15, 2021
9475f36
feat: update local usage
Alex-Werner Nov 15, 2021
afb46ef
tests: update tests
Alex-Werner Nov 15, 2021
a43369a
fix: integration issues
Alex-Werner Nov 18, 2021
3d2ddbe
feat: introduced ChainStore as new primitives
Alex-Werner Nov 23, 2021
eb52ecf
feat: introduce ChainStorage
Alex-Werner Nov 27, 2021
67c40db
feat: introduce IdentitiesStore
Alex-Werner Nov 27, 2021
ceab121
feat!: Storage now only holds Account, Chain or Wallet Store
Alex-Werner Nov 27, 2021
d40e9db
feat(KeyChain): return newly issued paths on address marked
Alex-Werner Nov 27, 2021
86a1b2d
feat: integrate store and keychains
Alex-Werner Nov 27, 2021
d82fcab
fix: get private keys
Alex-Werner Nov 28, 2021
9522989
tests: update tests
Alex-Werner Nov 28, 2021
0349d5a
fix: broadcastTransaction including chaining
Alex-Werner Nov 28, 2021
f9eb15d
feat!: update plugin injection and additional test fixes
Alex-Werner Nov 29, 2021
d3dd975
feat(WalletStore): move to one file per methods + export/import
Alex-Werner Nov 30, 2021
f9d1399
refact: remove old unused IdentityStore
Alex-Werner Nov 30, 2021
426e919
fix: ensure watched for privateKey
Alex-Werner Nov 30, 2021
4862b71
Removes obsolete stopWorker from the Account
markin-io Dec 1, 2021
d824f5b
Removes obsolete stopWorker from the Account
markin-io Dec 1, 2021
1ba47cc
Fix getTotalBalance.spec.js
markin-io Dec 1, 2021
6968c8f
Prepared a mock for the wallet at getUnusedAddress.spec.js
markin-io Dec 1, 2021
09d6b9a
Fixes test case for getUnusedAddress.spec.js
markin-io Dec 2, 2021
35be5c3
Fixes getUnconfirmedBalance.spec.js
markin-io Dec 2, 2021
c6abcef
Adds cloneDeep to export and import state to prevent messing with the…
markin-io Dec 2, 2021
ec7cc24
Fixes getConfirmedBalance.spec.js, getTransaction.spec.js, getUTXOS.s…
markin-io Dec 2, 2021
46ac52e
feat: test fixes and processing of external keychain on account.importTx
Alex-Werner Dec 9, 2021
1b5b1e4
feat: getTransactionHistory migrate
Alex-Werner Dec 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,087 changes: 1,087 additions & 0 deletions fixtures/chains/for_wallet_c922713eac.json

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions fixtures/chains/testnet/blockheaders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"height": 600000,
"blockheader": "00000020a69faca490012f4371e4bd40a40167809e6fe1b03c9c5dcb7df247f2fa000000b4b8c2d4a78fb35e50a4eda0bd3a5b9b32f4d739b28a4266f24775b3b79d5b61c73275610e04021ea74d0000",
"hash":"000000de786e659950e0f27681faf1a91871d15de264d0b769cb5941c1d807c3"
},
{
"height": 610000,
"blockheader": "00000020af5155e1f8d5b60fb247ac9bb8badbdce1fa72302336c7daab53585caf0000006d495b9629989ac3699d528956b1f617fb51a199ef4277c3f45f4606aba8e461d1c78a61210b011e94ef0000",
"hash":"00000094d124cfb68d6d59ffaec9f7d63965cb894855684e23a586274b49708f"
}
]
14 changes: 14 additions & 0 deletions fixtures/chains/testnet/transactions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"blockHash": "000000b2537d9b3468e02dc6f49fb8bbb5c9d8b77895df1e76816fbad5555d7d",
"transaction": "02000000019583d226737edfad682cc1f0297f688bfca4c0046062ed3e88fa47dd47eab2b2010000006a473044022021550232cc659fa412deb2ea98956faf9ff0efea3a04029bb63022f6809105ce0220230a3f955a3ee7563f5b006342d8db940f3b29f4e312701bf51720575c7a7a8a012103f3d2b2ddfe6ffad2b8fc1708f2eafadfed36bf31a05dfa04b1fc176526475b0ffeffffff02a003d806000000001976a91464220a1c12690ec26d837b3be0a2e3588bb4b79188ac4c5bc92b250000001976a9143e89746b9aa52703ab784bc0df467b160406ffb988acb56b0900",
"height": 617398,
"isInstantLocked": true,
"isChainLocked": true
},
{
"transaction": "0200000001c7d66bb85e0069c221b44b07f49f52cc4f2e54f70e14430b94888327763a66a9010000006b483045022100da5b319f73e6adfee751f33308f5a8c1fceeab2683e15e132d79053b3118639602204262022fb85f88d9802649a289a1134b678efcf708faaeae8f101e8eab785054012102bc626898b49f31f5194de7bc68004401639a20cfa82e4c2eac9684a91fc47a57feffffff0270f2f605000000001976a91464220a1c12690ec26d837b3be0a2e3588bb4b79188ac912e250c250000001976a91415e1edb5c5d9e67d0e36f94343b3eff26bb76d1088ac266e0900",
"blockHash":"0000005c81a683007e86e75c76b4b2feca229f806702ca92953562f2ae628ce7",
"height": 618023
}
]
97 changes: 97 additions & 0 deletions fixtures/wallets/c922713eac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"walletId": "c922713eac",
"state": {
"mnemonic": null,
"paths": {
"m/44'/1'/0'": {
"path": "m/44'/1'/0'",
"addresses": {
"m/0/0": "ycRqwWy2pNzwNumX79MmRyvQYVpy6w3AeX",
"m/0/1": "ycuRYGdNudwRxKNDQBqHDW7aGbJU6uqhXo",
"m/0/2": "yfNFUv1vfx3EVyVGtfZNXqvFR7HLP5MGRq",
"m/0/3": "yjDWQWhNixjKLMjzmXxWqLdJUEcgyjQh1o",
"m/0/4": "ygCCNzQM2Uj7Dfyi6sxPGBmRY6hqHGEFP9",
"m/0/5": "yX5c33WWgLacu7Z1hnBTLKPSXbbGt4BFNt",
"m/0/6": "yYeyVQqiejQsFmkQjtbcigLLPVGJKHxQBL",
"m/0/7": "yTFXnvNARXGPNL1ZKFHyVah3xY6JxzQaPD",
"m/0/8": "yNGpfTzZkJNhEQUk6Wj1VdS8RUVpq6qA2g",
"m/0/9": "ySW43fHX7uTEjJWjozu3EF3bsXywFoo1gf",
"m/0/10": "yM3LdfhFcMQBQoECRrh2WZwy6c8xnsA1rq",
"m/0/11": "ybDdvzUVYvqSPnvdzqgQo1ictZxTjoNTeY",
"m/0/12": "yZLvsg1LuC1q9xa1FqNoKWKHZJTLb1Rs5U",
"m/0/13": "yeGtNDLgTEfSYtYK84kXwvHXwRu3AQprku",
"m/0/14": "yPBq6vmEXnz2FtHVztLHD9HPQf8FMbnRPr",
"m/0/15": "yjcBeyf1r8EkjNFXGgX4NmNQEwk4NNH4Dp",
"m/0/16": "ySCxSmKAfjo8fk15TCM9chiS1dAQfJ54z2",
"m/0/17": "ySBWPfBDnN2iWKt4uRoFaVPGDoRDQpo5i1",
"m/0/18": "yXMhEgMKAknAUTNR31nYr4uSP7GMpmCgsm",
"m/0/19": "yf9Zudcaof9c3KrdPVz3r7YPZJ1U2ECbXE",
"m/1/0": "yXwFx2jAMxxntn421z9PsdzytmHRJGjyU4",
"m/1/1": "yTDBgBUYbPq2XWkrnEWXTZGDcvbPxH1chY",
"m/1/2": "yexVh4ARXbi7ZCUEEGEDde63t91N5e6kfC",
"m/1/3": "ydVc6fZz46csMbAea6xtd1AmW3Zohk9DX5",
"m/1/4": "yWvR7rm6s28SePpVi24AX1pNcBoTubsEcC",
"m/1/5": "yb4yiJrSTstkTrm4Ah9cfkyYmbC3H2TPoS",
"m/1/6": "yb5dJVhq2pi68Qm1ZfzUsux9fCqPdw5GuM",
"m/1/7": "yeSJLf7xsfenJwmwAb28suXpHLwd8bgc2K",
"m/1/8": "yTqDebXPzENywmQiciNjn6U5Hkv7uBYvgm",
"m/1/9": "yegUezShAWzyZfM8WVSj5yzaKzVTRQC9n7",
"m/1/10": "ydtkdeeX8NfAR7thLnzDPwrsiZ7c3a7bVL",
"m/1/11": "yUk83srvLCbpjkiYTpcPpftjGroSeYdHTF",
"m/1/12": "yScDono7QjZPqNJo27eCsrNwUAXFdTLK9P",
"m/1/13": "yZBYJEqmt8rE57unfDRseXBLkdCyfDF9VX",
"m/1/14": "yhhkAYqLNJQyu5XNAT61b2b8Qo7k5Uib1b",
"m/1/15": "yZoLgZuUEmFANWFA8PE2zNVH1Yaz9fciGT",
"m/1/16": "yZQVV3EaLpAehKMpPiGy7w3NRmgKD7xJX1",
"m/1/17": "yQ7SV5m46ck1fVQrJinvA982aBAUv3TCq2",
"m/1/18": "yaaw9BZ16eoXv4RAGBA9qbSrjvTTbqbUKq",
"m/1/19": "yjbLQQkP5tZ3aZ734vFXscFG14vDPnE1rx",
"m/0/20": "yYqmE6MCitNpgyL7iRdNheG2ZP4bNCxoMV",
"m/1/20": "yQpSjWKF6HabXAMizRvMETDd6EbQixXQZ7",
"m/1/21": "yNi1fiMR554w6MehxFoESXwUHk3v6AJELy",
"m/1/22": "yVRRAWki91bieh6eAYjwZZpJLcgmY14D79",
"m/1/23": "yf3NLNnFSnZQuQEFHrAU3Kzdip3AfNXBy3",
"m/1/24": "yTpUMFdpe2WnMz9cjJp3jcDR4G6gXjW5jh",
"m/1/25": "yjPgE4RimwUGZFJpDZjANyioWd1SbZpcaS",
"m/1/26": "ygjDcpfLxzs8pweCQ6Ty8GioNDTgfQX3GQ",
"m/1/27": "yUFchfQMACPyoy6HtqNRv8gjEYKvjd3Wd6",
"m/1/28": "yj1oiPUjyo2RLvpbyigfb7pLiX1piritz1",
"m/1/29": "ycGhUD69dS2V18LFy4qrfYhG1qJ8JnVvX7",
"m/1/30": "yj6f6KLsQHFoVCUmfbpjSGmdqnB3j9NouZ",
"m/1/31": "ycA6K1bW4nxYH8UBvYaXpxmdnMoXPQxp8L",
"m/1/32": "yPx12VyoeVLhMCVDiwK7Js7zDWNtNbq8JV",
"m/1/33": "yMSpVBXff6XoLMwmP7N4nX4Mjo21ewkYkE",
"m/1/34": "yVoywf8fK8VtPEiLyx6zknqWBjE4izUXvD",
"m/1/35": "yU4Xor7Y8XjXFNYmVebqKeaCPqDmKNxbYd",
"m/1/36": "yiE7vzjGNseTtEwtXZTmjcf99hfwLziJPq",
"m/1/37": "yLmXE68Kq8UrK42QjyNWi8gFqf1ihd3UiW",
"m/1/38": "yQnUHRyB768tawz3iLDs5VVLYg5dGEJYQi",
"m/1/39": "yMEnFG5TBqEZXYXTg3PhENtZgGbwhw6qbX",
"m/1/40": "ybPPRHGDK6HUjAapixJaHjpFrBP7p1eNHX",
"m/1/41": "yeKckmFWSPq4ZgxrKtqgWLfspT5YSuinAw",
"m/1/42": "yX5fXtxaF5Umi3wkCvFCCbYjQniex8YfZb",
"m/1/43": "yYXYNLd3pwDnZMo8VvFZWtuTaW97yMBtvh",
"m/1/44": "yPxjUsH2X9SFnpXt4ke7boWdVJb1jLRU2U",
"m/1/45": "yPaJs6aVAxsSsjsaeoWEEf1KWNJHA4osTX",
"m/1/46": "yRtTcfySvuZHmnyTGnSVFJiuXQLAMtA8Zp",
"m/1/47": "yWniGBz9g5WzC8SNw2Yz6rTiw8gXCwviHH",
"m/1/48": "yTBBLUse991FY17xVQxTW6gELhDPLTbrfg",
"m/1/49": "yW8ZcyB43XEaNb1rC3vU8B787pCFd5A92G",
"m/1/50": "yZFMjHZLcw8VLZSfBDamfaowiespUADi8x",
"m/1/51": "yS4CoPF6Bb6vZAorsTQGddhdqzUNA4NQkq",
"m/1/52": "yeKFhYBcoDB5BFQVatGEY6xAWWgyAH2znL",
"m/1/53": "yVtwa9msBFy3s5YW4zpKaRFEAS3CK5h1sd",
"m/1/54": "ySdqTcWTqRHJBwsymifjg4j6hBTUtrhjCo",
"m/1/55": "yXgzDeQ6Fa3gzthByHYeiwyVKYzDov7EtR",
"m/1/56": "yZVUpv1RfnH4gTiTtuarXVpAcK1h9irJ7q",
"m/1/57": "yS4osisWi5dpSmUZFav56Uxj4Uhc3i7RaL",
"m/1/58": "ygAb2f6gztLoPdZrma8BRjm3MtNGZFrUbX",
"m/1/59": "ygukA9r4bM3CDS1gkFfTfVNozC7c5FvnGj"
}
}
},
"identities": {
"0": "D8oTFRQqiKcLEYXZBUVLsM9jBctq7YcM7MAXXT9GJesK"
}
}
}
3 changes: 2 additions & 1 deletion src/CONSTANTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const CONSTANTS = {
PRIVATEKEY: 'privateKey',
// TODO: DEPRECATE.
SINGLE_ADDRESS: 'single_address',
// TODO: DEPRECATE.
HDWALLET: 'hdwallet',
HDPRIVATE: 'hdprivate',
HDPUBLIC: 'hdpublic',
},
// List of account function and properties that can be injected in a plugin
Expand Down Expand Up @@ -79,7 +81,6 @@ const CONSTANTS = {
],
UNSAFE_PROPERTIES: [
'storage',
'keyChain',
'identities',
],
SAFE_PROPERTIES: [
Expand Down
1 change: 1 addition & 0 deletions src/EVENTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
TRANSACTION: 'transaction',
BLOCKHEADER: 'blockheader',
FETCHED_ADDRESS: 'FETCHED/ADDRESS',
UPDATED_ADDRESS: 'UPDATED/ADDRESS',
ERROR_UPDATE_ADDRESS: 'ERROR/UPDATE_ADDRESS',
FETCHED_TRANSACTION: 'FETCHED/TRANSACTION',
FETCHED_UNCONFIRMED_TRANSACTION: 'FETCHED/UNCONFIRMED_TRANSACTION',
Expand Down
4 changes: 2 additions & 2 deletions src/errors/InjectionToPluginUnallowed.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const WalletLibError = require('./WalletLibError');

class InjectionToPluginUnallowed extends WalletLibError {
constructor(pluginName) {
super(`Injection of plugin : ${pluginName} Unallowed`);
constructor(currentPluginName, injectingPluginName) {
super(`Injection of plugin : ${injectingPluginName} into ${currentPluginName} not allowed`);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import { Account } from "./types/Account/Account";
import { Wallet } from "./types/Wallet/Wallet";
import { Identities } from "./types/Identities/Identities";
import { IdentitiesStore } from "./types/IdentitiesStore/IdentitiesStore";
import { KeyChain } from "./types/KeyChain/KeyChain";
import { KeyChainStore } from "./types/KeyChainStore/KeyChainStore";
import { Storage } from "./types/Storage/Storage";
import { ChainStore } from "./types/ChainStore/ChainStore";
import CONSTANTS from "./CONSTANTS";
import EVENTS from "./EVENTS";
import utils from "./utils";
Expand All @@ -13,8 +17,11 @@ import plugins from "./plugins";
export {
Account,
Wallet,
ChainStore,
KeyChain,
KeyChainStore,
Identities,
IdentitiesStore,
EVENTS,
CONSTANTS,
utils,
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
// polyfill included here. Making it work with webpack is rather tricky, so it is used as per
// documentation: https://github.com/YuzuJS/setImmediate#usage
require('setimmediate');
const Wallet = require('./types/Wallet/Wallet');
const Account = require('./types/Account/Account');
const ChainStore = require('./types/ChainStore/ChainStore');
const Identities = require('./types/Identities/Identities');
const KeyChain = require('./types/KeyChain/KeyChain');
const KeyChainStore = require('./types/KeyChainStore/KeyChainStore');
const Storage = require('./types/Storage/Storage');
const Wallet = require('./types/Wallet/Wallet');
const WalletStore = require('./types/WalletStore/WalletStore');
const EVENTS = require('./EVENTS');
const CONSTANTS = require('./CONSTANTS');
const utils = require('./utils');
const plugins = require('./plugins');

module.exports = {
Wallet,
Account,
ChainStore,
Identities,
KeyChain,
KeyChainStore,
Storage,
Wallet,
WalletStore,
EVENTS,
CONSTANTS,
utils,
Expand Down
19 changes: 11 additions & 8 deletions src/plugins/Plugins/ChainPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ class ChainPlugin extends StandardPlugin {
*/
async execBlockListener() {
const self = this;
const { network } = this.storage.store.wallets[this.walletId];
const { network } = this.storage.application;
const chainStore = this.storage.getChainStore(network);

// const { network } = this.storage.store.wallets[this.walletId];

if (!this.isSubscribedToBlocks) {
self.transport.on(EVENTS.BLOCK, async (ev) => {
// const { network } = self.storage.store.wallets[self.walletId];
const { payload: block } = ev;
this.parentEvents.emit(EVENTS.BLOCK, { type: EVENTS.BLOCK, payload: block });
// We do not announce BLOCKHEADER as this is done by Storage
await self.storage.importBlockHeader(block.header);
await chainStore.importBlockHeader(block.header);
});
self.transport.on(EVENTS.BLOCKHEIGHT_CHANGED, async (ev) => {
const { payload: blockheight } = ev;
Expand All @@ -50,7 +53,7 @@ class ChainPlugin extends StandardPlugin {
type: EVENTS.BLOCKHEIGHT_CHANGED, payload: blockheight,
});

this.storage.store.chains[network.toString()].blockHeight = blockheight;
chainStore.state.blockHeight = blockheight;
logger.debug(`ChainPlugin - setting chain blockheight ${blockheight}`);
});
await self.transport.subscribeToBlocks();
Expand All @@ -69,20 +72,20 @@ class ChainPlugin extends StandardPlugin {
return false;
}

const { network } = this.storage.application;
const chainStore = this.storage.getChainStore(network);
const { chain: { blocksCount: blocks }, network: { fee: { relay } } } = res;

const { network } = this.storage.store.wallets[this.walletId];

logger.debug('ChainPlugin - Setting up starting blockHeight', blocks);

this.storage.store.chains[network.toString()].blockHeight = blocks;
chainStore.state.blockHeight = blocks;

if (relay) {
this.storage.store.chains[network.toString()].fees.minRelay = dashToDuffs(relay);
chainStore.state.fees.minRelay = dashToDuffs(relay);
}

const bestBlock = await this.transport.getBlockHeaderByHeight(blocks);
await this.storage.importBlockHeader(bestBlock);
await chainStore.importBlockHeader(bestBlock);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/StandardPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class StandardPlugin extends EventEmitter {
// this.parentEvents = {on:obj.on, emit:obj.emit};
this.parentEvents = obj;
} else {
this.emit('error', new InjectionToPluginUnallowed(name), {
this.emit('error', new InjectionToPluginUnallowed(this.name, name), {
type: 'plugin',
pluginType: 'plugin',
pluginName: this.name,
Expand Down
14 changes: 8 additions & 6 deletions src/plugins/Workers/IdentitySyncWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class IdentitySyncWorker extends Worker {
}

async execute() {
const indexedIds = await this.storage.getIndexedIdentityIds(this.walletId);
const walletStore = this.storage.getWalletStore(this.walletId);
const indexedIds = await walletStore.getIndexedIdentityIds();

// Add gaps to empty indices
const unusedIndices = [];
Expand Down Expand Up @@ -98,11 +99,12 @@ class IdentitySyncWorker extends Worker {
logger.silly(`IdentitySyncWorker - got ${Identifier.from(fetchedId)} at ${index}`);

// eslint-disable-next-line no-await-in-loop
await this.storage.insertIdentityIdAtIndex(
this.walletId,
Identifier.from(fetchedId).toString(),
index,
);
await this.storage
.getWalletStore(this.walletId)
.insertIdentityIdAtIndex(
Identifier.from(fetchedId).toString(),
index,
);
}

logger.silly('IdentitySyncWorker - sync finished');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TransactionSyncStreamWorker extends Worker {
'importBlockHeader',
'importInstantLock',
'storage',
'keyChainStore',
'transport',
'walletId',
'getAddress',
Expand All @@ -49,12 +50,11 @@ class TransactionSyncStreamWorker extends Worker {
* @param {string[]} addressList
* @param {string} network
*/
static filterWalletTransactions(transactions, addressList, network) {
static filterAddressesTransactions(transactions, addressList, network) {
const spentOutputs = [];
const unspentOutputs = [];
const filteredTransactions = transactions.filter((tx) => {
let isWalletTransaction = false;

tx.inputs.forEach((input) => {
if (input.script) {
const addr = input.script.toAddress(network).toString();
Expand Down Expand Up @@ -124,7 +124,6 @@ class TransactionSyncStreamWorker extends Worker {
.getMessagesList()
.map((instantSendLock) => new InstantLock(Buffer.from(instantSendLock)));
}

return walletTransactions;
}

Expand All @@ -135,11 +134,11 @@ class TransactionSyncStreamWorker extends Worker {
const {
skipSynchronizationBeforeHeight,
skipSynchronization,
} = (this.storage.store.syncOptions || {});
} = (this.storage.application.syncOptions || {});

if (skipSynchronization) {
logger.debug('TransactionSyncStreamWorker - Wallet created from a new mnemonic. Sync from the best block height.');
const bestBlockHeight = this.storage.store.chains[this.network.toString()].blockHeight;
const bestBlockHeight = this.storage.getChainStore(this.network.toString()).blockHeight;
this.setLastSyncedBlockHeight(bestBlockHeight);
return;
}
Expand Down Expand Up @@ -238,25 +237,15 @@ class TransactionSyncStreamWorker extends Worker {
}

setLastSyncedBlockHash(hash) {
const { walletId } = this;
const accountsStore = this.storage.store.wallets[walletId].accounts;
const applicationStore = this.storage.application;

const accountStore = ([WALLET_TYPES.HDWALLET, WALLET_TYPES.HDPUBLIC].includes(this.walletType))
? accountsStore[this.BIP44PATH.toString()]
: accountsStore[this.index.toString()];
applicationStore.blockHash = hash;

accountStore.blockHash = hash;

return accountStore.blockHash;
return applicationStore.blockHash;
}

getLastSyncedBlockHash() {
const { walletId } = this;
const accountsStore = this.storage.store.wallets[walletId].accounts;

const { blockHash } = ([WALLET_TYPES.HDWALLET, WALLET_TYPES.HDPUBLIC].includes(this.walletType))
? accountsStore[this.BIP44PATH.toString()]
: accountsStore[this.index.toString()];
const { blockHash } = this.storage.application;

return blockHash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const logger = require('../../../../logger');

function onStreamError(error, reject) {
logger.silly('TransactionSyncStreamWorker - end stream on error');
logger.silly(error.message);
reject(error);
}
module.exports = onStreamError;
Loading