generated from ipfs/ipfs-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blockservice: add session workaround to work with wrapped blockservices
- Loading branch information
Showing
3 changed files
with
96 additions
and
20 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
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
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,37 @@ | ||
package blockservice | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ipfs/boxo/blockstore" | ||
"github.com/ipfs/boxo/provider" | ||
blocks "github.com/ipfs/go-block-format" | ||
) | ||
|
||
var _ blockstore.Blockstore = providingBlockstore{} | ||
|
||
type providingBlockstore struct { | ||
blockstore.Blockstore | ||
provider provider.Provider | ||
} | ||
|
||
func (pbs providingBlockstore) Put(ctx context.Context, b blocks.Block) error { | ||
if err := pbs.Blockstore.Put(ctx, b); err != nil { | ||
return err | ||
} | ||
|
||
return pbs.provider.Provide(b.Cid()) | ||
} | ||
|
||
func (pbs providingBlockstore) PutMany(ctx context.Context, b []blocks.Block) error { | ||
if err := pbs.Blockstore.PutMany(ctx, b); err != nil { | ||
return err // what are the semantics here, did some blocks were put ? assume PutMany is atomic | ||
} | ||
|
||
for _, b := range b { | ||
if err := pbs.provider.Provide(b.Cid()); err != nil { | ||
return err // this can only error if the whole provider is done for | ||
} | ||
} | ||
return nil | ||
} |