66 "errors"
77 "fmt"
88 "hash"
9+ "io"
910 "net/http"
1011 "net/url"
1112
@@ -16,10 +17,10 @@ import (
1617 "github.com/storacha/go-ucanto/core/ipld"
1718 "github.com/storacha/go-ucanto/core/ipld/block"
1819 "github.com/storacha/go-ucanto/core/ipld/codec/cbor"
20+ "github.com/storacha/go-ucanto/core/ipld/codec/json"
1921 ucansha256 "github.com/storacha/go-ucanto/core/ipld/hash/sha256"
2022 "github.com/storacha/go-ucanto/core/message"
2123 mdm "github.com/storacha/go-ucanto/core/message/datamodel"
22- "github.com/storacha/go-ucanto/core/result"
2324 rdm "github.com/storacha/go-ucanto/server/retrieval/datamodel"
2425 "github.com/storacha/go-ucanto/transport"
2526 "github.com/storacha/go-ucanto/transport/headercar"
@@ -155,20 +156,23 @@ func Execute(ctx context.Context, inv invocation.Invocation, conn client.Connect
155156 return nil , nil , fmt .Errorf ("unexpected status code: %d" , res .Status ())
156157 }
157158
158- // find the next part
159- output , err := conn .Codec ().Decode (response )
159+ body , err := io .ReadAll (response .Body ())
160160 if err != nil {
161- return nil , nil , fmt .Errorf ("decoding message : %w" , err )
161+ return nil , nil , fmt .Errorf ("reading not extended body : %w" , err )
162162 }
163163
164- missprfs , err := extractMissingProofs (inv .Link (), output )
164+ var model rdm.MissingProofsModel
165+ err = json .Decode (body , & model , rdm .MissingProofsType ())
165166 if err != nil {
166- return nil , nil , fmt .Errorf ("extracting missing proofs: %w" , err )
167+ return nil , nil , fmt .Errorf ("decoding body: %w" , err )
168+ }
169+ if len (model .Proofs ) == 0 {
170+ return nil , nil , fmt .Errorf ("missing missing proofs: %w" , err )
167171 }
168172
169- p , ok := parts [missprfs [0 ].String ()]
173+ p , ok := parts [model . Proofs [0 ].String ()]
170174 if ! ok {
171- return nil , nil , fmt .Errorf ("missing proof not found or was already sent: %s" , missprfs [0 ].String ())
175+ return nil , nil , fmt .Errorf ("missing proof not found or was already sent: %s" , model . Proofs [0 ].String ())
172176 }
173177 part = p
174178 delete (parts , p .Link ().String ())
@@ -217,26 +221,3 @@ func newPartialInvocationMessage(invocation ipld.Link, part delegation.Delegatio
217221 }
218222 return message .NewMessage (rt .Link (), bs )
219223}
220-
221- func extractMissingProofs (invocation ipld.Link , msg message.AgentMessage ) ([]ipld.Link , error ) {
222- root , ok := msg .Get (invocation )
223- if ! ok {
224- return nil , fmt .Errorf ("missing receipt for invocation: %s" , invocation .String ())
225- }
226- rcpt , ok , err := msg .Receipt (root )
227- if err != nil {
228- return nil , fmt .Errorf ("getting receipt %s: %w" , root .String (), err )
229- }
230- if ! ok {
231- return nil , fmt .Errorf ("missing receipt for invocation: %s" , invocation .String ())
232- }
233- _ , x := result .Unwrap (rcpt .Out ())
234- if x == nil {
235- return nil , errors .New ("missing error in receipt" )
236- }
237- model , err := ipld .Rebind [rdm.MissingProofsModel ](x , rdm .MissingProofsType ())
238- if err != nil {
239- return nil , fmt .Errorf ("binding missing proofs error: %w" , err )
240- }
241- return model .Proofs , nil
242- }
0 commit comments