-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from BoltzExchange/swaptree-compare
SwapTree compare function
- Loading branch information
Showing
10 changed files
with
417 additions
and
175 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
Submodule forge-std
updated
27 files
+0 −3 | .gitmodules | |
+1 −1 | README.md | |
+1 −1 | foundry.toml | |
+0 −1 | lib/ds-test | |
+1 −1 | scripts/vm.py | |
+518 −225 | src/StdAssertions.sol | |
+3 −1 | src/StdChains.sol | |
+7 −11 | src/StdJson.sol | |
+201 −106 | src/StdStorage.sol | |
+179 −0 | src/StdToml.sol | |
+4 −4 | src/Test.sol | |
+525 −1 | src/Vm.sol | |
+51 −33 | src/mocks/MockERC20.sol | |
+46 −32 | src/mocks/MockERC721.sol | |
+39 −909 | test/StdAssertions.t.sol | |
+29 −24 | test/StdChains.t.sol | |
+18 −10 | test/StdCheats.t.sol | |
+49 −0 | test/StdJson.t.sol | |
+8 −8 | test/StdMath.t.sol | |
+159 −11 | test/StdStorage.t.sol | |
+49 −0 | test/StdToml.t.sol | |
+18 −18 | test/StdUtils.t.sol | |
+3 −3 | test/Vm.t.sol | |
+8 −0 | test/fixtures/test.json | |
+6 −0 | test/fixtures/test.toml | |
+1 −1 | test/mocks/MockERC20.t.sol | |
+1 −1 | test/mocks/MockERC721.t.sol |
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
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
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
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
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,26 @@ | ||
import { Taptree } from 'bitcoinjs-lib/src/types'; | ||
import { SwapTree, Tapleaf } from '../consts/Types'; | ||
|
||
const compareLeaf = (leaf: Tapleaf, compareLeaf: Tapleaf) => | ||
leaf.version === compareLeaf.version && | ||
leaf.output.equals(compareLeaf.output); | ||
|
||
const compareTree = (tree: Taptree, compare: Taptree) => { | ||
if (Array.isArray(tree) !== Array.isArray(compare)) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(tree) && Array.isArray(compare)) { | ||
return ( | ||
tree.length === compare.length && | ||
tree.every((leaf, i) => compareTree(leaf, compare[i])) | ||
); | ||
} else { | ||
return compareLeaf(tree as Tapleaf, compare as Tapleaf); | ||
} | ||
}; | ||
|
||
export const compareTrees = <T extends SwapTree>( | ||
tree: T, | ||
compare: T, | ||
): boolean => compareTree(tree.tree, compare.tree); |
Oops, something went wrong.