Skip to content

Commit

Permalink
fix: offline deal handling (#363)
Browse files Browse the repository at this point in the history
* fix offline deal handling

* apply suggestion

* use default headers instead of null
  • Loading branch information
LexLuthr authored Jan 13, 2025
1 parent 1418afb commit 04bc8ef
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions market/mk12/mk12.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,24 +424,30 @@ func (m *MK12) processDeal(ctx context.Context, deal *ProviderDealState) (*Provi
}, nil
}

// de-serialize transport opaque token
var headers []byte
tInfo := &HttpRequest{}
if err := json.Unmarshal(deal.Transfer.Params, tInfo); err != nil {
return &ProviderDealRejectionInfo{
Reason: fmt.Sprintf("failed to de-serialize transport params bytes '%s': %s", string(deal.Transfer.Params), err),
}, nil
}

goheaders := http.Header{}
for k, v := range tInfo.Headers {
goheaders.Set(k, v)
}
if !deal.IsOffline {
// de-serialize transport opaque token
if err := json.Unmarshal(deal.Transfer.Params, tInfo); err != nil {
return &ProviderDealRejectionInfo{
Reason: fmt.Sprintf("failed to de-serialize transport params bytes '%s': %s", string(deal.Transfer.Params), err),
}, nil
}

headers, err := json.Marshal(goheaders)
if err != nil {
return &ProviderDealRejectionInfo{
Reason: fmt.Sprintf("failed to marshal headers: %s", err),
}, nil
goheaders := http.Header{}
for k, v := range tInfo.Headers {
goheaders.Set(k, v)
}

headers, err = json.Marshal(goheaders)
if err != nil {
return &ProviderDealRejectionInfo{
Reason: fmt.Sprintf("failed to marshal headers: %s", err),
}, nil
}
} else {
headers = []byte("{}")
}

// Cbor marshal the Deal Label manually as non-string label will result in "" with JSON marshal
Expand Down

0 comments on commit 04bc8ef

Please sign in to comment.