1+ // The common package contains types used by multiple mini-protocols
12package common
23
34import (
45 "github.com/cloudstruct/go-ouroboros-network/utils"
56 "github.com/fxamacker/cbor/v2"
67)
78
9+ // The Point type represents a point on the blockchain. It consists of a slot number and block hash
810type Point struct {
911 // Tells the CBOR decoder to convert to/from a struct and a CBOR array
1012 _ struct {} `cbor:",toarray"`
1113 Slot uint64
1214 Hash []byte
1315}
1416
17+ // NewPoint returns a Point object with the specified slot number and block hash
1518func NewPoint (slot uint64 , blockHash []byte ) Point {
1619 return Point {
1720 Slot : slot ,
1821 Hash : blockHash ,
1922 }
2023}
2124
25+ // NewPointOrigin returns an "empty" Point object which represents the origin of the blockchain
2226func NewPointOrigin () Point {
2327 return Point {}
2428}
2529
26- // A "point" can sometimes be empty, but the CBOR library gets grumpy about this
27- // when doing automatic decoding from an array, so we have to handle this case specially
30+ // UnmarshalCBOR is a helper function for decoding a Point object from CBOR. The object content can vary,
31+ // so we need to do some special handling when decoding. It is not intended to be called directly.
2832func (p * Point ) UnmarshalCBOR (data []byte ) error {
2933 var tmp []interface {}
3034 if err := cbor .Unmarshal (data , & tmp ); err != nil {
@@ -37,6 +41,8 @@ func (p *Point) UnmarshalCBOR(data []byte) error {
3741 return nil
3842}
3943
44+ // MarshalCBOR is a helper function for encoding a Point object to CBOR. The object content can vary, so we
45+ // need to do some special handling when encoding. It is not intended to be called directly.
4046func (p * Point ) MarshalCBOR () ([]byte , error ) {
4147 var data []interface {}
4248 if p .Slot == 0 && p .Hash == nil {
0 commit comments