diff --git a/recording_blockstore/recording_blockstore.go b/recording_blockstore/recording_blockstore.go index 73c897b..954a965 100644 --- a/recording_blockstore/recording_blockstore.go +++ b/recording_blockstore/recording_blockstore.go @@ -20,6 +20,7 @@ func New(base blockstore.Blockstore) *RecordingBlockstore { return &RecordingBlockstore{ base: base, inserts: make(map[cid.Cid]blockformat.Block), + reads: make(map[cid.Cid]blockformat.Block), } } diff --git a/server/handle_sync_get_blocks.go b/server/handle_sync_get_blocks.go index e99cc53..7fe5d48 100644 --- a/server/handle_sync_get_blocks.go +++ b/server/handle_sync_get_blocks.go @@ -11,20 +11,22 @@ import ( "github.com/labstack/echo/v4" ) +type ComAtprotoSyncGetBlocksRequest struct { + Did string `query:"did"` + Cids []string `query:"cids"` +} + func (s *Server) handleGetBlocks(e echo.Context) error { ctx := e.Request().Context() - did := e.QueryParam("did") - if did == "" { - return helpers.InputError(e, nil) - } - cidstrs, ok := e.QueryParams()["cids"] - if !ok { + var req ComAtprotoSyncGetBlocksRequest + if err := e.Bind(&req); err != nil { return helpers.InputError(e, nil) } + var cids []cid.Cid - for _, cs := range cidstrs { + for _, cs := range req.Cids { c, err := cid.Cast([]byte(cs)) if err != nil { return err @@ -33,7 +35,7 @@ func (s *Server) handleGetBlocks(e echo.Context) error { cids = append(cids, c) } - urepo, err := s.getRepoActorByDid(did) + urepo, err := s.getRepoActorByDid(req.Did) if err != nil { return helpers.ServerError(e, nil) } diff --git a/server/repo.go b/server/repo.go index 77b0626..663218b 100644 --- a/server/repo.go +++ b/server/repo.go @@ -104,7 +104,7 @@ func (rm *RepoMan) applyWrites(urepo models.Repo, writes []Op, swapCommit *strin dbs := rm.s.getBlockstore(urepo.Did) bs := recording_blockstore.New(dbs) - r, err := repo.OpenRepo(context.TODO(), dbs, rootcid) + r, err := repo.OpenRepo(context.TODO(), bs, rootcid) entries := []models.Record{} var results []ApplyWriteResult diff --git a/sqlite_blockstore/sqlite_blockstore.go b/sqlite_blockstore/sqlite_blockstore.go index 5c7fcb3..c670280 100644 --- a/sqlite_blockstore/sqlite_blockstore.go +++ b/sqlite_blockstore/sqlite_blockstore.go @@ -135,21 +135,3 @@ func (bs *SqliteBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, er func (bs *SqliteBlockstore) HashOnRead(enabled bool) { panic("not implemented") } - -func (bs *SqliteBlockstore) Execute(ctx context.Context) error { - if !bs.readonly { - return fmt.Errorf("blockstore was not readonly") - } - - bs.readonly = false - for _, b := range bs.inserts { - bs.Put(ctx, b) - } - bs.readonly = true - - return nil -} - -func (bs *SqliteBlockstore) GetLog() map[cid.Cid]blocks.Block { - return bs.inserts -}