gov

package
v0.23.0-iris4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	DefaultCodespace sdk.CodespaceType = 5

	CodeUnknownProposal         sdk.CodeType = 1
	CodeInactiveProposal        sdk.CodeType = 2
	CodeAlreadyActiveProposal   sdk.CodeType = 3
	CodeAlreadyFinishedProposal sdk.CodeType = 4
	CodeAddressNotStaked        sdk.CodeType = 5
	CodeInvalidTitle            sdk.CodeType = 6
	CodeInvalidDescription      sdk.CodeType = 7
	CodeInvalidProposalType     sdk.CodeType = 8
	CodeInvalidVote             sdk.CodeType = 9
	CodeInvalidGenesis          sdk.CodeType = 10
	CodeInvalidProposalStatus   sdk.CodeType = 11
)
View Source
const (
	ParamStoreKeyDepositProcedureDeposit          = "depositprocedure/deposit"
	ParamStoreKeyDepositProcedureMaxDepositPeriod = "depositprocedure/maxDepositPeriod"
	ParamStoreKeyVotingProcedureVotingPeriod      = "votingprocedure/votingPeriod"
	ParamStoreKeyTallyingProcedureThreshold       = "tallyingprocedure/threshold"
	ParamStoreKeyTallyingProcedureVeto            = "tallyingprocedure/veto"
	ParamStoreKeyTallyingProcedurePenalty         = "tallyingprocedure/penalty"
)
View Source
const MsgType = "gov"

name to idetify transaction types

View Source
const Prefix = "gov/"

Variables

View Source
var (
	KeyNextProposalID        = []byte("newProposalID")
	KeyActiveProposalQueue   = []byte("activeProposalQueue")
	KeyInactiveProposalQueue = []byte("inactiveProposalQueue")
)

Key for getting a the next available proposalID from the store

Functions

func EndBlocker

func EndBlocker(ctx sdk.Context, keeper Keeper) (tags sdk.Tags, nonVotingVals []sdk.AccAddress)

Called every block, process inflation, update validator set

func ErrAddressNotStaked

func ErrAddressNotStaked(codespace sdk.CodespaceType, address sdk.AccAddress) sdk.Error

func ErrAlreadyActiveProposal

func ErrAlreadyActiveProposal(codespace sdk.CodespaceType, proposalID int64) sdk.Error

func ErrAlreadyFinishedProposal

func ErrAlreadyFinishedProposal(codespace sdk.CodespaceType, proposalID int64) sdk.Error

func ErrInactiveProposal

func ErrInactiveProposal(codespace sdk.CodespaceType, proposalID int64) sdk.Error

func ErrInvalidDescription

func ErrInvalidDescription(codespace sdk.CodespaceType, description string) sdk.Error

func ErrInvalidGenesis

func ErrInvalidGenesis(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrInvalidProposalType

func ErrInvalidProposalType(codespace sdk.CodespaceType, proposalType ProposalKind) sdk.Error

func ErrInvalidTitle

func ErrInvalidTitle(codespace sdk.CodespaceType, title string) sdk.Error

func ErrInvalidVote

func ErrInvalidVote(codespace sdk.CodespaceType, voteOption VoteOption) sdk.Error

func ErrUnknownProposal

func ErrUnknownProposal(codespace sdk.CodespaceType, proposalID int64) sdk.Error

func InitGenesis

func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState)

InitGenesis - store genesis parameters

func KeyDeposit

func KeyDeposit(proposalID int64, depositerAddr sdk.AccAddress) []byte

Key for getting a specific deposit from the store

func KeyDepositsSubspace

func KeyDepositsSubspace(proposalID int64) []byte

Key for getting all deposits on a proposal from the store

func KeyProposal

func KeyProposal(proposalID int64) []byte

Key for getting a specific proposal from the store

func KeyVote

func KeyVote(proposalID int64, voterAddr sdk.AccAddress) []byte

Key for getting a specific vote from the store

func KeyVotesSubspace

func KeyVotesSubspace(proposalID int64) []byte

Key for getting all votes on a proposal from the store

func NewHandler

func NewHandler(keeper Keeper) sdk.Handler

Handle all "gov" type messages.

func Pow10

func Pow10(y int) sdk.Int

func ProposalEqual

func ProposalEqual(proposalA Proposal, proposalB Proposal) bool

checks if two proposals are equal

func RegisterWire

func RegisterWire(cdc *wire.Codec)

Register concrete types on wire codec

func SortAddresses

func SortAddresses(addrs []sdk.AccAddress)

Sorts Addresses

func SortByteArrays

func SortByteArrays(src [][]byte) [][]byte

Public

Types

type Deposit

type Deposit struct {
	Depositer  sdk.AccAddress `json:"depositer"`   //  Address of the depositer
	ProposalID int64          `json:"proposal_id"` //  proposalID of the proposal
	Amount     sdk.Coins      `json:"amount"`      //  Deposit amount
}

Deposit

type DepositProcedure

type DepositProcedure struct {
	MinDeposit       sdk.Coins `json:"min_deposit"`        //  Minimum deposit for a proposal to enter voting period.
	MaxDepositPeriod int64     `json:"max_deposit_period"` //  Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months
}

Procedure around Deposits for governance

type GenesisState

type GenesisState struct {
	StartingProposalID int64             `json:"starting_proposalID"`
	DepositProcedure   DepositProcedure  `json:"deposit_period"`
	VotingProcedure    VotingProcedure   `json:"voting_period"`
	TallyingProcedure  TallyingProcedure `json:"tallying_procedure"`
}

GenesisState - all staking state that must be provided at genesis

func DefaultGenesisState

func DefaultGenesisState() GenesisState

get raw genesis raw message for testing

func NewGenesisState

func NewGenesisState(startingProposalID int64, dp DepositProcedure, vp VotingProcedure, tp TallyingProcedure) GenesisState

func NewIrisGenesisState

func NewIrisGenesisState(minDeposit sdk.Coins, depositPeriod int64, votingPeriod int64) GenesisState

////////////////// iris/cosmos-sdk begin///////////////////////////

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Governance Keeper

func NewKeeper

func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ps params.SetterProxy, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper

NewGovernanceMapper returns a mapper that uses go-wire to (binary) encode and decode gov types.

func (Keeper) ActiveProposalQueuePeek

func (keeper Keeper) ActiveProposalQueuePeek(ctx sdk.Context) Proposal

Return the Proposal at the front of the ProposalQueue

func (Keeper) ActiveProposalQueuePop

func (keeper Keeper) ActiveProposalQueuePop(ctx sdk.Context) Proposal

Remove and return a Proposal from the front of the ProposalQueue

func (Keeper) ActiveProposalQueuePush

func (keeper Keeper) ActiveProposalQueuePush(ctx sdk.Context, proposal Proposal)

Add a proposalID to the back of the ProposalQueue

func (Keeper) AddDeposit

func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID int64, depositerAddr sdk.AccAddress, depositAmount sdk.Coins) (sdk.Error, bool)

Adds or updates a deposit of a specific depositer on a specific proposal Activates voting period when appropriate

func (Keeper) AddVote

func (keeper Keeper) AddVote(ctx sdk.Context, proposalID int64, voterAddr sdk.AccAddress, option VoteOption) sdk.Error

Adds a vote on a specific proposal

func (Keeper) DeleteDeposits

func (keeper Keeper) DeleteDeposits(ctx sdk.Context, proposalID int64)

Deletes all the deposits on a specific proposal without refunding them

func (Keeper) DeleteProposal

func (keeper Keeper) DeleteProposal(ctx sdk.Context, proposal Proposal)

Implements sdk.AccountMapper.

func (Keeper) GetDeposit

func (keeper Keeper) GetDeposit(ctx sdk.Context, proposalID int64, depositerAddr sdk.AccAddress) (Deposit, bool)

Gets the deposit of a specific depositer on a specific proposal

func (Keeper) GetDepositProcedure

func (keeper Keeper) GetDepositProcedure(ctx sdk.Context) DepositProcedure

Returns the current Deposit Procedure from the global param store

func (Keeper) GetDeposits

func (keeper Keeper) GetDeposits(ctx sdk.Context, proposalID int64) sdk.Iterator

Gets all the deposits on a specific proposal

func (Keeper) GetProposal

func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID int64) Proposal

Get Proposal from store by ProposalID

func (Keeper) GetTallyingProcedure

func (keeper Keeper) GetTallyingProcedure(ctx sdk.Context) TallyingProcedure

Returns the current Tallying Procedure from the global param store

func (Keeper) GetVote

func (keeper Keeper) GetVote(ctx sdk.Context, proposalID int64, voterAddr sdk.AccAddress) (Vote, bool)

Gets the vote of a specific voter on a specific proposal

func (Keeper) GetVotes

func (keeper Keeper) GetVotes(ctx sdk.Context, proposalID int64) sdk.Iterator

Gets all the votes on a specific proposal

func (Keeper) GetVotingProcedure

func (keeper Keeper) GetVotingProcedure(ctx sdk.Context) VotingProcedure

Returns the current Voting Procedure from the global param store

func (Keeper) InactiveProposalQueuePeek

func (keeper Keeper) InactiveProposalQueuePeek(ctx sdk.Context) Proposal

Return the Proposal at the front of the ProposalQueue

func (Keeper) InactiveProposalQueuePop

func (keeper Keeper) InactiveProposalQueuePop(ctx sdk.Context) Proposal

Remove and return a Proposal from the front of the ProposalQueue

func (Keeper) InactiveProposalQueuePush

func (keeper Keeper) InactiveProposalQueuePush(ctx sdk.Context, proposal Proposal)

Add a proposalID to the back of the ProposalQueue

func (Keeper) NewParametersProposal

func (keeper Keeper) NewParametersProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind, params Params) Proposal

func (Keeper) NewProposal

func (keeper Keeper) NewProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind, params Params) Proposal

func (Keeper) NewSofterwareUpgradeProposal

func (keeper Keeper) NewSofterwareUpgradeProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind) Proposal

func (Keeper) NewTextProposal

func (keeper Keeper) NewTextProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind) Proposal

Creates a NewProposal

func (Keeper) RefundDeposits

func (keeper Keeper) RefundDeposits(ctx sdk.Context, proposalID int64)

Returns and deletes all the deposits on a specific proposal

func (Keeper) SetProposal

func (keeper Keeper) SetProposal(ctx sdk.Context, proposal Proposal)

Implements sdk.AccountMapper.

func (Keeper) WireCodec

func (keeper Keeper) WireCodec() *wire.Codec

Returns the go-wire codec.

type MsgDeposit

type MsgDeposit struct {
	ProposalID int64          `json:"proposalID"` // ID of the proposal
	Depositer  sdk.AccAddress `json:"depositer"`  // Address of the depositer
	Amount     sdk.Coins      `json:"amount"`     // Coins to add to the proposal's deposit
}

----------------------------------------------------------- MsgDeposit

func NewMsgDeposit

func NewMsgDeposit(depositer sdk.AccAddress, proposalID int64, amount sdk.Coins) MsgDeposit

func (MsgDeposit) Get

func (msg MsgDeposit) Get(key interface{}) (value interface{})

Implements Msg.

func (MsgDeposit) GetSignBytes

func (msg MsgDeposit) GetSignBytes() []byte

Implements Msg.

func (MsgDeposit) GetSigners

func (msg MsgDeposit) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgDeposit) String

func (msg MsgDeposit) String() string

func (MsgDeposit) Type

func (msg MsgDeposit) Type() string

Implements Msg.

func (MsgDeposit) ValidateBasic

func (msg MsgDeposit) ValidateBasic() sdk.Error

Implements Msg.

type MsgSubmitProposal

type MsgSubmitProposal struct {
	Title          string         //  Title of the proposal
	Description    string         //  Description of the proposal
	ProposalType   ProposalKind   //  Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}
	Proposer       sdk.AccAddress //  Address of the proposer
	InitialDeposit sdk.Coins      //  Initial deposit paid by sender. Must be strictly positive.
	Params         Params
}

----------------------------------------------------------- MsgSubmitProposal

func NewMsgSubmitProposal

func NewMsgSubmitProposal(title string, description string, proposalType ProposalKind, proposer sdk.AccAddress, initialDeposit sdk.Coins) MsgSubmitProposal

func NewSubmitProposal

func NewSubmitProposal(title string, description string, proposalType ProposalKind, proposer sdk.AccAddress, initialDeposit sdk.Coins, params Params) MsgSubmitProposal

func (MsgSubmitProposal) Get

func (msg MsgSubmitProposal) Get(key interface{}) (value interface{})

Implements Msg.

func (MsgSubmitProposal) GetSignBytes

func (msg MsgSubmitProposal) GetSignBytes() []byte

Implements Msg.

func (MsgSubmitProposal) GetSigners

func (msg MsgSubmitProposal) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgSubmitProposal) String

func (msg MsgSubmitProposal) String() string

func (MsgSubmitProposal) Type

func (msg MsgSubmitProposal) Type() string

Implements Msg.

func (MsgSubmitProposal) ValidateBasic

func (msg MsgSubmitProposal) ValidateBasic() sdk.Error

Implements Msg.

type MsgVote

type MsgVote struct {
	ProposalID int64          //  proposalID of the proposal
	Voter      sdk.AccAddress //  address of the voter
	Option     VoteOption     //  option from OptionSet chosen by the voter
}

----------------------------------------------------------- MsgVote

func NewMsgVote

func NewMsgVote(voter sdk.AccAddress, proposalID int64, option VoteOption) MsgVote

func (MsgVote) Get

func (msg MsgVote) Get(key interface{}) (value interface{})

Implements Msg.

func (MsgVote) GetSignBytes

func (msg MsgVote) GetSignBytes() []byte

Implements Msg.

func (MsgVote) GetSigners

func (msg MsgVote) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgVote) String

func (msg MsgVote) String() string

func (MsgVote) Type

func (msg MsgVote) Type() string

Implements Msg.

func (MsgVote) ValidateBasic

func (msg MsgVote) ValidateBasic() sdk.Error

Implements Msg.

type Op

type Op string

////////////////// iris/cosmos-sdk begin ///////////////////////////

const (
	Add    Op = "add"
	Update Op = "update"
)

type Param

type Param struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	Op    Op     `json:"op"`
}

type ParameterProposal

type ParameterProposal struct {
	TextProposal
	Params Params `json:"params"`
}

func (*ParameterProposal) Execute

func (pp *ParameterProposal) Execute(ctx sdk.Context, k Keeper) (err error)

type Params

type Params []Param

type Proposal

type Proposal interface {
	GetProposalID() int64
	SetProposalID(int64)

	GetTitle() string
	SetTitle(string)

	GetDescription() string
	SetDescription(string)

	GetProposalType() ProposalKind
	SetProposalType(ProposalKind)

	GetStatus() ProposalStatus
	SetStatus(ProposalStatus)

	GetSubmitBlock() int64
	SetSubmitBlock(int64)

	GetTotalDeposit() sdk.Coins
	SetTotalDeposit(sdk.Coins)

	GetVotingStartBlock() int64
	SetVotingStartBlock(int64)

	Execute(ctx sdk.Context, k Keeper) error
}

----------------------------------------------------------- Proposal interface

type ProposalKind

type ProposalKind byte

Type that represents Proposal Type as a byte

const (
	ProposalTypeText            ProposalKind = 0x01
	ProposalTypeParameterChange ProposalKind = 0x02
	ProposalTypeSoftwareUpgrade ProposalKind = 0x03
)

nolint

func ProposalTypeFromString added in v0.21.0

func ProposalTypeFromString(str string) (ProposalKind, error)

String to proposalType byte. Returns ff if invalid.

func (ProposalKind) Format added in v0.21.0

func (pt ProposalKind) Format(s fmt.State, verb rune)

For Printf / Sprintf, returns bech32 when using %s

func (ProposalKind) Marshal added in v0.21.0

func (pt ProposalKind) Marshal() ([]byte, error)

Marshal needed for protobuf compatibility

func (ProposalKind) MarshalJSON added in v0.21.0

func (pt ProposalKind) MarshalJSON() ([]byte, error)

Marshals to JSON using string

func (ProposalKind) String added in v0.21.0

func (pt ProposalKind) String() string

Turns VoteOption byte to String

func (*ProposalKind) Unmarshal added in v0.21.0

func (pt *ProposalKind) Unmarshal(data []byte) error

Unmarshal needed for protobuf compatibility

func (*ProposalKind) UnmarshalJSON added in v0.21.0

func (pt *ProposalKind) UnmarshalJSON(data []byte) error

Unmarshals from JSON assuming Bech32 encoding

type ProposalQueue

type ProposalQueue []int64

----------------------------------------------------------- ProposalQueue

type ProposalStatus added in v0.21.0

type ProposalStatus byte

Type that represents Proposal Status as a byte

const (
	StatusDepositPeriod ProposalStatus = 0x01
	StatusVotingPeriod  ProposalStatus = 0x02
	StatusPassed        ProposalStatus = 0x03
	StatusRejected      ProposalStatus = 0x04
)

nolint

func ProposalStatusFromString added in v0.21.0

func ProposalStatusFromString(str string) (ProposalStatus, error)

ProposalStatusToString turns a string into a ProposalStatus

func (ProposalStatus) Format added in v0.21.0

func (status ProposalStatus) Format(s fmt.State, verb rune)

For Printf / Sprintf, returns bech32 when using %s

func (ProposalStatus) Marshal added in v0.21.0

func (status ProposalStatus) Marshal() ([]byte, error)

Marshal needed for protobuf compatibility

func (ProposalStatus) MarshalJSON added in v0.21.0

func (status ProposalStatus) MarshalJSON() ([]byte, error)

Marshals to JSON using string

func (ProposalStatus) String added in v0.21.0

func (status ProposalStatus) String() string

Turns VoteStatus byte to String

func (*ProposalStatus) Unmarshal added in v0.21.0

func (status *ProposalStatus) Unmarshal(data []byte) error

Unmarshal needed for protobuf compatibility

func (*ProposalStatus) UnmarshalJSON added in v0.21.0

func (status *ProposalStatus) UnmarshalJSON(data []byte) error

Unmarshals from JSON assuming Bech32 encoding

type SoftwareUpgradeProposal

type SoftwareUpgradeProposal struct {
	TextProposal
}

func (*SoftwareUpgradeProposal) Execute

func (sp *SoftwareUpgradeProposal) Execute(ctx sdk.Context, k Keeper) error

type TallyingProcedure

type TallyingProcedure struct {
	Threshold         sdk.Rat `json:"threshold"`          //  Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
	Veto              sdk.Rat `json:"veto"`               //  Minimum value of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3
	GovernancePenalty sdk.Rat `json:"governance_penalty"` //  Penalty if validator does not vote
}

Procedure around Tallying votes in governance

type TextProposal

type TextProposal struct {
	ProposalID   int64        `json:"proposal_id"`   //  ID of the proposal
	Title        string       `json:"title"`         //  Title of the proposal
	Description  string       `json:"description"`   //  Description of the proposal
	ProposalType ProposalKind `json:"proposal_type"` //  Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}

	Status ProposalStatus `json:"proposal_status"` //  Status of the Proposal {Pending, Active, Passed, Rejected}

	SubmitBlock  int64     `json:"submit_block"`  //  Height of the block where TxGovSubmitProposal was included
	TotalDeposit sdk.Coins `json:"total_deposit"` //  Current deposit on this proposal. Initial value is set at InitialDeposit

	VotingStartBlock int64 `json:"voting_start_block"` //  Height of the block where MinDeposit was reached. -1 if MinDeposit is not reached
}

----------------------------------------------------------- Text Proposals

func (*TextProposal) Execute

func (tp *TextProposal) Execute(ctx sdk.Context, k Keeper) error

func (TextProposal) GetDescription

func (tp TextProposal) GetDescription() string

func (TextProposal) GetProposalID

func (tp TextProposal) GetProposalID() int64

nolint

func (TextProposal) GetProposalType

func (tp TextProposal) GetProposalType() ProposalKind

func (TextProposal) GetStatus

func (tp TextProposal) GetStatus() ProposalStatus

func (TextProposal) GetSubmitBlock

func (tp TextProposal) GetSubmitBlock() int64

func (TextProposal) GetTitle

func (tp TextProposal) GetTitle() string

func (TextProposal) GetTotalDeposit

func (tp TextProposal) GetTotalDeposit() sdk.Coins

func (TextProposal) GetVotingStartBlock

func (tp TextProposal) GetVotingStartBlock() int64

func (*TextProposal) SetDescription

func (tp *TextProposal) SetDescription(description string)

func (*TextProposal) SetProposalID

func (tp *TextProposal) SetProposalID(proposalID int64)

func (*TextProposal) SetProposalType

func (tp *TextProposal) SetProposalType(proposalType ProposalKind)

func (*TextProposal) SetStatus

func (tp *TextProposal) SetStatus(status ProposalStatus)

func (*TextProposal) SetSubmitBlock

func (tp *TextProposal) SetSubmitBlock(submitBlock int64)

func (*TextProposal) SetTitle

func (tp *TextProposal) SetTitle(title string)

func (*TextProposal) SetTotalDeposit

func (tp *TextProposal) SetTotalDeposit(totalDeposit sdk.Coins)

func (*TextProposal) SetVotingStartBlock

func (tp *TextProposal) SetVotingStartBlock(votingStartBlock int64)

type Vote

type Vote struct {
	Voter      sdk.AccAddress `json:"voter"`       //  address of the voter
	ProposalID int64          `json:"proposal_id"` //  proposalID of the proposal
	Option     VoteOption     `json:"option"`      //  option from OptionSet chosen by the voter
}

Vote

type VoteOption

type VoteOption byte

Type that represents VoteOption as a byte

const (
	OptionEmpty      VoteOption = 0x00
	OptionYes        VoteOption = 0x01
	OptionAbstain    VoteOption = 0x02
	OptionNo         VoteOption = 0x03
	OptionNoWithVeto VoteOption = 0x04
)

nolint

func VoteOptionFromString added in v0.21.0

func VoteOptionFromString(str string) (VoteOption, error)

String to proposalType byte. Returns ff if invalid.

func (VoteOption) Format added in v0.21.0

func (vo VoteOption) Format(s fmt.State, verb rune)

For Printf / Sprintf, returns bech32 when using %s

func (VoteOption) Marshal added in v0.21.0

func (vo VoteOption) Marshal() ([]byte, error)

Marshal needed for protobuf compatibility

func (VoteOption) MarshalJSON added in v0.21.0

func (vo VoteOption) MarshalJSON() ([]byte, error)

Marshals to JSON using string

func (VoteOption) String added in v0.21.0

func (vo VoteOption) String() string

Turns VoteOption byte to String

func (*VoteOption) Unmarshal added in v0.21.0

func (vo *VoteOption) Unmarshal(data []byte) error

Unmarshal needed for protobuf compatibility

func (*VoteOption) UnmarshalJSON added in v0.21.0

func (vo *VoteOption) UnmarshalJSON(data []byte) error

Unmarshals from JSON assuming Bech32 encoding

type VotingProcedure

type VotingProcedure struct {
	VotingPeriod int64 `json:"voting_period"` //  Length of the voting period.
}

Procedure around Voting in governance

Directories

Path Synopsis
client
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL