File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,22 @@ func (s *ScriptRef) UnmarshalCBOR(data []byte) error {
82
82
return nil
83
83
}
84
84
85
+ func (s * ScriptRef ) MarshalCBOR () ([]byte , error ) {
86
+ tmpData := []any {
87
+ s .Type ,
88
+ s .Script ,
89
+ }
90
+ tmpDataCbor , err := cbor .Encode (tmpData )
91
+ if err != nil {
92
+ return nil , err
93
+ }
94
+ tmpTag := cbor.Tag {
95
+ Number : 24 ,
96
+ Content : tmpDataCbor ,
97
+ }
98
+ return cbor .Encode (tmpTag )
99
+ }
100
+
85
101
type PlutusV1Script []byte
86
102
87
103
func (PlutusV1Script ) isScript () {}
Original file line number Diff line number Diff line change @@ -23,9 +23,10 @@ import (
23
23
"github.com/blinklabs-io/gouroboros/ledger/common"
24
24
)
25
25
26
- func TestScriptRefDecode (t * testing.T ) {
26
+ func TestScriptRefDecodeEncode (t * testing.T ) {
27
27
// 24_0(<<[3, h'480123456789abcdef']>>)
28
- testCbor , _ := hex .DecodeString ("d8184c820349480123456789abcdef" )
28
+ testCborHex := "d8184c820349480123456789abcdef"
29
+ testCbor , _ := hex .DecodeString (testCborHex )
29
30
scriptCbor , _ := hex .DecodeString ("480123456789abcdef" )
30
31
expectedScript := common .PlutusV3Script (scriptCbor )
31
32
var testScriptRef common.ScriptRef
@@ -39,6 +40,13 @@ func TestScriptRefDecode(t *testing.T) {
39
40
& expectedScript ,
40
41
)
41
42
}
43
+ scriptRefCbor , err := cbor .Encode (testScriptRef )
44
+ if err != nil {
45
+ t .Fatalf ("unexpected error: %s" , err )
46
+ }
47
+ if hex .EncodeToString (scriptRefCbor ) != testCborHex {
48
+ t .Fatalf ("did not get expected CBOR\n got: %x\n wanted: %s" , scriptRefCbor , testCborHex )
49
+ }
42
50
}
43
51
44
52
func TestNativeScriptHash (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments