Skip to content

Commit

Permalink
Consolidate EBT code in ebt file
Browse files Browse the repository at this point in the history
  • Loading branch information
arj03 committed Oct 28, 2020
1 parent 867c6f0 commit fbdb342
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ exports.init = function (dir, config) {
state = validate.appendNew(state, null, net.config.keys, msg, Date.now())
//console.log(state.queue[0])
db.add(state.queue[0].value, (err, data) => {
net.post(data.value) // tell ebt
net.ebt.onPost(data)
cb(err, data)
})
},
Expand Down
16 changes: 9 additions & 7 deletions simple-ebt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var path = require('path')
var toPull = require('push-stream-to-pull-stream')
var isFeed = require('ssb-ref').isFeed

const { originalData } = require('./msg-utils')

var AtomicFile = require('atomic-file')

exports.name = 'ebt'
Expand Down Expand Up @@ -48,12 +50,13 @@ exports.init = function (sbot, config) {
f.set(clock)
},
getAt: function (pair, cb) {
sbot.getAtSequence([pair.id, pair.sequence], function (err, data) {
cb(err, data ? data.value : null)
SSB.db.getDataFromAuthorSequence([pair.id, pair.sequence], (err, value) => {
if (err) cb(err)
else cb(null, originalData(value).value)
})
},
append: function (msg, cb) {
sbot.add(msg, function (err, msg) {
SSB.db.validateAndAdd(msg, (err, msg) => {
cb(err && err.fatal ? err : null, msg)
})
},
Expand All @@ -76,15 +79,14 @@ exports.init = function (sbot, config) {

SSB.events.on('SSB: loaded', updateClock)

sbot.post(function(msg) {
ebt.onAppend(msg.value)
})

function onClose() {
sbot.emit('replicate:finish', ebt.state.clock)
}

return {
onPost: function(msg) {
ebt.onAppend(msg.value)
},
updateClock,
replicate: function(opts) {
if (opts.version != 3)
Expand Down
17 changes: 0 additions & 17 deletions ssb-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

const pull = require('pull-stream')
const pullCont = require('pull-cont')
var Obv = require('obv')
const { originalData } = require('./msg-utils')

exports.manifest = {
Expand Down Expand Up @@ -76,21 +75,5 @@ exports.init = function (sbot, config) {
)
}

// all the rest is ebt stuff

sbot.post = Obv()

sbot.add = function(msg, cb) {
SSB.db.validateAndAdd(msg, cb)
}

sbot.getAtSequence = function (seqid, cb) {
// will NOT expose private plaintext
SSB.db.getDataFromAuthorSequence((typeof seqid === 'string') ? seqid.split(':') : seqid, function (err, value) {
if (err) cb(err)
else cb(null, originalData(value))
})
}

return {}
}

0 comments on commit fbdb342

Please sign in to comment.