Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request: add block height control (#93)
Browse files Browse the repository at this point in the history
* add block height control

* disable bank handler

* update

* add 	MILESTONE_MERCURY_HEIGHT

* enhance message

* rename to 	milestoneMercuryHeight       int64

Co-authored-by: aaron <[email protected]>
Co-authored-by: Green <[email protected]>
Co-authored-by: zhongqiuwood <[email protected]>
  • Loading branch information
4 people authored Feb 27, 2021
1 parent b0d9d00 commit d951ae2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ examples/build/*
docs/_build
docs/tutorial
docs/node_modules
dev/testnet
dev/cache
dist
tools-stamp

Expand Down
58 changes: 58 additions & 0 deletions types/milestone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package types

import (
"strconv"
"sync"
)

var (
MILESTONE_MERCURY_HEIGHT string
milestoneMercuryHeight int64
once sync.Once
)

func string2number(input string) int64 {
if len(input) == 0 {
input = "0"
}
res, err := strconv.ParseInt(input, 10, 64)
if err != nil {
panic(err)
}
return res
}

func initVersionBlockHeight() {
once.Do(func() {
milestoneMercuryHeight = string2number(MILESTONE_MERCURY_HEIGHT)
})
}

func init() {
initVersionBlockHeight()
}

//disable transfer tokens to contract address by cli
func higherThanMercury(height int64) bool {
if milestoneMercuryHeight == 0 {
// milestoneMercuryHeight not enabled
return false
}
return height > milestoneMercuryHeight
}


//disable transfer tokens to contract address by cli
func IsDisableTransferToContractBlock(height int64) bool {
return higherThanMercury(height)
}

//disable change the param EvmDenom by proposal
func IsDisableChangeEvmDenomByProposal(height int64) bool {
return higherThanMercury(height)
}

//disable transfer tokens by module of cosmos-sdk/bank
func IsDisableBankTransferBlock(height int64) bool {
return higherThanMercury(height)
}
5 changes: 5 additions & 0 deletions x/bank/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
// NewHandler returns a handler for "bank" type messages.
func NewHandler(k keeper.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {

if sdk.IsDisableBankTransferBlock(ctx.BlockHeight()) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "bank message is disabled")
}

ctx = ctx.WithEventManager(sdk.NewEventManager())

switch msg := msg.(type) {
Expand Down

0 comments on commit d951ae2

Please sign in to comment.