Skip to content

Instantly share code, notes, and snippets.

View gabrocheleau's full-sized avatar
🐕

Gabriel Rocheleau gabrocheleau

🐕
View GitHub Profile
@gabrocheleau
gabrocheleau / Markdium-Shell.bash
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
git clone https://github.com/gabrocheleau/merkle-patricia-tree-examples.git
cd merkle-patricia-tree-examples/
npm install
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
await trie1.put(Buffer.from('testKey'), Buffer.from('testValue'))
await trie1.put(Buffer.from('testKey0001'), Buffer.from('testValue1'))
await trie1.put(Buffer.from('testKey000A'), Buffer.from('testValueA')) // What Marie claims
await trie2.put(Buffer.from('testKey'), Buffer.from('testValue'))
await trie2.put(Buffer.from('testKey0001'), Buffer.from('testValue1'))
await trie2.put(Buffer.from('testKey000z'), Buffer.from('testValuez')) // What John claims
var temp1 = await trie1.findPath(Buffer.from('testKey'))
var temp2 = await trie2.findPath(Buffer.from('testKey'))
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
console.log('Value of branch at index 3: ', node1.node._branches[3][1].toString())
console.log('Value of branch at index 4: ', node1.node._branches[4][1].toString())
// RESULT
Value of branch at index 3: testValue0
Value of branch at index 4: testValueA
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
async function test() {
var node1 = await trie.findPath(Buffer.from('testKey')) // We attempt to retrieve the node using the key "testKey"
console.log('Node 1: ', node1.node) // null
}
test()
// RESULT
Node 1: null
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
var node1 = await trie.findPath(Buffer.from('testKey0')) // We retrieve one of the leaf nodes
console.log('Node 1: ', node1.node) // A leaf node! We can see that it contains 2 items: the encodedPath and the value
console.log('Node 1 value: ', node1.node._value.toString()) // The leaf node's value
// RESULT
Node 1: LeafNode {
_nibbles: [ 0 ],
_value:
}
Node 1 value: testValue0
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
console.log('Node value: ', node1.node._value.toString()) // The branch node's value
// RESULT
Node value: testValue
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
await trie.put(Buffer.from('testKey0'), Buffer.from('testValue0'))
await trie.put(Buffer.from('testKeyA'), Buffer.from('testValueA'))
var node1 = await trie.findPath(Buffer.from('testKey')) // We retrieve the node at the "branching" off of the keys
console.log('Node: ', node1.node) // A branch node!
console.log('Node value: ', node1.node._value) // The branch node's value, in this case an empty buffer since the key "testValue" isn't assigned a value
// RESULT
Node: BranchNode {
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
console.log(Buffer.from('testKey0001'))
console.log(Buffer.from('testKey000A'))
// RESULT
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
// <--path--> <------------- value ----------------->
[ , ] // going down the path of "testKey0"
[ , ] // going down the path of "testKeyA"
@gabrocheleau
gabrocheleau / Markdium-JSX.jsx
Created June 20, 2020 02:52
Markdium-Ethereum's Merkle Patricia Trees
// <------ same ------> <-> (different)
// "testKey0", "0" = 30 in bytes
// "testKeyA", "A" = 41 in bytes