Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Looking at the replication events and data for an OrbitDB key-value store.
- Here is a snippet of the code I'm looking at, based on this Event
- documentation:
- https://github.com/orbitdb/orbit-db-store#events
- */
- // Load data persisted to the hard drive.
- await this.db.load()
- // console.log('this.db: ', this.db)
- // Studying events:
- // https://github.com/orbitdb/orbit-db-store#replicationstatus
- this.db.events.on('replicated', (address, count) => {
- console.log('replicated event fired')
- console.log('replicated address: ', address)
- console.log('replicated count: ', count)
- })
- this.db.events.on('replicate', (address, entry) => {
- console.log('replicate event fired')
- console.log('replicate address: ', address)
- console.log('replicate entry: ', entry)
- const data = this.db.get(entry)
- console.log('entry data: ', data)
- const all = this.db.all
- console.log('all entries: ', all)
- })
- this.db.events.on('write', (address, entry, heads) => {
- console.log('write event fired!')
- console.log('write address: ', address)
- console.log('write entry: ', entry)
- console.log('write heads: ', heads)
- })
- console.log('...finished createDb()')
- /*
- The above code produces this output on the console:
- replicate event fired
- replicate address: /orbitdb/zdpuAvLPKXcHLneHE7NmPjQtDfbcbRy69pioRE1n4is3xhd4U/testdb009/_access
- replicate entry: {
- hash: 'zdpuAroa3Hqu9v5mKXvbQ5qxj4SHvEfT7vBkHZY3xaHQk4Mdj',
- id: '/orbitdb/zdpuAvLPKXcHLneHE7NmPjQtDfbcbRy69pioRE1n4is3xhd4U/testdb009/_access',
- payload: { op: 'PUT', key: 'write', value: [ '*' ] },
- next: [ 'zdpuAnAVCL1zJ6V545G8ev6g2CfkW3nPsvyWrhaaNpHYBc7em' ],
- refs: [ 'zdpuB1sr6B4soQc7U4eCbkB1e8SCUxCgBP1g5Uog6L17uPgWS' ],
- v: 2,
- clock: {
- id: '04fb1bcc9d4c7d12ae30eb2aee1cdfd80eec75733db574e24b5f426041e8b1212019afcddb2321c169370e86a23c61965f83d9e1e6b8df93f4b2de4582c8bc163e',
- time: 3
- },
- key: '04fb1bcc9d4c7d12ae30eb2aee1cdfd80eec75733db574e24b5f426041e8b1212019afcddb2321c169370e86a23c61965f83d9e1e6b8df93f4b2de4582c8bc163e',
- identity: {
- id: '03db9af05643d65cb9f741b5898bd4962998922f500a58cf407b32d444f580c6f8',
- publicKey: '04fb1bcc9d4c7d12ae30eb2aee1cdfd80eec75733db574e24b5f426041e8b1212019afcddb2321c169370e86a23c61965f83d9e1e6b8df93f4b2de4582c8bc163e',
- signatures: {
- id: '3044022059a83a3d28129f855a8b0a508d02e45982b8916e64a37492f6f0f4cddba633cc022001f729f78628412fcecc59b7c4ba479f18fc602dccae256195aa6ec02aa2d6f7',
- publicKey: '304402207cd87f0d5d4dc3e7efaf336ffcfeba895558d6cfd04447800b8f481fa59fd5d0022063d863929b970ee0b94e32682584f7f119094f168830cca7b5275b6684d324b1'
- },
- type: 'orbitdb'
- },
- sig: '304502210089fece55e7ca1429d2efd65315ad221799807d4010ebd0d225038ee4a00dae4502201391ff5285bb6758b1dde6def80636c27d7518a4db90dba731766b72d41e7e88'
- }
- entry data: undefined
- all entries: {}
- replicate event fired
- replicate address: /orbitdb/zdpuAvLPKXcHLneHE7NmPjQtDfbcbRy69pioRE1n4is3xhd4U/testdb009/_access
- replicate entry: zdpuAnAVCL1zJ6V545G8ev6g2CfkW3nPsvyWrhaaNpHYBc7em
- entry data: undefined
- all entries: { write: [ '*' ] }
- replicated event fired
- replicated address: /orbitdb/zdpuAvLPKXcHLneHE7NmPjQtDfbcbRy69pioRE1n4is3xhd4U/testdb009/_access
- replicated count: 1
- replicate event fired
- replicate address: /orbitdb/zdpuAvLPKXcHLneHE7NmPjQtDfbcbRy69pioRE1n4is3xhd4U/testdb009/_access
- replicate entry: zdpuB1sr6B4soQc7U4eCbkB1e8SCUxCgBP1g5Uog6L17uPgWS
- entry data: undefined
- all entries: { write: [ '*' ] }
- replicated event fired
- replicated address: /orbitdb/zdpuAvLPKXcHLneHE7NmPjQtDfbcbRy69pioRE1n4is3xhd4U/testdb009/_access
- replicated count: 1
- replicated event fired
- replicated address: /orbitdb/zdpuAvLPKXcHLneHE7NmPjQtDfbcbRy69pioRE1n4is3xhd4U/testdb009/_access
- replicated count: 1
- Question:
- Given a hash like this:
- zdpuB1sr6B4soQc7U4eCbkB1e8SCUxCgBP1g5Uog6L17uPgWS
- How do I get the actualy key-value entry represented by that hash?
- */
Advertisement
Add Comment
Please, Sign In to add comment