From 04bc8eff2e5a00fdf52a197a2be0a856c099baf8 Mon Sep 17 00:00:00 2001 From: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:01:20 +0530 Subject: [PATCH] fix: offline deal handling (#363) * fix offline deal handling * apply suggestion * use default headers instead of null --- market/mk12/mk12.go | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/market/mk12/mk12.go b/market/mk12/mk12.go index cd6355c99..fbcac56bd 100644 --- a/market/mk12/mk12.go +++ b/market/mk12/mk12.go @@ -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