github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/consensus/neatcon/types/signable.go (about)

     1  package types
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  
     7  	. "github.com/neatlib/common-go"
     8  	"github.com/neatlib/merkle-go"
     9  )
    10  
    11  type Signable interface {
    12  	WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
    13  }
    14  
    15  func SignBytes(chainID string, o Signable) []byte {
    16  	buf, n, err := new(bytes.Buffer), new(int), new(error)
    17  	o.WriteSignBytes(chainID, buf, n, err)
    18  	if *err != nil {
    19  		PanicCrisis(err)
    20  	}
    21  	return buf.Bytes()
    22  }
    23  
    24  func HashSignBytes(chainID string, o Signable) []byte {
    25  	return merkle.SimpleHashFromBinary(SignBytes(chainID, o))
    26  }