6 "github.com/bytom/bytom/consensus"
7 "github.com/bytom/bytom/encoding/blockchain"
8 "github.com/bytom/bytom/protocol/bc"
11 // SupLinks is alias of SupLink slice
12 type SupLinks []*SupLink
14 // AddSupLink used to add a supLink by specified validator
15 func (s *SupLinks) AddSupLink(sourceHeight uint64, sourceHash bc.Hash, signature []byte, validatorOrder int) {
16 for _, supLink := range *s {
17 if supLink.SourceHash == sourceHash {
18 supLink.Signatures[validatorOrder] = signature
23 supLink := &SupLink{SourceHeight: sourceHeight, SourceHash: sourceHash}
24 supLink.Signatures[validatorOrder] = signature
25 *s = append(*s, supLink)
28 func (s *SupLinks) readFrom(r *blockchain.Reader) (err error) {
29 size, err := blockchain.ReadVarint31(r)
34 supLinks := make([]*SupLink, size)
35 for i := 0; i < int(size); i++ {
37 if err := supLink.readFrom(r); err != nil {
47 func (s SupLinks) writeTo(w io.Writer) error {
48 if _, err := blockchain.WriteVarint31(w, uint64(len(s))); err != nil {
52 for _, supLink := range s {
53 if err := supLink.writeTo(w); err != nil {
60 // SupLink is an ordered pair of checkpoints (a, b), also written a → b
61 // the validators will sign it once considered as legal
65 Signatures [consensus.MaxNumOfValidators][]byte
68 func (s *SupLink) readFrom(r *blockchain.Reader) (err error) {
69 if s.SourceHeight, err = blockchain.ReadVarint63(r); err != nil {
73 if _, err := s.SourceHash.ReadFrom(r); err != nil {
77 for i := 0; i < consensus.MaxNumOfValidators; i++ {
78 if s.Signatures[i], err = blockchain.ReadVarstr31(r); err != nil {
85 func (s *SupLink) writeTo(w io.Writer) error {
86 if _, err := blockchain.WriteVarint63(w, s.SourceHeight); err != nil {
90 if _, err := s.SourceHash.WriteTo(w); err != nil {
94 for _, signature := range s.Signatures {
95 if _, err := blockchain.WriteVarstr31(w, signature); err != nil {