tendermint/types/signable.go

25 lines
584 B
Go
Raw Normal View History

2015-11-01 11:34:08 -08:00
package types
import (
"bytes"
"io"
2017-10-04 13:40:45 -07:00
cmn "github.com/tendermint/tmlibs/common"
2015-11-01 11:34:08 -08:00
)
// Signable is an interface for all signable things.
// It typically removes signatures before serializing.
type Signable interface {
2015-11-10 13:10:43 -08:00
WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
2015-11-01 11:34:08 -08:00
}
// SignBytes is a convenience method for getting the bytes to sign of a Signable.
func SignBytes(chainID string, o Signable) []byte {
2015-11-10 13:10:43 -08:00
buf, n, err := new(bytes.Buffer), new(int), new(error)
2015-11-01 11:34:08 -08:00
o.WriteSignBytes(chainID, buf, n, err)
if *err != nil {
2017-10-04 13:40:45 -07:00
cmn.PanicCrisis(err)
2015-11-01 11:34:08 -08:00
}
return buf.Bytes()
}