Skip to content

Commit

Permalink
feat: return location commitment in blob/accept receipt (#15)
Browse files Browse the repository at this point in the history
This PR augments the blob/accept handler to return the location
commitment in the receipt effects.
  • Loading branch information
alanshaw authored Oct 28, 2024
1 parent 3644eb9 commit 17af5b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/multiformats/go-multihash v0.2.3
github.com/storacha/go-capabilities v0.0.0-20241021134022-7144600f5aeb
github.com/storacha/go-metadata v0.0.0-20241021141939-f94d93dcda78
github.com/storacha/go-ucanto v0.1.1-0.20241028093931-42d9e1db4bfb
github.com/storacha/go-ucanto v0.1.1-0.20241028163940-34de8cd912bb
github.com/storacha/ipni-publisher v0.0.0-20241018055706-032286a2dc3f
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ github.com/storacha/go-capabilities v0.0.0-20241021134022-7144600f5aeb h1:A9/44D
github.com/storacha/go-capabilities v0.0.0-20241021134022-7144600f5aeb/go.mod h1:1x2qMcvOUvF6prSiWXsEeEfV3OcX/L2fk6iNgPMNfZU=
github.com/storacha/go-metadata v0.0.0-20241021141939-f94d93dcda78 h1:NAti9hMLMo8F0Iyz5ldS41CY6MyukRH0OrTPV4u2340=
github.com/storacha/go-metadata v0.0.0-20241021141939-f94d93dcda78/go.mod h1:DcwwQnyFuTk531cKD9sUkQg/gzpwKaIqH9I7oZYyeRc=
github.com/storacha/go-ucanto v0.1.1-0.20241028093931-42d9e1db4bfb h1:bjubXTmLyLl7eap6HhIoFmwIH6H4CCtnJlcE4hbc2Qo=
github.com/storacha/go-ucanto v0.1.1-0.20241028093931-42d9e1db4bfb/go.mod h1:7ba9jAgqmwlF/JfyFUQcGV07uiYNlmJNu8qH4hHtrJk=
github.com/storacha/go-ucanto v0.1.1-0.20241028163940-34de8cd912bb h1:lFwFtMjgt162ot9pnu230haLjRQ1rqwJOIAyywOqAX8=
github.com/storacha/go-ucanto v0.1.1-0.20241028163940-34de8cd912bb/go.mod h1:7ba9jAgqmwlF/JfyFUQcGV07uiYNlmJNu8qH4hHtrJk=
github.com/storacha/ipni-publisher v0.0.0-20241018055706-032286a2dc3f h1:62fTASO3wRPCWCkl6we2DftsFy/DfbmVpwJyqK7gmUc=
github.com/storacha/ipni-publisher v0.0.0-20241018055706-032286a2dc3f/go.mod h1:fEuGSF5WMaOSAyDQCYAvow6Y+YKzpXczEk3A+H+s1fQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/publisher/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/storacha/go-ucanto/client"
"github.com/storacha/go-ucanto/core/delegation"
"github.com/storacha/go-ucanto/core/invocation"
"github.com/storacha/go-ucanto/core/receipt"
"github.com/storacha/go-ucanto/core/receipt/fx"
"github.com/storacha/go-ucanto/core/result/ok"
"github.com/storacha/go-ucanto/principal"
"github.com/storacha/go-ucanto/server"
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestPublisherService(t *testing.T) {
publisherStore := store.FromDatastore(dstore)

handlerCalled := false
handler := func(cap ucan.Capability[claim.CacheCaveats], inv invocation.Invocation, ctx server.InvocationContext) (ok.Unit, receipt.Effects, error) {
handler := func(cap ucan.Capability[claim.CacheCaveats], inv invocation.Invocation, ctx server.InvocationContext) (ok.Unit, fx.Effects, error) {
handlerCalled = true
claim := cap.Nb().Claim
for b, err := range inv.Blocks() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/storage/ucan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/storacha/go-capabilities/pkg/blob"
"github.com/storacha/go-ucanto/core/delegation"
"github.com/storacha/go-ucanto/core/invocation"
"github.com/storacha/go-ucanto/core/receipt"
"github.com/storacha/go-ucanto/core/receipt/fx"
"github.com/storacha/go-ucanto/core/result/failure"
"github.com/storacha/go-ucanto/server"
"github.com/storacha/go-ucanto/ucan"
Expand All @@ -31,7 +31,7 @@ func NewUCANServer(storageService Service) (server.ServerView, error) {
blob.AllocateAbility,
server.Provide(
blob.Allocate,
func(cap ucan.Capability[blob.AllocateCaveats], inv invocation.Invocation, iCtx server.InvocationContext) (blob.AllocateOk, receipt.Effects, error) {
func(cap ucan.Capability[blob.AllocateCaveats], inv invocation.Invocation, iCtx server.InvocationContext) (blob.AllocateOk, fx.Effects, error) {
ctx := context.TODO()
digest := cap.Nb().Blob.Digest
log := log.With("blob", digestutil.Format(digest))
Expand Down Expand Up @@ -102,7 +102,7 @@ func NewUCANServer(storageService Service) (server.ServerView, error) {
blob.AcceptAbility,
server.Provide(
blob.Accept,
func(cap ucan.Capability[blob.AcceptCaveats], inv invocation.Invocation, iCtx server.InvocationContext) (blob.AcceptOk, receipt.Effects, error) {
func(cap ucan.Capability[blob.AcceptCaveats], inv invocation.Invocation, iCtx server.InvocationContext) (blob.AcceptOk, fx.Effects, error) {
ctx := context.TODO()
digest := cap.Nb().Blob.Digest
log := log.With("blob", digestutil.Format(digest))
Expand Down Expand Up @@ -156,7 +156,7 @@ func NewUCANServer(storageService Service) (server.ServerView, error) {
return blob.AcceptOk{}, nil, failure.FromError(err)
}

return blob.AcceptOk{Site: claim.Link()}, nil, nil
return blob.AcceptOk{Site: claim.Link()}, fx.NewEffects(fx.WithFork(fx.FromInvocation(claim))), nil
},
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,11 @@ func TestServer(t *testing.T) {
fmt.Println(*f.Stack)
require.Nil(t, f)
})

require.NotEmpty(t, rcpt.Fx().Fork())
effect := rcpt.Fx().Fork()[0]
claim, ok := effect.Invocation()
require.True(t, ok)
require.Equal(t, assert.LocationAbility, claim.Capabilities()[0].Can())
})
}

0 comments on commit 17af5b8

Please sign in to comment.