diff --git a/core.js b/core.js index 1e0cbdc..98aa966 100644 --- a/core.js +++ b/core.js @@ -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) }) }, diff --git a/simple-ebt.js b/simple-ebt.js index 6e4f1ed..8039953 100644 --- a/simple-ebt.js +++ b/simple-ebt.js @@ -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' @@ -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) }) }, @@ -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) diff --git a/ssb-db.js b/ssb-db.js index b7cf572..ac0544a 100644 --- a/ssb-db.js +++ b/ssb-db.js @@ -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 = { @@ -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 {} }