Commit 27ff705435b6458d192cfb844027d32cd144a183
don't rehash root
wanderer committed on 3/22/2018, 12:58:23 AMParent: 3cd983ac8d618fa6a28393d6beee5e609408ded4
Files changed
datastore.js | changed |
tests/index.js | changed |
datastore.js | ||
---|---|---|
@@ -5,8 +5,11 @@ | ||
5 | 5 | const cbor = require('borc') |
6 | 6 | |
7 | 7 | module.exports = class TreeDAG extends DAG { |
8 | 8 | async put (val) { |
9 | + if (TreeDAG.isValidLink(val)) { | |
10 | + return val | |
11 | + } | |
9 | 12 | const encoded = cbor.encode(val) |
10 | 13 | const key = await TreeDAG.getMerkleLink(encoded) |
11 | 14 | |
12 | 15 | return new Promise((resolve, reject) => { |
tests/index.js | ||
---|---|---|
@@ -3,8 +3,19 @@ | ||
3 | 3 | const level = require('level-browserify') |
4 | 4 | const RadixTree = require('../') |
5 | 5 | const db = level('./testdb') |
6 | 6 | |
7 | +tape.only('set and get', async t => { | |
8 | + let tree = new RadixTree({ | |
9 | + db: db | |
10 | + }) | |
11 | + const stateRoot = await tree.flush() | |
12 | + console.log(stateRoot) | |
13 | + const stateRoot2 = await tree.flush() | |
14 | + console.log(stateRoot2) | |
15 | + t.end() | |
16 | +}) | |
17 | + | |
7 | 18 | tape('set and get', async t => { |
8 | 19 | const r = await RadixTree.getMerkleLink(Buffer.from([0])) |
9 | 20 | |
10 | 21 | t.equal(r.toString('hex'), '6e340b9cffb37a989ca544e6bb780a2c78901d3f', 'should hash') |
Built with git-ssb-web