func (kv KVPair) Hash() []byte { hasher, n, err := ripemd160.New(), new(int64), new(error) wire.WriteString(kv.Key, hasher, n, err) if kvH, ok := kv.Value.(Hashable); ok { wire.WriteByteSlice(kvH.Hash(), hasher, n, err) } else { wire.WriteBinary(kv.Value, hasher, n, err) } if *err != nil { PanicSanity(*err) } return hasher.Sum(nil) }
func (s *State) Save() { s.accounts.Save() s.validatorInfos.Save() s.nameReg.Save() buf, n, err := new(bytes.Buffer), new(int64), new(error) wire.WriteString(s.ChainID, buf, n, err) wire.WriteVarint(s.LastBlockHeight, buf, n, err) wire.WriteByteSlice(s.LastBlockHash, buf, n, err) wire.WriteBinary(s.LastBlockParts, buf, n, err) wire.WriteTime(s.LastBlockTime, buf, n, err) wire.WriteBinary(s.BondedValidators, buf, n, err) wire.WriteBinary(s.LastBondedValidators, buf, n, err) wire.WriteBinary(s.UnbondingValidators, buf, n, err) wire.WriteByteSlice(s.accounts.Hash(), buf, n, err) wire.WriteByteSlice(s.validatorInfos.Hash(), buf, n, err) wire.WriteByteSlice(s.nameReg.Hash(), buf, n, err) if *err != nil { PanicCrisis(*err) } s.DB.Set(stateKey, buf.Bytes()) }
func (p *Peer) WriteTo(w io.Writer) (n int64, err error) { wire.WriteString(p.Key, w, &n, &err) return }