mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-30 19:51:58 +00:00
postmerge
This commit is contained in:
30
types/signable.go
Normal file
30
types/signable.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-merkle"
|
||||
)
|
||||
|
||||
// Signable is an interface for all signable things.
|
||||
// It typically removes signatures before serializing.
|
||||
type Signable interface {
|
||||
WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
|
||||
}
|
||||
|
||||
// SignBytes is a convenience method for getting the bytes to sign of a Signable.
|
||||
func SignBytes(chainID string, o Signable) []byte {
|
||||
buf, n, err := new(bytes.Buffer), new(int), new(error)
|
||||
o.WriteSignBytes(chainID, buf, n, err)
|
||||
if *err != nil {
|
||||
PanicCrisis(err)
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// HashSignBytes is a convenience method for getting the hash of the bytes of a signable
|
||||
func HashSignBytes(chainID string, o Signable) []byte {
|
||||
return merkle.SimpleHashFromBinary(SignBytes(chainID, o))
|
||||
}
|
Reference in New Issue
Block a user