|
| 1 | +# Solidity Patricia Tree |
| 2 | + |
| 3 | +## Credits |
| 4 | + |
| 5 | +This is a rewritten version of [Christian Reitwießner](https://github.com/chriseth)'s [patricia-tree](https://github.com/chriseth/patricia-tree) to use his patricia tree implementation as a solidity library through npm. |
| 6 | + |
| 7 | + |
| 8 | +##### latest released version |
| 9 | +[](https://www.npmjs.com/package/solidity-patricia-tree) |
| 10 | +[](https://travis-ci.org/commitground/solidity-patricia-tree) |
| 11 | +[](https://coveralls.io/github/commitground/solidity-patricia-tree?branch=develop) |
| 12 | + |
| 13 | +##### in progress |
| 14 | +[](https://www.npmjs.com/package/solidity-patricia-tree) |
| 15 | +[](https://travis-ci.org/commitground/solidity-patricia-tree) |
| 16 | +[](https://coveralls.io/github/commitground/solidity-patricia-tree?branch=develop) |
| 17 | + |
| 18 | +[](https://github.com/standard/standard) |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +```bash |
| 25 | +npm i solidity-patricia-tree |
| 26 | +``` |
| 27 | + |
| 28 | +```solidity |
| 29 | +pragma solidity ^0.4.25; |
| 30 | +
|
| 31 | +import {PatriciaTree} from "solidity-patricia-tree/contracts/tree.sol"; |
| 32 | +contract YourContract { |
| 33 | + using PatriciaTree for PatriciaTree.Tree; |
| 34 | +
|
| 35 | + function test() { |
| 36 | + //testInsert(); |
| 37 | + testProofs(); |
| 38 | + } |
| 39 | + function testInsert() internal { |
| 40 | + PatriciaTree.Tree memory tree; |
| 41 | + tree.insert("one", "ONE"); |
| 42 | + tree.insert("two", "ONE"); |
| 43 | + tree.insert("three", "ONE"); |
| 44 | + tree.insert("four", "ONE"); |
| 45 | + tree.insert("five", "ONE"); |
| 46 | + tree.insert("six", "ONE"); |
| 47 | + tree.insert("seven", "ONE"); |
| 48 | + // update |
| 49 | + tree.insert("one", "TWO"); |
| 50 | + } |
| 51 | + function testProofs() internal { |
| 52 | + PatriciaTree.Tree memory tree; |
| 53 | + tree.insert("one", "ONE"); |
| 54 | + uint branchMask; |
| 55 | + bytes32[] siblings; |
| 56 | + (branchMask, siblings) = tree.getProof("one"); |
| 57 | + tree.verifyProof(root, "one", "ONE", branchMask, siblings); |
| 58 | + tree.insert("two", "TWO"); |
| 59 | + (branchMask, siblings) = tree.getProof("one"); |
| 60 | + tree.verifyProof(root, "one", "ONE", branchMask, siblings); |
| 61 | + (branchMask, siblings) = tree.getProof("two"); |
| 62 | + tree.verifyProof(root, "two", "TWO", branchMask, siblings); |
| 63 | + } |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | + |
| 68 | +## Development |
| 69 | + |
| 70 | +### Pre-requisites |
| 71 | + |
| 72 | +```bash |
| 73 | +npm install -g truffle |
| 74 | +npm install -g ganache |
| 75 | +npm install |
| 76 | +``` |
| 77 | + |
| 78 | +### Tests |
| 79 | + |
| 80 | +Test cases include the information about how the functions work, but also includes a demo scenario. |
| 81 | +Running and reading the test cases will help you understand how it works. |
| 82 | + |
| 83 | +```bash |
| 84 | +npm run test |
| 85 | +``` |
| 86 | + |
| 87 | + |
| 88 | +## Contributors |
| 89 | +- Original author: [Christian Reitwießner](https://github.com/chriseth) |
| 90 | +- [Wanseob Lim](https://github.com/james-lim)<[email@wanseob.com](mailto:email@wanseob.com)> |
| 91 | + |
| 92 | +## License |
| 93 | + |
| 94 | +[MIT LICENSE](./LICENSE) |
0 commit comments