Skip to content

Commit

Permalink
Merge pull request #72 from binance-chain/release/0.25.0-binance.6
Browse files Browse the repository at this point in the history
Release/0.25.0 binance.6
  • Loading branch information
yutianwu authored Feb 25, 2019
2 parents 8d34b82 + 7166963 commit 0f6803a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 6 deletions.
1 change: 1 addition & 0 deletions store/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type (
Store = types.Store
Committer = types.Committer
CommitStore = types.CommitStore
TreeStore = types.TreeStore
MultiStore = types.MultiStore
CacheMultiStore = types.CacheMultiStore
CommitMultiStore = types.CommitMultiStore
Expand Down
4 changes: 4 additions & 0 deletions store/iavlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func newIAVLStore(tree *iavl.MutableTree, numRecent int64, storeEvery int64) *ia
return st
}

func (st *iavlStore) GetImmutableTree() *iavl.ImmutableTree {
return st.tree.ImmutableTree
}

// Implements Committer.
func (st *iavlStore) Commit() CommitID {
// Save a new version.
Expand Down
5 changes: 5 additions & 0 deletions types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"

"github.com/tendermint/iavl"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
Expand Down Expand Up @@ -43,6 +44,10 @@ type CommitStore interface {
Store
}

type TreeStore interface {
GetImmutableTree() *iavl.ImmutableTree
}

// Queryable allows a Store to expose internal state to the abci.Query
// interface. Multistore can route requests to the proper Store.
//
Expand Down
20 changes: 14 additions & 6 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command {
// GetCmdQueryProposal implements the query proposal command.
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "proposal",
Use: "query-proposal",
Short: "Query details of a single proposal",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
Expand Down Expand Up @@ -290,7 +290,7 @@ func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
// GetCmdQueryProposals implements a query proposals command.
func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "proposals",
Use: "query-proposals",
Short: "Query proposals with optional filters",
RunE: func(cmd *cobra.Command, args []string) error {
bechDepositerAddr := viper.GetString(flagDepositer)
Expand Down Expand Up @@ -369,7 +369,7 @@ func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
// GetCmdQueryVote implements the query proposal vote command.
func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "vote",
Use: "query-vote",
Short: "Query details of a single vote",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
Expand Down Expand Up @@ -408,7 +408,7 @@ func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command {
// GetCmdQueryVotes implements the command to query for proposal votes.
func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "votes",
Use: "query-votes",
Short: "Query votes on a proposal",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
Expand Down Expand Up @@ -441,7 +441,7 @@ func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
// GetCmdQueryDeposit implements the query proposal deposit command.
func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "deposit",
Use: "query-deposit",
Short: "Query details of a deposit",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
Expand Down Expand Up @@ -480,7 +480,7 @@ func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
// GetCmdQueryDeposits implements the command to query for proposal deposits.
func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "deposits",
Use: "query-deposits",
Short: "Query deposits on a proposal",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
Expand Down Expand Up @@ -560,6 +560,14 @@ func GetCmdSubmitListProposal(cdc *codec.Codec) *cobra.Command {
initPrice := viper.GetInt64(flagInitPrice)
expireTimestamp := viper.GetInt64(flagExpireTime)

if tradeAsset == "" {
return errors.New("base asset should not be empty")
}

if quoteAsset == "" {
return errors.New("quote asset should not be empty")
}

if initPrice <= 0 {
return errors.New("init price should greater than 0")
}
Expand Down
5 changes: 5 additions & 0 deletions x/gov/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ const (
CodeInvalidVote sdk.CodeType = 9
CodeInvalidGenesis sdk.CodeType = 10
CodeInvalidProposalStatus sdk.CodeType = 11
CodeInvalidProposal sdk.CodeType = 12
)

//----------------------------------------
// Error constructors

func ErrInvalidProposal(codespace sdk.CodespaceType, msg string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidProposal, fmt.Sprintf("Invalid proposal: %s", msg))
}

func ErrUnknownProposal(codespace sdk.CodespaceType, proposalID int64) sdk.Error {
return sdk.NewError(codespace, CodeUnknownProposal, fmt.Sprintf("Unknown proposal with id %d", proposalID))
}
Expand Down
6 changes: 6 additions & 0 deletions x/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func NewHandler(keeper Keeper) sdk.Handler {
func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitProposal) sdk.Result {

proposal := keeper.NewTextProposal(ctx, msg.Title, msg.Description, msg.ProposalType)

hooksErr := keeper.OnProposalSubmitted(ctx, proposal)
if hooksErr != nil {
return ErrInvalidProposal(keeper.codespace, hooksErr.Error()).Result()
}

proposalID := proposal.GetProposalID()
proposalIDBytes := []byte(fmt.Sprintf("%d", proposalID))

Expand Down
21 changes: 21 additions & 0 deletions x/gov/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gov

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// event hooks for governance
type GovHooks interface {
OnProposalSubmitted(ctx sdk.Context, proposal Proposal) error // Must be called when a proposal submitted
}

func (keeper Keeper) OnProposalSubmitted(ctx sdk.Context, proposal Proposal) error {
hs := keeper.hooks[proposal.GetProposalType()]
for _, hooks := range hs {
err := hooks.OnProposalSubmitted(ctx, proposal)
if err != nil {
return err
}
}
return nil
}
16 changes: 16 additions & 0 deletions x/gov/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gov

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
Expand Down Expand Up @@ -52,6 +53,9 @@ type Keeper struct {
// The codec codec for binary encoding/decoding.
cdc *codec.Codec

// Hooks registered
hooks map[ProposalKind][]GovHooks

// Reserved codespace
codespace sdk.CodespaceType

Expand All @@ -71,13 +75,25 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, paramsKeeper params.Keeper, p
paramSpace: paramSpace.WithTypeTable(ParamTypeTable()),
ck: ck,
ds: ds,
hooks: make(map[ProposalKind][]GovHooks),
vs: ds.GetValidatorSet(),
cdc: cdc,
codespace: codespace,
pool: pool,
}
}

// AddHooks add hooks for gov keeper
func (keeper Keeper) AddHooks(proposalType ProposalKind, hooks GovHooks) Keeper {
hs := keeper.hooks[proposalType]
if hs == nil {
hs = make([]GovHooks, 0, 0)
}
hs = append(hs, hooks)
keeper.hooks[proposalType] = hs
return keeper
}

// =====================================================
// Proposals

Expand Down

0 comments on commit 0f6803a

Please sign in to comment.