File tree Expand file tree Collapse file tree 3 files changed +12
-48
lines changed Expand file tree Collapse file tree 3 files changed +12
-48
lines changed Original file line number Diff line number Diff line change @@ -121,24 +121,8 @@ func (l List) String() string {
121
121
122
122
// NewList creates a new List variant.
123
123
func NewList (items ... PlutusData ) PlutusData {
124
- return & List {items }
125
- }
126
-
127
- // IndefList
128
-
129
- type IndefList struct {
130
- Items []PlutusData
131
- }
132
-
133
- func (IndefList ) isPlutusData () {}
134
-
135
- func (l IndefList ) String () string {
136
- return fmt .Sprintf ("IndefList%v" , l .Items )
137
- }
138
-
139
- // NewIndefList creates a new IndefList
140
- func NewIndefList (items ... PlutusData ) PlutusData {
141
- return & IndefList {
142
- Items : items ,
124
+ if items == nil {
125
+ items = make ([]PlutusData , 0 )
143
126
}
127
+ return & List {items }
144
128
}
Original file line number Diff line number Diff line change @@ -24,7 +24,11 @@ var testDefs = []struct {
24
24
NewInteger (big .NewInt (123 )),
25
25
NewInteger (big .NewInt (456 )),
26
26
),
27
- CborHex : "82187b1901c8" ,
27
+ CborHex : "9f187b1901c8ff" ,
28
+ },
29
+ {
30
+ Data : NewList (),
31
+ CborHex : "80" ,
28
32
},
29
33
{
30
34
Data : NewConstr (
@@ -42,19 +46,8 @@ var testDefs = []struct {
42
46
NewInteger (big .NewInt (1 )),
43
47
NewInteger (big .NewInt (2 )),
44
48
),
45
- CborHex : "820102 " ,
49
+ CborHex : "9f0102ff " ,
46
50
},
47
- // TODO: figure out how to not fail this
48
- // It works fine for encode, but we don't have a good way to capture an indef-length list on decode
49
- /*
50
- {
51
- Data: NewIndefList(
52
- NewInteger(big.NewInt(1)),
53
- NewInteger(big.NewInt(2)),
54
- ),
55
- CborHex: "9f0102ff",
56
- },
57
- */
58
51
}
59
52
60
53
func TestPlutusDataEncode (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -32,8 +32,6 @@ func encodeToRaw(pd PlutusData) (any, error) {
32
32
return encodeByteString (v )
33
33
case * List :
34
34
return encodeList (v )
35
- case * IndefList :
36
- return encodeIndefList (v )
37
35
default :
38
36
return nil , fmt .Errorf ("unknown PlutusData type: %T" , pd )
39
37
}
@@ -158,21 +156,10 @@ func encodeByteString(bs *ByteString) (any, error) {
158
156
159
157
// encodeList encodes a List to CBOR array format.
160
158
func encodeList (l * List ) (any , error ) {
161
- result := make ([]any , len (l .Items ))
162
-
163
- for i , item := range l .Items {
164
- encoded , err := encodeToRaw (item )
165
- if err != nil {
166
- return nil , fmt .Errorf ("failed to encode list item %d: %w" , i , err )
167
- }
168
- result [i ] = encoded
159
+ if len (l .Items ) == 0 {
160
+ ret := make ([]any , 0 )
161
+ return ret , nil
169
162
}
170
-
171
- return result , nil
172
- }
173
-
174
- // encodeIndefList encodes an IndefList to CBOR format
175
- func encodeIndefList (l * IndefList ) (any , error ) {
176
163
tmpData := []byte {
177
164
// Start an indefinite-length list
178
165
0x9F ,
You can’t perform that action at this time.
0 commit comments