gov

package
v0.0.0-...-b5e13e0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	DefaultCodespace sdk.CodespaceType = ModuleName

	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 (
	// ModuleKey is the name of the module
	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

	// Parameter store default namestore
	DefaultParamspace = ModuleName
)
View Source
const (
	TypeMsgDeposit        = "deposit"
	TypeMsgVote           = "vote"
	TypeMsgSubmitProposal = "submit_proposal"

	MaxDescriptionLength int = 5000
	MaxTitleLength       int = 140
)

Governance message types and routes

View Source
const (
	QueryParams    = "params"
	QueryProposals = "proposals"
	QueryProposal  = "proposal"
	QueryDeposits  = "deposits"
	QueryDeposit   = "deposit"
	QueryVotes     = "votes"
	QueryVote      = "vote"
	QueryTally     = "tally"

	ParamDeposit  = "deposit"
	ParamVoting   = "voting"
	ParamTallying = "tallying"
)

query endpoints supported by the governance Querier

View Source
const (
	// Default period for deposits & voting
	DefaultPeriod time.Duration = 86400 * 2 * time.Second // 2 days
)

Variables

View Source
var (

	// 治理 质押的key
	ParamStoreKeyDepositParams = []byte("depositparams")
	// 治理 投票的key
	ParamStoreKeyVotingParams = []byte("votingparams")
	ParamStoreKeyTallyParams  = []byte("tallyparams")

	// TODO: Find another way to implement this without using accounts, or find a cleaner way to implement it using accounts.
	// TODO:找到另一种方法来实现这一点而不使用帐户,或者找到一种更简洁的方法来使用帐户实现它。
	DepositedCoinsAccAddr     = sdk.AccAddress(crypto.AddressHash([]byte("govDepositedCoins")))
	BurnedDepositCoinsAccAddr = sdk.AccAddress(crypto.AddressHash([]byte("govBurnedDepositCoins")))
)

Parameter store key

View Source
var (
	KeyDelimiter = []byte(":")

	// 最新的一个提案Id的 key
	KeyNextProposalID = []byte("newProposalID")
	//
	PrefixActiveProposalQueue = []byte("activeProposalQueue")
	//
	PrefixInactiveProposalQueue = []byte("inactiveProposalQueue")
)

Key for getting a the next available proposalID from the store

Functions

func EndBlocker

func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags

Called every block, process inflation, update validator set

TODO 链上治理相关

func ErrAddressNotStaked

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

func ErrAlreadyActiveProposal

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

func ErrAlreadyFinishedProposal

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

func ErrInactiveProposal

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

func ErrInvalidDescription

func ErrInvalidDescription(codespace sdk.CodespaceType, errorMsg 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, errorMsg string) sdk.Error

func ErrInvalidVote

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

func ErrUnknownProposal

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

func InitGenesis

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

InitGenesis - store genesis parameters

func KeyActiveProposalQueueProposal

func KeyActiveProposalQueueProposal(endTime time.Time, proposalID uint64) []byte

Returns the key for a proposalID in the activeProposalQueue

func KeyDeposit

func KeyDeposit(proposalID uint64, depositorAddr sdk.AccAddress) []byte

Key for getting a specific deposit from the store

func KeyDepositsSubspace

func KeyDepositsSubspace(proposalID uint64) []byte

Key for getting all deposits on a proposal from the store

func KeyInactiveProposalQueueProposal

func KeyInactiveProposalQueueProposal(endTime time.Time, proposalID uint64) []byte

Returns the key for a proposalID in the activeProposalQueue

func KeyProposal

func KeyProposal(proposalID uint64) []byte

Key for getting a specific proposal from the store

func KeyVote

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

Key for getting a specific vote from the store

func KeyVotesSubspace

func KeyVotesSubspace(proposalID uint64) []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 NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

func ParamKeyTable

func ParamKeyTable() params.KeyTable

Key declaration for parameters

func PrefixActiveProposalQueueTime

func PrefixActiveProposalQueueTime(endTime time.Time) []byte

Returns the key for a proposalID in the activeProposalQueue

func PrefixInactiveProposalQueueTime

func PrefixInactiveProposalQueueTime(endTime time.Time) []byte

Returns the key for a proposalID in the activeProposalQueue

func ProposalEqual

func ProposalEqual(proposalA Proposal, proposalB Proposal) bool

checks if two proposals are equal

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

Register concrete types on codec codec

func SortAddresses

func SortAddresses(addrs []sdk.AccAddress)

Sorts Addresses

func SortByteArrays

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

Public

func SortValAddresses

func SortValAddresses(addrs []sdk.ValAddress)

TODO: Remove once address interface has been implemented (ref: #2186)

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

ValidateGenesis

Types

type BankKeeper

type BankKeeper interface {
	GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins

	// TODO remove once governance doesn't require use of accounts
	SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
	SetSendEnabled(ctx sdk.Context, enabled bool)
}

expected bank keeper

type Deposit

type Deposit struct {
	Depositor  sdk.AccAddress `json:"depositor"`   //  Address of the depositor
	ProposalID uint64         `json:"proposal_id"` //  proposalID of the proposal
	Amount     sdk.Coins      `json:"amount"`      //  Deposit amount
}

Deposit

func (Deposit) Empty

func (d Deposit) Empty() bool

Returns whether a deposit is empty

func (Deposit) Equals

func (d Deposit) Equals(comp Deposit) bool

Returns whether 2 deposits are equal

func (Deposit) String

func (d Deposit) String() string

type DepositParams

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

Param around deposits for governance

func (DepositParams) Equal

func (dp DepositParams) Equal(dp2 DepositParams) bool

Checks equality of DepositParams

func (DepositParams) String

func (dp DepositParams) String() string

type DepositWithMetadata

type DepositWithMetadata struct {
	ProposalID uint64  `json:"proposal_id"`
	Deposit    Deposit `json:"deposit"`
}

DepositWithMetadata (just for genesis)

type Deposits

type Deposits []Deposit

Deposits is a collection of depoist

func (Deposits) String

func (d Deposits) String() string

type GenesisState

type GenesisState struct {
	StartingProposalID uint64                `json:"starting_proposal_id"`
	Deposits           []DepositWithMetadata `json:"deposits"`
	Votes              []VoteWithMetadata    `json:"votes"`
	Proposals          []Proposal            `json:"proposals"`
	DepositParams      DepositParams         `json:"deposit_params"`
	VotingParams       VotingParams          `json:"voting_params"`
	TallyParams        TallyParams           `json:"tally_params"`
}

GenesisState - all staking state that must be provided at genesis

func DefaultGenesisState

func DefaultGenesisState() GenesisState

get raw genesis raw message for testing

func ExportGenesis

func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState

ExportGenesis - output genesis parameters

func NewGenesisState

func NewGenesisState(startingProposalID uint64, dp DepositParams, vp VotingParams, tp TallyParams) GenesisState

func (GenesisState) Equal

func (data GenesisState) Equal(data2 GenesisState) bool

Checks whether 2 GenesisState structs are equivalent.

func (GenesisState) IsEmpty

func (data GenesisState) IsEmpty() bool

Returns if a GenesisState is empty or has data in it

type Keeper

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

Governance Keeper

func NewKeeper

func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, paramsKeeper params.Keeper,
	paramSpace params.Subspace, ck BankKeeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper

NewKeeper returns a governance keeper. It handles: - submitting governance proposals - depositing funds into proposals, and activating upon sufficient funds being deposited - users voting on proposals, with weight proportional to stake in the system - and tallying the result of the vote.

func (Keeper) ActiveProposalQueueIterator

func (keeper Keeper) ActiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator

Returns an iterator for all the proposals in the Active Queue that expire by endTime

func (Keeper) AddDeposit

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

Adds or updates a deposit of a specific depositor on a specific proposal Activates voting period when appropriate * 添加提案上的 质押 在特定提案上添加或更新特定存款人的存款在适当时激活投票期

func (Keeper) AddVote

func (keeper Keeper) AddVote(ctx sdk.Context, proposalID uint64, 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 uint64)

Deletes all the deposits on a specific proposal without refunding them

删除特定提案上的所有存款而不退款

func (Keeper) DeleteProposal

func (keeper Keeper) DeleteProposal(ctx sdk.Context, proposalID uint64)

Implements sdk.AccountKeeper. 清除某提案相关信息

func (Keeper) GetDeposit

func (keeper Keeper) GetDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress) (Deposit, bool)

Gets the deposit of a specific depositor on a specific proposal

func (Keeper) GetDepositParams

func (keeper Keeper) GetDepositParams(ctx sdk.Context) DepositParams

Returns the current DepositParams from the global param store

func (Keeper) GetDeposits

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

Gets all the deposits on a specific proposal as an sdk.Iterator

func (Keeper) GetLastProposalID

func (keeper Keeper) GetLastProposalID(ctx sdk.Context) (proposalID uint64)

Get the last used proposal ID

func (Keeper) GetProposal

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

Get Proposal from store by ProposalID

func (Keeper) GetProposalsFiltered

func (keeper Keeper) GetProposalsFiltered(ctx sdk.Context, voterAddr sdk.AccAddress, depositorAddr sdk.AccAddress, status ProposalStatus, numLatest uint64) []Proposal

Get Proposal from store by ProposalID voterAddr will filter proposals by whether or not that address has voted on them depositorAddr will filter proposals by whether or not that address has deposited to them status will filter proposals by status numLatest will fetch a specified number of the most recent proposals, or 0 for all proposals

func (Keeper) GetTallyParams

func (keeper Keeper) GetTallyParams(ctx sdk.Context) TallyParams

Returns the current TallyParam from the global param store

func (Keeper) GetVote

func (keeper Keeper) GetVote(ctx sdk.Context, proposalID uint64, 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 uint64) sdk.Iterator

Gets all the votes on a specific proposal

func (Keeper) GetVotingParams

func (keeper Keeper) GetVotingParams(ctx sdk.Context) VotingParams

Returns the current VotingParams from the global param store

func (Keeper) InactiveProposalQueueIterator

func (keeper Keeper) InactiveProposalQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator

Returns an iterator for all the proposals in the Inactive Queue that expire by endTime

func (Keeper) InsertActiveProposalQueue

func (keeper Keeper) InsertActiveProposalQueue(ctx sdk.Context, endTime time.Time, proposalID uint64)

Inserts a ProposalID into the active proposal queue at endTime

func (Keeper) InsertInactiveProposalQueue

func (keeper Keeper) InsertInactiveProposalQueue(ctx sdk.Context, endTime time.Time, proposalID uint64)

Inserts a ProposalID into the inactive proposal queue at endTime

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 uint64)

Refunds and deletes all the deposits on a specific proposal

退还并删除特定提案上的所有存款

func (Keeper) RemoveFromActiveProposalQueue

func (keeper Keeper) RemoveFromActiveProposalQueue(ctx sdk.Context, endTime time.Time, proposalID uint64)

removes a proposalID from the Active Proposal Queue

func (Keeper) RemoveFromInactiveProposalQueue

func (keeper Keeper) RemoveFromInactiveProposalQueue(ctx sdk.Context, endTime time.Time, proposalID uint64)

removes a proposalID from the Inactive Proposal Queue 从非活动(非激活)提案队列中删除提案ID

func (Keeper) SetProposal

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

Implements sdk.AccountKeeper.

type MsgDeposit

type MsgDeposit struct {
	ProposalID uint64         `json:"proposal_id"` // ID of the proposal
	Depositor  sdk.AccAddress `json:"depositor"`   // Address of the depositor
	Amount     sdk.Coins      `json:"amount"`      // Coins to add to the proposal's deposit
}

MsgDeposit

func NewMsgDeposit

func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins) MsgDeposit

func (MsgDeposit) GetSignBytes

func (msg MsgDeposit) GetSignBytes() []byte

Implements Msg.

func (MsgDeposit) GetSigners

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

Implements Msg.

func (MsgDeposit) Route

func (msg MsgDeposit) Route() string

Implements Msg. nolint

func (MsgDeposit) String

func (msg MsgDeposit) String() string

func (MsgDeposit) Type

func (msg MsgDeposit) Type() string

func (MsgDeposit) ValidateBasic

func (msg MsgDeposit) ValidateBasic() sdk.Error

Implements Msg.

type MsgSubmitProposal

type MsgSubmitProposal struct {
	// 提案的标题
	Title string `json:"title"` //  Title of the proposal
	// 这个是文本格式的 提案内容
	Description string `json:"description"` //  Description of the proposal
	// 标识提案的类型
	// 目前只有四种提案类型,代码中只用到三种
	// nil提案类型、 文本提案、 参数改变提案、 软件升级提案
	ProposalType ProposalKind `json:"proposal_type"` //  Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}
	// 发起提案者的 地址
	Proposer sdk.AccAddress `json:"proposer"` //  Address of the proposer
	// 提案发起人支付的初始存款。 必须严格积极。
	InitialDeposit sdk.Coins `json:"initial_deposit"` //  Initial deposit paid by sender. Must be strictly positive.
}

MsgSubmitProposal 提交一个提案 入参

func NewMsgSubmitProposal

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

func (MsgSubmitProposal) GetSignBytes

func (msg MsgSubmitProposal) GetSignBytes() []byte

Implements Msg.

func (MsgSubmitProposal) GetSigners

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

Implements Msg.

func (MsgSubmitProposal) Route

func (msg MsgSubmitProposal) Route() string

nolint

func (MsgSubmitProposal) String

func (msg MsgSubmitProposal) String() string

func (MsgSubmitProposal) Type

func (msg MsgSubmitProposal) Type() string

func (MsgSubmitProposal) ValidateBasic

func (msg MsgSubmitProposal) ValidateBasic() sdk.Error

Implements Msg.

type MsgVote

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

MsgVote

func NewMsgVote

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

func (MsgVote) GetSignBytes

func (msg MsgVote) GetSignBytes() []byte

Implements Msg.

func (MsgVote) GetSigners

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

Implements Msg.

func (MsgVote) Route

func (msg MsgVote) Route() string

Implements Msg. nolint

func (MsgVote) String

func (msg MsgVote) String() string

func (MsgVote) Type

func (msg MsgVote) Type() string

func (MsgVote) ValidateBasic

func (msg MsgVote) ValidateBasic() sdk.Error

Implements Msg.

type Params

type Params struct {
	VotingParams  VotingParams  `json:"voting_params"`
	TallyParams   TallyParams   `json:"tally_params"`
	DepositParams DepositParams `json:"deposit_params"`
}

Params returns all of the governance params

func NewParams

func NewParams(vp VotingParams, tp TallyParams, dp DepositParams) Params

func (Params) String

func (gp Params) String() string

type Proposal

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

	GetTitle() string
	SetTitle(string)

	GetDescription() string
	SetDescription(string)

	GetProposalType() ProposalKind
	SetProposalType(ProposalKind)

	GetStatus() ProposalStatus
	SetStatus(ProposalStatus)

	GetFinalTallyResult() TallyResult
	SetFinalTallyResult(TallyResult)

	GetSubmitTime() time.Time
	SetSubmitTime(time.Time)

	GetDepositEndTime() time.Time
	SetDepositEndTime(time.Time)

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

	GetVotingStartTime() time.Time
	SetVotingStartTime(time.Time)

	GetVotingEndTime() time.Time
	SetVotingEndTime(time.Time)

	String() string
}

Proposal interface

type ProposalKind

type ProposalKind byte

Type that represents Proposal Type as a byte 表示 治理的提案类型

const (
	// nil提案
	ProposalTypeNil ProposalKind = 0x00
	// 文本提案
	ProposalTypeText ProposalKind = 0x01
	// 参数改变提案
	ProposalTypeParameterChange ProposalKind = 0x02
	// 软件升级提案
	ProposalTypeSoftwareUpgrade ProposalKind = 0x03
)

nolint

func ProposalTypeFromString

func ProposalTypeFromString(str string) (ProposalKind, error)

String to proposalType byte. Returns 0xff if invalid.

func (ProposalKind) Format

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

For Printf / Sprintf, returns bech32 when using %s nolint: errcheck

func (ProposalKind) Marshal

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

Marshal needed for protobuf compatibility

func (ProposalKind) MarshalJSON

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

Marshals to JSON using string

func (ProposalKind) String

func (pt ProposalKind) String() string

Turns VoteOption byte to String

func (*ProposalKind) Unmarshal

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

Unmarshal needed for protobuf compatibility

func (*ProposalKind) UnmarshalJSON

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

Unmarshals from JSON assuming Bech32 encoding

type ProposalQueue

type ProposalQueue []uint64

ProposalQueue

type ProposalStatus

type ProposalStatus byte

Type that represents Proposal Status as a byte 治理提案的状态类型

const (
	// nil类型
	StatusNil ProposalStatus = 0x00
	// 提案质押轮
	StatusDepositPeriod ProposalStatus = 0x01
	// 提案投票轮
	StatusVotingPeriod ProposalStatus = 0x02
	// 提案通过
	StatusPassed ProposalStatus = 0x03
	// 提案被拒绝
	StatusRejected ProposalStatus = 0x04
)

nolint

func ProposalStatusFromString

func ProposalStatusFromString(str string) (ProposalStatus, error)

ProposalStatusToString turns a string into a ProposalStatus

func (ProposalStatus) Format

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

For Printf / Sprintf, returns bech32 when using %s nolint: errcheck

func (ProposalStatus) Marshal

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

Marshal needed for protobuf compatibility

func (ProposalStatus) MarshalJSON

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

Marshals to JSON using string

func (ProposalStatus) String

func (status ProposalStatus) String() string

Turns VoteStatus byte to String

func (*ProposalStatus) Unmarshal

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

Unmarshal needed for protobuf compatibility

func (*ProposalStatus) UnmarshalJSON

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

Unmarshals from JSON assuming Bech32 encoding

type Proposals

type Proposals []Proposal

Proposals is an array of proposal

func (Proposals) String

func (p Proposals) String() string

type QueryDepositParams

type QueryDepositParams struct {
	ProposalID uint64
	Depositor  sdk.AccAddress
}

Params for query 'custom/gov/deposit'

func NewQueryDepositParams

func NewQueryDepositParams(proposalID uint64, depositor sdk.AccAddress) QueryDepositParams

creates a new instance of QueryDepositParams

type QueryProposalParams

type QueryProposalParams struct {
	ProposalID uint64
}

Params for queries: - 'custom/gov/proposal' - 'custom/gov/deposits' - 'custom/gov/tally' - 'custom/gov/votes'

func NewQueryProposalParams

func NewQueryProposalParams(proposalID uint64) QueryProposalParams

creates a new instance of QueryProposalParams

type QueryProposalsParams

type QueryProposalsParams struct {
	Voter          sdk.AccAddress
	Depositor      sdk.AccAddress
	ProposalStatus ProposalStatus
	Limit          uint64
}

Params for query 'custom/gov/proposals'

func NewQueryProposalsParams

func NewQueryProposalsParams(status ProposalStatus, limit uint64, voter, depositor sdk.AccAddress) QueryProposalsParams

creates a new instance of QueryProposalsParams

type QueryVoteParams

type QueryVoteParams struct {
	ProposalID uint64
	Voter      sdk.AccAddress
}

Params for query 'custom/gov/vote'

func NewQueryVoteParams

func NewQueryVoteParams(proposalID uint64, voter sdk.AccAddress) QueryVoteParams

creates a new instance of QueryVoteParams

type TallyParams

type TallyParams struct {
	Quorum    sdk.Dec `json:"quorum"`    //  Minimum percentage of total stake needed to vote for a result to be considered valid
	Threshold sdk.Dec `json:"threshold"` //  Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
	Veto      sdk.Dec `json:"veto"`      //  Minimum value of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3
}

Param around Tallying votes in governance

func (TallyParams) String

func (tp TallyParams) String() string

type TallyResult

type TallyResult struct {
	Yes        sdk.Int `json:"yes"`
	Abstain    sdk.Int `json:"abstain"`
	No         sdk.Int `json:"no"`
	NoWithVeto sdk.Int `json:"no_with_veto"`
}

Tally Results

func EmptyTallyResult

func EmptyTallyResult() TallyResult

checks if two proposals are equal

func NewTallyResult

func NewTallyResult(yes, abstain, no, noWithVeto sdk.Int) TallyResult

func NewTallyResultFromMap

func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) TallyResult

func (TallyResult) Equals

func (tr TallyResult) Equals(comp TallyResult) bool

checks if two proposals are equal

func (TallyResult) String

func (tr TallyResult) String() string

type TextProposal

type TextProposal struct {
	// 提议ID
	ProposalID uint64 `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}

	// 该提议的最终计算结果详情
	FinalTallyResult TallyResult `json:"final_tally_result"` //  Result of Tallys

	// 提议的提交时间
	// 包含TxGovSubmitProposal的块的时间
	SubmitTime time.Time `json:"submit_time"` //  Time of the block where TxGovSubmitProposal was included

	// 如果未达到存款金额,提案将到期的时间
	DepositEndTime time.Time `json:"deposit_end_time"` // Time that the Proposal would expire if deposit amount isn't met

	// 此提案的当前存款。 初始值在InitialDeposit中设置
	TotalDeposit sdk.Coins `json:"total_deposit"` //  Current deposit on this proposal. Initial value is set at InitialDeposit

	// 到达MinDeposit的块的时间。 -1如果未达到MinDeposit
	VotingStartTime time.Time `json:"voting_start_time"` //  Time of the block where MinDeposit was reached. -1 if MinDeposit is not reached

	// 此提案的VotingPeriod将结束并且将计算投票的时间
	// 该提议的投票轮的到期时间
	VotingEndTime time.Time `json:"voting_end_time"` // Time that the VotingPeriod for this proposal will end and votes will be tallied
}

Text Proposals * 文本 提议 TODO 目前Proposal接口的实现,只有这个

func (TextProposal) GetDepositEndTime

func (tp TextProposal) GetDepositEndTime() time.Time

func (TextProposal) GetDescription

func (tp TextProposal) GetDescription() string

func (TextProposal) GetFinalTallyResult

func (tp TextProposal) GetFinalTallyResult() TallyResult

func (TextProposal) GetProposalID

func (tp TextProposal) GetProposalID() uint64

nolint

func (TextProposal) GetProposalType

func (tp TextProposal) GetProposalType() ProposalKind

func (TextProposal) GetStatus

func (tp TextProposal) GetStatus() ProposalStatus

func (TextProposal) GetSubmitTime

func (tp TextProposal) GetSubmitTime() time.Time

func (TextProposal) GetTitle

func (tp TextProposal) GetTitle() string

func (TextProposal) GetTotalDeposit

func (tp TextProposal) GetTotalDeposit() sdk.Coins

func (TextProposal) GetVotingEndTime

func (tp TextProposal) GetVotingEndTime() time.Time

func (TextProposal) GetVotingStartTime

func (tp TextProposal) GetVotingStartTime() time.Time

func (*TextProposal) SetDepositEndTime

func (tp *TextProposal) SetDepositEndTime(depositEndTime time.Time)

func (*TextProposal) SetDescription

func (tp *TextProposal) SetDescription(description string)

func (*TextProposal) SetFinalTallyResult

func (tp *TextProposal) SetFinalTallyResult(tallyResult TallyResult)

func (*TextProposal) SetProposalID

func (tp *TextProposal) SetProposalID(proposalID uint64)

func (*TextProposal) SetProposalType

func (tp *TextProposal) SetProposalType(proposalType ProposalKind)

func (*TextProposal) SetStatus

func (tp *TextProposal) SetStatus(status ProposalStatus)

func (*TextProposal) SetSubmitTime

func (tp *TextProposal) SetSubmitTime(submitTime time.Time)

func (*TextProposal) SetTitle

func (tp *TextProposal) SetTitle(title string)

func (*TextProposal) SetTotalDeposit

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

func (*TextProposal) SetVotingEndTime

func (tp *TextProposal) SetVotingEndTime(votingEndTime time.Time)

func (*TextProposal) SetVotingStartTime

func (tp *TextProposal) SetVotingStartTime(votingStartTime time.Time)

func (TextProposal) String

func (tp TextProposal) String() string

type Vote

type Vote struct {
	// 发起治理投票的 地址 (选民)
	Voter sdk.AccAddress `json:"voter"` //  address of the voter
	// 被投票的 提议ID
	ProposalID uint64 `json:"proposal_id"` //  proposalID of the proposal
	// 投票类型
	Option VoteOption `json:"option"` //  option from OptionSet chosen by the voter
}

Vote

func (Vote) Empty

func (v Vote) Empty() bool

Returns whether a vote is empty

func (Vote) Equals

func (v Vote) Equals(comp Vote) bool

Returns whether 2 votes are equal

func (Vote) String

func (v Vote) String() string

type VoteOption

type VoteOption byte

Type that represents VoteOption as a byte 提案的投票类型

const (
	// 空投
	OptionEmpty VoteOption = 0x00
	// 非弃权选民投了 yes
	OptionYes VoteOption = 0x01
	// 弃权
	OptionAbstain VoteOption = 0x02
	// 非弃权选民投了No
	OptionNo VoteOption = 0x03
	// 否决
	OptionNoWithVeto VoteOption = 0x04
)

nolint

func VoteOptionFromString

func VoteOptionFromString(str string) (VoteOption, error)

String to proposalType byte. Returns ff if invalid.

func (VoteOption) Format

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

For Printf / Sprintf, returns bech32 when using %s nolint: errcheck

func (VoteOption) Marshal

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

Marshal needed for protobuf compatibility

func (VoteOption) MarshalJSON

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

Marshals to JSON using string

func (VoteOption) String

func (vo VoteOption) String() string

Turns VoteOption byte to String

func (*VoteOption) Unmarshal

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

Unmarshal needed for protobuf compatibility

func (*VoteOption) UnmarshalJSON

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

Unmarshals from JSON assuming Bech32 encoding

type VoteWithMetadata

type VoteWithMetadata struct {
	ProposalID uint64 `json:"proposal_id"`
	Vote       Vote   `json:"vote"`
}

VoteWithMetadata (just for genesis)

type Votes

type Votes []Vote

Votes is a collection of Vote

func (Votes) String

func (v Votes) String() string

type VotingParams

type VotingParams struct {
	VotingPeriod time.Duration `json:"voting_period"` //  Length of the voting period.
}

Param around Voting in governance

func (VotingParams) String

func (vp VotingParams) String() string

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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