github.com/cranelv/ethereum_mpc@v0.0.0-20191031014521-23aeb1415092/consensus_pbft/singletons/singletons.go (about) 1 package singletons 2 3 import ( 4 "github.com/ethereum/go-ethereum/rlp" 5 "github.com/ethereum/go-ethereum/consensus_pbft/pbftTypes" 6 "github.com/ethereum/go-ethereum/crypto/sha3" 7 "github.com/ethereum/go-ethereum/common" 8 ) 9 10 var ( 11 Log Logger = &PbftLogger{} 12 Marshaler MarshalInterface = &rlpMarshal{} 13 Hasher HashInterface = &rlpHasher{} 14 ) 15 type rlpMarshal struct { 16 17 } 18 func (rm *rlpMarshal)Marshal(data interface{}) ([]byte, error){ 19 return rlp.EncodeToBytes(data) 20 } 21 func (rm *rlpMarshal)Unmarshal(buf []byte, data interface{}) error{ 22 return rlp.DecodeBytes(buf,data) 23 } 24 25 type rlpHasher struct { 26 } 27 28 func (rh *rlpHasher)Hash(data interface{}) pbftTypes.MessageDigest { 29 h := common.Hash{} 30 hw := sha3.NewKeccak256() 31 rlp.Encode(hw, data) 32 hw.Sum(h[:0]) 33 return pbftTypes.MessageDigest(h[:]) 34 }