@@ -48,18 +48,16 @@ func (c Constr) String() string {
4848
4949// NewConstr creates a new Constr variant.
5050func NewConstr (tag uint , fields ... PlutusData ) PlutusData {
51- if fields == nil {
52- fields = make ([]PlutusData , 0 )
53- }
54- return & Constr {Tag : tag , Fields : fields }
51+ tmpFields := make ([]PlutusData , len (fields ))
52+ copy (tmpFields , fields )
53+ return & Constr {Tag : tag , Fields : tmpFields }
5554}
5655
5756// NewConstrDefIndef creates a Constr with the ability to specify whether it should use definite- or indefinite-length encoding
5857func NewConstrDefIndef (useIndef bool , tag uint , fields ... PlutusData ) PlutusData {
59- if fields == nil {
60- fields = make ([]PlutusData , 0 )
61- }
62- return & Constr {Tag : tag , Fields : fields , useIndef : & useIndef }
58+ tmpFields := make ([]PlutusData , len (fields ))
59+ copy (tmpFields , fields )
60+ return & Constr {Tag : tag , Fields : tmpFields , useIndef : & useIndef }
6361}
6462
6563// Map
@@ -77,12 +75,16 @@ func (m Map) String() string {
7775
7876// NewMap creates a new Map variant.
7977func NewMap (pairs [][2 ]PlutusData ) PlutusData {
80- return & Map {Pairs : pairs }
78+ tmpPairs := make ([][2 ]PlutusData , len (pairs ))
79+ copy (tmpPairs , pairs )
80+ return & Map {Pairs : tmpPairs }
8181}
8282
8383// NewMapDefIndef creates a new Map with the ability to specify whether it should use definite- or indefinite-length encoding
8484func NewMapDefIndef (useIndef bool , pairs [][2 ]PlutusData ) PlutusData {
85- return & Map {Pairs : pairs , useIndef : & useIndef }
85+ tmpPairs := make ([][2 ]PlutusData , len (pairs ))
86+ copy (tmpPairs , pairs )
87+ return & Map {Pairs : tmpPairs , useIndef : & useIndef }
8688}
8789
8890// Integer
@@ -99,7 +101,8 @@ func (i Integer) String() string {
99101
100102// NewInteger creates a new Integer variant.
101103func NewInteger (value * big.Int ) PlutusData {
102- return & Integer {value }
104+ tmpVal := new (big.Int ).Set (value )
105+ return & Integer {tmpVal }
103106}
104107
105108// ByteString
@@ -136,16 +139,14 @@ func (l List) String() string {
136139
137140// NewList creates a new List variant.
138141func NewList (items ... PlutusData ) PlutusData {
139- if items == nil {
140- items = make ([]PlutusData , 0 )
141- }
142- return & List {Items : items }
142+ tmpItems := make ([]PlutusData , len (items ))
143+ copy (tmpItems , items )
144+ return & List {Items : tmpItems }
143145}
144146
145147// NewListDefIndef creates a list with the ability to specify whether it should use definite- or indefinite-length encoding
146148func NewListDefIndef (useIndef bool , items ... PlutusData ) PlutusData {
147- if items == nil {
148- items = make ([]PlutusData , 0 )
149- }
150- return & List {Items : items , useIndef : & useIndef }
149+ tmpItems := make ([]PlutusData , len (items ))
150+ copy (tmpItems , items )
151+ return & List {Items : tmpItems , useIndef : & useIndef }
151152}
0 commit comments