cosmos-sdk/x/gov/types/keys.go

165 lines
5.1 KiB
Go
Raw Normal View History

Merge PR #4206: Param Change Proposal * Add params error types * Update param module keeper to take a codespace * Update imports * Implement SetRaw and SetRawWithSubkey * Implement ParamChange and update aliases * Add types codec * Implement ParameterChangeProposal * Implement TestParameterChangeProposal * Fix linting errors * Update tags * Implement content * Updata params aliases * Finish params handler and proposal types * Move deposit and vote logic to types package * Move proposal type to types package * Move errors to types package * Update proposal * Move gov messages to types package * Minor updates to naming * Move keys to types package * Move codec to types package * Move proposal types to types package * Update aliases * Add governance alias types * Implement governance router * Update gov aliases * Update gov keeper * Update private functions needed for the keeper * Update godocs * Update the gov message handler * Update Gaia app * Make updates to auth * Update the message codec in the keeper * Update gov end blocker * Update types tests * Minor tweaks * Add legacy genesis logic * Update gov aliases * Move gov keys to types package * Revertt to using gov/types in params * Implement params handler test * Update governance tests * Fix endblocker tests * Fix governance querier tests * Add seal support to gov router * Update simulationCreateMsgSubmitProposal * Disable software upgrade proposals * Move params keys to types package * Implement param module proposal client logic * Update gov client logic * Update gaia app client hooks * Fix linting errors * Fix ValidateBasic * Remove legacy files * Update paramchange to use strings * Update paramchange cli cmd * Update ValidateBasic and errors * Use PostCommands when adding child cmds * Fix codec logic * Update params client and handler * Update IsValidProposalType * Update SubmitProposal to test exec * Implement TestGaiaCLISubmitParamChangeProposal * Implement TestSubmitParamChangeProposal * Update swagger.yaml * Update gaiacli.md * Update gov spec docs * Fix linting errors * Fix unit tests * Add pending log entries * Update docs * Update docs * Update client/lcd/swagger-ui/swagger.yaml Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update cmd/gaia/cli_test/test_helpers.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update client/lcd/test_helpers.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update x/gov/types/proposal.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Address PR comments * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update gov docs to include quorum notes * Add logs to handleParameterChangeProposal * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Support and use new StatusFailed when proposal passes but fails exec * Add docs/notes warning on param validity * Update docs * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Minor doc update * Update x/gov/client/cli/tx.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Fix usage of fromAddr * Rige code style suggestion * Update x/params/types/proposal.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Fix CI lint errors * Update NewModuleClient godoc * Add godoc to rtr.Seal() call * Rename files * Rename NewProposalHandler
2019-04-30 09:31:38 -07:00
package types
2018-06-21 17:19:14 -07:00
import (
"encoding/binary"
2018-06-21 17:19:14 -07:00
"fmt"
"time"
2018-06-21 17:19:14 -07:00
sdk "github.com/cosmos/cosmos-sdk/types"
)
Merge PR #4206: Param Change Proposal * Add params error types * Update param module keeper to take a codespace * Update imports * Implement SetRaw and SetRawWithSubkey * Implement ParamChange and update aliases * Add types codec * Implement ParameterChangeProposal * Implement TestParameterChangeProposal * Fix linting errors * Update tags * Implement content * Updata params aliases * Finish params handler and proposal types * Move deposit and vote logic to types package * Move proposal type to types package * Move errors to types package * Update proposal * Move gov messages to types package * Minor updates to naming * Move keys to types package * Move codec to types package * Move proposal types to types package * Update aliases * Add governance alias types * Implement governance router * Update gov aliases * Update gov keeper * Update private functions needed for the keeper * Update godocs * Update the gov message handler * Update Gaia app * Make updates to auth * Update the message codec in the keeper * Update gov end blocker * Update types tests * Minor tweaks * Add legacy genesis logic * Update gov aliases * Move gov keys to types package * Revertt to using gov/types in params * Implement params handler test * Update governance tests * Fix endblocker tests * Fix governance querier tests * Add seal support to gov router * Update simulationCreateMsgSubmitProposal * Disable software upgrade proposals * Move params keys to types package * Implement param module proposal client logic * Update gov client logic * Update gaia app client hooks * Fix linting errors * Fix ValidateBasic * Remove legacy files * Update paramchange to use strings * Update paramchange cli cmd * Update ValidateBasic and errors * Use PostCommands when adding child cmds * Fix codec logic * Update params client and handler * Update IsValidProposalType * Update SubmitProposal to test exec * Implement TestGaiaCLISubmitParamChangeProposal * Implement TestSubmitParamChangeProposal * Update swagger.yaml * Update gaiacli.md * Update gov spec docs * Fix linting errors * Fix unit tests * Add pending log entries * Update docs * Update docs * Update client/lcd/swagger-ui/swagger.yaml Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update cmd/gaia/cli_test/test_helpers.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update client/lcd/test_helpers.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update x/gov/types/proposal.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Address PR comments * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update gov docs to include quorum notes * Add logs to handleParameterChangeProposal * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Support and use new StatusFailed when proposal passes but fails exec * Add docs/notes warning on param validity * Update docs * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Minor doc update * Update x/gov/client/cli/tx.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Fix usage of fromAddr * Rige code style suggestion * Update x/params/types/proposal.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Fix CI lint errors * Update NewModuleClient godoc * Add godoc to rtr.Seal() call * Rename files * Rename NewProposalHandler
2019-04-30 09:31:38 -07:00
const (
// ModuleName is the name of the module
Merge PR #4206: Param Change Proposal * Add params error types * Update param module keeper to take a codespace * Update imports * Implement SetRaw and SetRawWithSubkey * Implement ParamChange and update aliases * Add types codec * Implement ParameterChangeProposal * Implement TestParameterChangeProposal * Fix linting errors * Update tags * Implement content * Updata params aliases * Finish params handler and proposal types * Move deposit and vote logic to types package * Move proposal type to types package * Move errors to types package * Update proposal * Move gov messages to types package * Minor updates to naming * Move keys to types package * Move codec to types package * Move proposal types to types package * Update aliases * Add governance alias types * Implement governance router * Update gov aliases * Update gov keeper * Update private functions needed for the keeper * Update godocs * Update the gov message handler * Update Gaia app * Make updates to auth * Update the message codec in the keeper * Update gov end blocker * Update types tests * Minor tweaks * Add legacy genesis logic * Update gov aliases * Move gov keys to types package * Revertt to using gov/types in params * Implement params handler test * Update governance tests * Fix endblocker tests * Fix governance querier tests * Add seal support to gov router * Update simulationCreateMsgSubmitProposal * Disable software upgrade proposals * Move params keys to types package * Implement param module proposal client logic * Update gov client logic * Update gaia app client hooks * Fix linting errors * Fix ValidateBasic * Remove legacy files * Update paramchange to use strings * Update paramchange cli cmd * Update ValidateBasic and errors * Use PostCommands when adding child cmds * Fix codec logic * Update params client and handler * Update IsValidProposalType * Update SubmitProposal to test exec * Implement TestGaiaCLISubmitParamChangeProposal * Implement TestSubmitParamChangeProposal * Update swagger.yaml * Update gaiacli.md * Update gov spec docs * Fix linting errors * Fix unit tests * Add pending log entries * Update docs * Update docs * Update client/lcd/swagger-ui/swagger.yaml Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update cmd/gaia/cli_test/test_helpers.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update client/lcd/test_helpers.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update x/gov/types/proposal.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Address PR comments * Update docs/cosmos-hub/gaiacli.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update gov docs to include quorum notes * Add logs to handleParameterChangeProposal * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Support and use new StatusFailed when proposal passes but fails exec * Add docs/notes warning on param validity * Update docs * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Update docs/spec/governance/02_state.md Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Minor doc update * Update x/gov/client/cli/tx.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Fix usage of fromAddr * Rige code style suggestion * Update x/params/types/proposal.go Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com> * Fix CI lint errors * Update NewModuleClient godoc * Add godoc to rtr.Seal() call * Rename files * Rename NewProposalHandler
2019-04-30 09:31:38 -07:00
ModuleName = "gov"
// StoreKey is the store key string for gov
StoreKey = ModuleName
// RouterKey is the message route for gov
RouterKey = ModuleName
// QuerierRoute is the querier route for gov
QuerierRoute = ModuleName
)
// Keys for governance store
// Items are stored with the following key: values
//
// - 0x00<proposalID_Bytes>: Proposal
//
// - 0x01<endTime_Bytes><proposalID_Bytes>: activeProposalID
//
// - 0x02<endTime_Bytes><proposalID_Bytes>: inactiveProposalID
//
// - 0x03: nextProposalID
//
// - 0x10<proposalID_Bytes><depositorAddr_Bytes>: Deposit
//
// - 0x20<proposalID_Bytes><voterAddr_Bytes>: Voter
2018-06-21 17:19:14 -07:00
var (
ProposalsKeyPrefix = []byte{0x00}
ActiveProposalQueuePrefix = []byte{0x01}
InactiveProposalQueuePrefix = []byte{0x02}
ProposalIDKey = []byte{0x03}
DepositsKeyPrefix = []byte{0x10}
VotesKeyPrefix = []byte{0x20}
2018-06-21 17:19:14 -07:00
)
var lenTime = len(sdk.FormatTimeBytes(time.Now()))
// GetProposalIDBytes returns the byte representation of the proposalID
func GetProposalIDBytes(proposalID uint64) (proposalIDBz []byte) {
proposalIDBz = make([]byte, 8)
binary.BigEndian.PutUint64(proposalIDBz, proposalID)
return
}
// GetProposalIDFromBytes returns proposalID in uint64 format from a byte array
func GetProposalIDFromBytes(bz []byte) (proposalID uint64) {
return binary.BigEndian.Uint64(bz)
}
// ProposalKey gets a specific proposal from the store
func ProposalKey(proposalID uint64) []byte {
return append(ProposalsKeyPrefix, GetProposalIDBytes(proposalID)...)
}
// ActiveProposalByTimeKey gets the active proposal queue key by endTime
func ActiveProposalByTimeKey(endTime time.Time) []byte {
return append(ActiveProposalQueuePrefix, sdk.FormatTimeBytes(endTime)...)
}
// ActiveProposalQueueKey returns the key for a proposalID in the activeProposalQueue
func ActiveProposalQueueKey(proposalID uint64, endTime time.Time) []byte {
return append(ActiveProposalByTimeKey(endTime), GetProposalIDBytes(proposalID)...)
}
// InactiveProposalByTimeKey gets the inactive proposal queue key by endTime
func InactiveProposalByTimeKey(endTime time.Time) []byte {
return append(InactiveProposalQueuePrefix, sdk.FormatTimeBytes(endTime)...)
2018-06-21 17:19:14 -07:00
}
// InactiveProposalQueueKey returns the key for a proposalID in the inactiveProposalQueue
func InactiveProposalQueueKey(proposalID uint64, endTime time.Time) []byte {
return append(InactiveProposalByTimeKey(endTime), GetProposalIDBytes(proposalID)...)
2018-06-21 17:19:14 -07:00
}
// DepositsKey gets the first part of the deposits key based on the proposalID
func DepositsKey(proposalID uint64) []byte {
return append(DepositsKeyPrefix, GetProposalIDBytes(proposalID)...)
2018-06-21 17:19:14 -07:00
}
// DepositKey key of a specific deposit from the store
func DepositKey(proposalID uint64, depositorAddr sdk.AccAddress) []byte {
return append(DepositsKey(proposalID), depositorAddr.Bytes()...)
2018-06-21 17:19:14 -07:00
}
// VotesKey gets the first part of the votes key based on the proposalID
func VotesKey(proposalID uint64) []byte {
return append(VotesKeyPrefix, GetProposalIDBytes(proposalID)...)
2018-06-21 17:19:14 -07:00
}
// VoteKey key of a specific vote from the store
func VoteKey(proposalID uint64, voterAddr sdk.AccAddress) []byte {
return append(VotesKey(proposalID), voterAddr.Bytes()...)
}
// Split keys function; used for iterators
// SplitProposalKey split the proposal key and returns the proposal id
func SplitProposalKey(key []byte) (proposalID uint64) {
if len(key[1:]) != 8 {
panic(fmt.Sprintf("unexpected key length (%d ≠ 8)", len(key[1:])))
}
return GetProposalIDFromBytes(key[1:])
}
// SplitActiveProposalQueueKey split the active proposal key and returns the proposal id and endTime
func SplitActiveProposalQueueKey(key []byte) (proposalID uint64, endTime time.Time) {
return splitKeyWithTime(key)
}
// SplitInactiveProposalQueueKey split the inactive proposal key and returns the proposal id and endTime
func SplitInactiveProposalQueueKey(key []byte) (proposalID uint64, endTime time.Time) {
return splitKeyWithTime(key)
}
// SplitKeyDeposit split the deposits key and returns the proposal id and depositor address
func SplitKeyDeposit(key []byte) (proposalID uint64, depositorAddr sdk.AccAddress) {
return splitKeyWithAddress(key)
}
// SplitKeyVote split the votes key and returns the proposal id and voter address
func SplitKeyVote(key []byte) (proposalID uint64, voterAddr sdk.AccAddress) {
return splitKeyWithAddress(key)
}
// private functions
func splitKeyWithTime(key []byte) (proposalID uint64, endTime time.Time) {
if len(key[1:]) != 8+lenTime {
panic(fmt.Sprintf("unexpected key length (%d ≠ %d)", len(key[1:]), lenTime+8))
}
endTime, err := sdk.ParseTimeBytes(key[1 : 1+lenTime])
if err != nil {
panic(err)
}
proposalID = GetProposalIDFromBytes(key[1+lenTime:])
return
}
func splitKeyWithAddress(key []byte) (proposalID uint64, addr sdk.AccAddress) {
if len(key[1:]) != 8+sdk.AddrLen {
panic(fmt.Sprintf("unexpected key length (%d ≠ %d)", len(key), 8+sdk.AddrLen))
}
proposalID = GetProposalIDFromBytes(key[1:9])
addr = sdk.AccAddress(key[9:])
return
}