11package data
22
33import (
4+ "bytes"
45 "fmt"
56 "math/big"
67)
@@ -29,6 +30,7 @@ func (p *PlutusDataWrapper) MarshalCBOR() ([]byte, error) {
2930type PlutusData interface {
3031 isPlutusData ()
3132 Clone () PlutusData
33+ Equal (PlutusData ) bool
3234 fmt.Stringer
3335}
3436
@@ -55,6 +57,25 @@ func (c Constr) Clone() PlutusData {
5557 return & Constr {Tag : c .Tag , Fields : tmpFields , useIndef : tmpIndef }
5658}
5759
60+ func (c Constr ) Equal (pd PlutusData ) bool {
61+ pdConstr , ok := pd .(* Constr )
62+ if ! ok {
63+ return false
64+ }
65+ if c .Tag != pdConstr .Tag {
66+ return false
67+ }
68+ if len (c .Fields ) != len (pdConstr .Fields ) {
69+ return false
70+ }
71+ for i := range c .Fields {
72+ if ! c .Fields [i ].Equal (pdConstr .Fields [i ]) {
73+ return false
74+ }
75+ }
76+ return true
77+ }
78+
5879func (c Constr ) String () string {
5980 return fmt .Sprintf ("Constr{tag: %d, fields: %v}" , c .Tag , c .Fields )
6081}
@@ -98,6 +119,22 @@ func (m Map) Clone() PlutusData {
98119 return & Map {Pairs : tmpPairs , useIndef : tmpIndef }
99120}
100121
122+ func (m Map ) Equal (pd PlutusData ) bool {
123+ pdMap , ok := pd .(* Map )
124+ if ! ok {
125+ return false
126+ }
127+ for i , pair := range pdMap .Pairs {
128+ if ! pair [0 ].Equal (pdMap .Pairs [i ][0 ]) {
129+ return false
130+ }
131+ if ! pair [1 ].Equal (pdMap .Pairs [i ][1 ]) {
132+ return false
133+ }
134+ }
135+ return true
136+ }
137+
101138func (m Map ) String () string {
102139 return fmt .Sprintf ("Map%v" , m .Pairs )
103140}
@@ -129,6 +166,17 @@ func (i Integer) Clone() PlutusData {
129166 return & Integer {tmpVal }
130167}
131168
169+ func (i Integer ) Equal (pd PlutusData ) bool {
170+ pdInt , ok := pd .(* Integer )
171+ if ! ok {
172+ return false
173+ }
174+ if i .Inner .Cmp (pdInt .Inner ) != 0 {
175+ return false
176+ }
177+ return true
178+ }
179+
132180func (i Integer ) String () string {
133181 return fmt .Sprintf ("Integer(%s)" , i .Inner .String ())
134182}
@@ -153,6 +201,17 @@ func (b ByteString) Clone() PlutusData {
153201 return & ByteString {tmpVal }
154202}
155203
204+ func (b ByteString ) Equal (pd PlutusData ) bool {
205+ pdByteString , ok := pd .(* ByteString )
206+ if ! ok {
207+ return false
208+ }
209+ if ! bytes .Equal (b .Inner , pdByteString .Inner ) {
210+ return false
211+ }
212+ return true
213+ }
214+
156215func (b ByteString ) String () string {
157216 return fmt .Sprintf ("ByteString(%x)" , b .Inner )
158217}
@@ -186,6 +245,22 @@ func (l List) Clone() PlutusData {
186245 return & List {Items : tmpItems , useIndef : tmpIndef }
187246}
188247
248+ func (l List ) Equal (pd PlutusData ) bool {
249+ pdList , ok := pd .(* List )
250+ if ! ok {
251+ return false
252+ }
253+ if len (l .Items ) != len (pdList .Items ) {
254+ return false
255+ }
256+ for i := range l .Items {
257+ if ! l .Items [i ].Equal (pdList .Items [i ]) {
258+ return false
259+ }
260+ }
261+ return true
262+ }
263+
189264func (l List ) String () string {
190265 return fmt .Sprintf ("List%v" , l .Items )
191266}
0 commit comments