-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add context-wrapped store and blockstore (#41)
Co-authored-by: Aayush Rajasekaran <[email protected]>
- Loading branch information
1 parent
eebb23b
commit 6c6a4a8
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |