From b5291fb22a464a4c046d5e4ff45788ab9672d3e4 Mon Sep 17 00:00:00 2001 From: MIxAxIM Date: Sun, 10 Dec 2023 21:32:37 +0330 Subject: [PATCH] HexString PlutusType has been added --- plutusencoder/plutus.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plutusencoder/plutus.go b/plutusencoder/plutus.go index 66e8c9b..bf48c15 100644 --- a/plutusencoder/plutus.go +++ b/plutusencoder/plutus.go @@ -346,6 +346,29 @@ func MarshalPlutus(v interface{}) (*PlutusData.PlutusData, error) { overallContainer = append(overallContainer.(PlutusData.PlutusDefArray), pdsb) } } + case "HexString": + if values.Field(i).Kind() != reflect.String { + return nil, fmt.Errorf("error: HexString field is not string") + } + hexString, err := hex.DecodeString(values.Field(i).Interface().(string)) + if err != nil { + return nil, fmt.Errorf("error: HexString field is not hex") + } + pdsb := PlutusData.PlutusData{ + PlutusDataType: PlutusData.PlutusBytes, + Value: hexString, + TagNr: constr, + } + if isMap { + nameBytes := serialization.CustomBytes{Value: name} + overallContainer.(map[serialization.CustomBytes]PlutusData.PlutusData)[nameBytes] = pdsb + } else { + if isIndef { + overallContainer = append(overallContainer.(PlutusData.PlutusIndefArray), pdsb) + } else { + overallContainer = append(overallContainer.(PlutusData.PlutusDefArray), pdsb) + } + } case "Address": addpd, err := GetAddressPlutusData(values.Field(i).Interface().(Address.Address)) if err != nil {