This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: comportement on new address with existing transaction in store (#…
…147) * refactor(BIP44Worker): split functions into individual files * fix(Storage): not processing transaction on new generated address * doc: fix lint for internal doc * fix: processing tx only once but at least once
- Loading branch information
1 parent
587a9bc
commit b17c291
Showing
4 changed files
with
76 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/plugins/Workers/BIP44Worker/utils/getMissingIndexes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const is = require('../../../../utils/is'); | ||
|
||
module.exports = function getMissingIndexes(paths, fromOrigin = true) { | ||
if (!is.arr(paths)) return false; | ||
|
||
let sortedIndexes = []; | ||
|
||
paths.forEach((path) => { | ||
const splitedPath = path.split('/'); | ||
const index = parseInt(splitedPath[5], 10); | ||
sortedIndexes.push(index); | ||
}); | ||
|
||
sortedIndexes = sortedIndexes.sort((a, b) => a - b); | ||
|
||
let missingIndex = sortedIndexes.reduce((acc, cur, ind, arr) => { | ||
const diff = cur - arr[ind - 1]; | ||
if (diff > 1) { | ||
let i = 1; | ||
while (i < diff) { | ||
acc.push(arr[ind - 1] + i); | ||
i += 1; | ||
} | ||
} | ||
return acc; | ||
}, []); | ||
|
||
// Will fix missing index before our first known indexes | ||
if (fromOrigin) { | ||
if (sortedIndexes[0] > 0) { | ||
for (let i = sortedIndexes[0] - 1; i >= 0; i -= 1) { | ||
missingIndex.push(i); | ||
} | ||
} | ||
} | ||
|
||
missingIndex = missingIndex.sort((a, b) => a - b); | ||
return missingIndex; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const is = require('../../../../utils/is'); | ||
|
||
module.exports = function isContiguousPath(currPath, prevPath) { | ||
if (is.undef(currPath)) return false; | ||
|
||
const splitedCurrPath = currPath.split('/'); | ||
const currIndex = parseInt(splitedCurrPath[5], 10); | ||
|
||
if (is.undef(prevPath)) { | ||
return currIndex === 0; | ||
} | ||
const splitedPrevPath = prevPath.split('/'); | ||
const prevIndex = parseInt(splitedPrevPath[5], 10); | ||
return prevIndex === currIndex - 1; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters