cosmos-sdk/state/chainstate.go

29 lines
669 B
Go
Raw Normal View History

2016-03-20 03:00:43 -07:00
package state
// ChainState maintains general information for the chain
type ChainState struct {
chainID string
2016-03-20 03:00:43 -07:00
}
// NewChainState creates a blank state
func NewChainState() *ChainState {
return &ChainState{}
2016-03-20 03:00:43 -07:00
}
2017-07-27 08:17:22 -07:00
var baseChainIDKey = []byte("base/chain_id")
// SetChainID stores the chain id in the store
func (s *ChainState) SetChainID(store KVStore, chainID string) {
2016-03-22 13:07:03 -07:00
s.chainID = chainID
2017-07-27 08:17:22 -07:00
store.Set(baseChainIDKey, []byte(chainID))
2016-03-22 13:07:03 -07:00
}
// GetChainID gets the chain id from the cache or the store
func (s *ChainState) GetChainID(store KVStore) string {
2017-03-14 14:28:49 -07:00
if s.chainID != "" {
return s.chainID
2016-03-22 13:07:03 -07:00
}
2017-07-27 08:17:22 -07:00
s.chainID = string(store.Get(baseChainIDKey))
2016-03-22 10:13:34 -07:00
return s.chainID
}