cosmos-sdk/state/state.go

27 lines
641 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
}
// 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
store.Set([]byte("base/chain_id"), []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
}
s.chainID = string(store.Get([]byte("base/chain_id")))
2016-03-22 10:13:34 -07:00
return s.chainID
}