Skip to content

Commit

Permalink
Merge pull request #33 from akifoq/main
Browse files Browse the repository at this point in the history
Merkle proofs: export new functions + throw on missing keys
  • Loading branch information
dvlkv authored May 20, 2024
2 parents 56f30d7 + 1733779 commit 2cd5401
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/dict/Dictionary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ describe('Dictionary', () => {
dictHash
);
}

expect(() => d.generateMerkleProof([6])).toThrow();
});

it('should generate merkle updates', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/dict/generateMerkleProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ export function generateMerkleProofDirect<K extends DictionaryKeyTypes, V>(
keys: K[],
keyObject: DictionaryKey<K>
): Cell {
keys = keys.filter((key) => dict.has(key));
keys.forEach((key) => {
if (!dict.has(key)) {
throw new Error(`Trying to generate merkle proof for a missing key "${key}"`)
}
})
const s = beginCell().storeDictDirect(dict).asSlice();
return doGenerateMerkleProof(
'',
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export { Writable } from './boc/Writable';
export { Dictionary, DictionaryKey, DictionaryKeyTypes, DictionaryValue } from './dict/Dictionary';

// Exotics
export { exoticMerkleProof } from './boc/cell/exoticMerkleProof';
export { exoticMerkleProof, convertToMerkleProof } from './boc/cell/exoticMerkleProof';
export { exoticMerkleUpdate } from './boc/cell/exoticMerkleUpdate';
export { exoticPruned } from './boc/cell/exoticPruned';

// Merkle trees
export { generateMerkleProof } from './dict/generateMerkleProof'
export { generateMerkleProof, generateMerkleProofDirect } from './dict/generateMerkleProof'
export { generateMerkleUpdate } from './dict/generateMerkleUpdate'

// Tuples
Expand Down

0 comments on commit 2cd5401

Please sign in to comment.