Skip to content

Commit

Permalink
Add context-wrapped store and blockstore (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Aayush Rajasekaran <[email protected]>
  • Loading branch information
geoff-vball and arajasek authored Jun 10, 2022
1 parent eebb23b commit 6c6a4a8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions store/ctx_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package store

import (
"context"

ipldcbor "github.com/ipfs/go-ipld-cbor"
)

type Store interface {
Context() context.Context
ipldcbor.IpldStore
}

// WrapStore Adapts a vanilla IPLD store as an ADT store.
func WrapStore(ctx context.Context, store ipldcbor.IpldStore) Store {
return &wstore{
ctx: ctx,
IpldStore: store,
}
}

// WrapBlockStore Adapts a block store as an ADT store.
func WrapBlockStore(ctx context.Context, bs ipldcbor.IpldBlockstore) Store {
return WrapStore(ctx, ipldcbor.NewCborStore(bs))
}

type wstore struct {
ctx context.Context
ipldcbor.IpldStore
}

var _ Store = &wstore{}

func (s *wstore) Context() context.Context {
return s.ctx
}

0 comments on commit 6c6a4a8

Please sign in to comment.