@@ -28,7 +28,7 @@ func (p *PlutusDataWrapper) MarshalCBOR() ([]byte, error) {
28
28
29
29
type PlutusData interface {
30
30
isPlutusData ()
31
-
31
+ Clone () PlutusData
32
32
fmt.Stringer
33
33
}
34
34
@@ -42,6 +42,19 @@ type Constr struct {
42
42
43
43
func (Constr ) isPlutusData () {}
44
44
45
+ func (c Constr ) Clone () PlutusData {
46
+ tmpFields := make ([]PlutusData , len (c .Fields ))
47
+ for i , field := range c .Fields {
48
+ tmpFields [i ] = field .Clone ()
49
+ }
50
+ var tmpIndef * bool
51
+ if c .useIndef != nil {
52
+ tmpIndef = new (bool )
53
+ * tmpIndef = * c .useIndef
54
+ }
55
+ return & Constr {Tag : c .Tag , Fields : tmpFields , useIndef : tmpIndef }
56
+ }
57
+
45
58
func (c Constr ) String () string {
46
59
return fmt .Sprintf ("Constr{tag: %d, fields: %v}" , c .Tag , c .Fields )
47
60
}
@@ -69,6 +82,22 @@ type Map struct {
69
82
70
83
func (Map ) isPlutusData () {}
71
84
85
+ func (m Map ) Clone () PlutusData {
86
+ tmpPairs := make ([][2 ]PlutusData , len (m .Pairs ))
87
+ for i , pair := range m .Pairs {
88
+ tmpPairs [i ] = [2 ]PlutusData {
89
+ pair [0 ].Clone (),
90
+ pair [1 ].Clone (),
91
+ }
92
+ }
93
+ var tmpIndef * bool
94
+ if m .useIndef != nil {
95
+ tmpIndef = new (bool )
96
+ * tmpIndef = * m .useIndef
97
+ }
98
+ return & Map {Pairs : tmpPairs , useIndef : tmpIndef }
99
+ }
100
+
72
101
func (m Map ) String () string {
73
102
return fmt .Sprintf ("Map%v" , m .Pairs )
74
103
}
@@ -95,6 +124,11 @@ type Integer struct {
95
124
96
125
func (Integer ) isPlutusData () {}
97
126
127
+ func (i Integer ) Clone () PlutusData {
128
+ tmpVal := new (big.Int ).Set (i .Inner )
129
+ return & Integer {tmpVal }
130
+ }
131
+
98
132
func (i Integer ) String () string {
99
133
return fmt .Sprintf ("Integer(%s)" , i .Inner .String ())
100
134
}
@@ -113,6 +147,12 @@ type ByteString struct {
113
147
114
148
func (ByteString ) isPlutusData () {}
115
149
150
+ func (b ByteString ) Clone () PlutusData {
151
+ tmpVal := make ([]byte , len (b .Inner ))
152
+ copy (tmpVal , b .Inner )
153
+ return & ByteString {tmpVal }
154
+ }
155
+
116
156
func (b ByteString ) String () string {
117
157
return fmt .Sprintf ("ByteString(%x)" , b .Inner )
118
158
}
@@ -133,6 +173,19 @@ type List struct {
133
173
134
174
func (List ) isPlutusData () {}
135
175
176
+ func (l List ) Clone () PlutusData {
177
+ tmpItems := make ([]PlutusData , len (l .Items ))
178
+ for i , item := range l .Items {
179
+ tmpItems [i ] = item .Clone ()
180
+ }
181
+ var tmpIndef * bool
182
+ if l .useIndef != nil {
183
+ tmpIndef = new (bool )
184
+ * tmpIndef = * l .useIndef
185
+ }
186
+ return & List {Items : tmpItems , useIndef : tmpIndef }
187
+ }
188
+
136
189
func (l List ) String () string {
137
190
return fmt .Sprintf ("List%v" , l .Items )
138
191
}
0 commit comments