Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Nov 16, 2023
1 parent a735cbc commit 82ea9a8
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ require (

replace (
github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0
github.com/cosmos/cosmos-sdk => github.com/j75689/bnc-cosmos-sdk v0.0.0-20230828031047-de8de0dae3cf //github.com/bnb-chain/bnc-cosmos-sdk v0.26.6
github.com/cosmos/cosmos-sdk => github.com/j75689/bnc-cosmos-sdk v0.0.0-20231116015058-f4c4b6cf4304 //github.com/bnb-chain/bnc-cosmos-sdk v0.26.6
github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,8 @@ github.com/iris-contrib/jade v1.1.4/go.mod h1:EDqR+ur9piDl6DUgs6qRrlfzmlx/D5Uybo
github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0GqwkjqxNd0u65g=
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
github.com/iris-contrib/schema v0.0.6/go.mod h1:iYszG0IOsuIsfzjymw1kMzTL8YQcCWlm65f3wX8J5iA=
github.com/j75689/bnc-cosmos-sdk v0.0.0-20230828031047-de8de0dae3cf h1:V7pDFgJSxT0EBqD0ZNB6tJjey1YatkVwkxhmYboCN3Q=
github.com/j75689/bnc-cosmos-sdk v0.0.0-20230828031047-de8de0dae3cf/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q=
github.com/j75689/bnc-cosmos-sdk v0.0.0-20231116015058-f4c4b6cf4304 h1:pRwSJU1SnmKNmpK8yIdTEoeny2MbKoQPvmvoY/BUaA8=
github.com/j75689/bnc-cosmos-sdk v0.0.0-20231116015058-f4c4b6cf4304/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
Expand Down
3 changes: 0 additions & 3 deletions plugins/bridge/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ func NewHandler(keeper Keeper) sdk.Handler {
}

func handleUnbindMsg(ctx sdk.Context, keeper Keeper, msg UnbindMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
// check is native symbol
if msg.Symbol == cmmtypes.NativeTokenSymbol {
return types.ErrInvalidSymbol("can not unbind native symbol").Result()
Expand Down
5 changes: 4 additions & 1 deletion plugins/tokens/freeze/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func NewHandler(tokenMapper store.Mapper, accKeeper auth.AccountKeeper, keeper b
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case FreezeMsg:
if sdk.IsUpgrade(sdk.BCFusionFirstHardFork) {
return sdk.ErrMsgNotSupported("").Result()
}
return handleFreezeToken(ctx, tokenMapper, accKeeper, keeper, msg)
case UnfreezeMsg:
return handleUnfreezeToken(ctx, tokenMapper, accKeeper, keeper, msg)
Expand All @@ -30,7 +33,7 @@ func NewHandler(tokenMapper store.Mapper, accKeeper auth.AccountKeeper, keeper b
}

func handleFreezeToken(ctx sdk.Context, tokenMapper store.Mapper, accKeeper auth.AccountKeeper, keeper bank.Keeper, msg FreezeMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
if sdk.IsUpgrade(sdk.BCFusionFirstHardFork) {
return sdk.ErrMsgNotSupported("").Result()
}
freezeAmount := msg.Amount
Expand Down
9 changes: 3 additions & 6 deletions plugins/tokens/issue/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
// NewHandler creates a new token issue message handler
func NewHandler(tokenMapper store.Mapper, keeper bank.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
if sdk.IsUpgrade(sdk.BCFusionFirstHardFork) {
return sdk.ErrMsgNotSupported("").Result()
}
switch msg := msg.(type) {
case IssueMsg:
return handleIssueToken(ctx, tokenMapper, keeper, msg)
Expand All @@ -38,9 +41,6 @@ func NewHandler(tokenMapper store.Mapper, keeper bank.Keeper) sdk.Handler {
}

func handleIssueToken(ctx sdk.Context, tokenMapper store.Mapper, bankKeeper bank.Keeper, msg IssueMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
errLogMsg := "issue token failed"
symbol := strings.ToUpper(msg.Symbol)
logger := log.With("module", "token", "symbol", symbol, "name", msg.Name, "total_supply", msg.TotalSupply, "issuer", msg.From)
Expand All @@ -67,9 +67,6 @@ func handleIssueToken(ctx sdk.Context, tokenMapper store.Mapper, bankKeeper bank

// Mint MiniToken is also handled by this function
func handleMintToken(ctx sdk.Context, tokenMapper store.Mapper, bankKeeper bank.Keeper, msg MintMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
symbol := strings.ToUpper(msg.Symbol)
logger := log.With("module", "token", "symbol", symbol, "amount", msg.Amount, "minter", msg.From)

Expand Down
6 changes: 0 additions & 6 deletions plugins/tokens/issue/handler_mini.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import (
)

func handleIssueMiniToken(ctx sdk.Context, tokenMapper store.Mapper, bankKeeper bank.Keeper, msg IssueMiniMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
errLogMsg := "issue miniToken failed"
origSymbol := strings.ToUpper(msg.Symbol)
logger := log.With("module", "mini-token", "symbol", origSymbol, "name", msg.Name, "total_supply", msg.TotalSupply, "issuer", msg.From)
Expand All @@ -37,9 +34,6 @@ func handleIssueMiniToken(ctx sdk.Context, tokenMapper store.Mapper, bankKeeper
}

func handleIssueTinyToken(ctx sdk.Context, tokenMapper store.Mapper, bankKeeper bank.Keeper, msg IssueTinyMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
errLogMsg := "issue tinyToken failed"
origSymbol := strings.ToUpper(msg.Symbol)
logger := log.With("module", "mini-token", "symbol", origSymbol, "name", msg.Name, "total_supply", msg.TotalSupply, "issuer", msg.From)
Expand Down
3 changes: 3 additions & 0 deletions plugins/tokens/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const (
)

func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap.Keeper) {
if !sdk.IsUpgrade(sdk.BCFusionSecondHardFork) {
return
}
logger := bnclog.With("module", "tokens")
logger.Info("unlock the time locks", "blockHeight", ctx.BlockHeight())

Expand Down
12 changes: 6 additions & 6 deletions plugins/tokens/swap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ func NewHandler(kp Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case HTLTMsg:
if sdk.IsUpgrade(sdk.BCFusionFirstHardFork) {
return sdk.ErrMsgNotSupported("").Result()
}
return handleHashTimerLockedTransfer(ctx, kp, msg)
case DepositHTLTMsg:
if sdk.IsUpgrade(sdk.BCFusionFirstHardFork) {
return sdk.ErrMsgNotSupported("").Result()
}
return handleDepositHashTimerLockedTransfer(ctx, kp, msg)
case ClaimHTLTMsg:
return handleClaimHashTimerLockedTransfer(ctx, kp, msg)
Expand All @@ -27,9 +33,6 @@ func NewHandler(kp Keeper) sdk.Handler {
}

func handleHashTimerLockedTransfer(ctx sdk.Context, kp Keeper, msg HTLTMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
header := ctx.BlockHeader()
blockTime := header.Time.Unix()
if msg.Timestamp < blockTime-ThirtyMinutes || msg.Timestamp > blockTime+FifteenMinutes {
Expand Down Expand Up @@ -69,9 +72,6 @@ func handleHashTimerLockedTransfer(ctx sdk.Context, kp Keeper, msg HTLTMsg) sdk.
}

func handleDepositHashTimerLockedTransfer(ctx sdk.Context, kp Keeper, msg DepositHTLTMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
swap := kp.GetSwap(ctx, msg.SwapID)
if swap == nil {
return ErrNonExistSwapID(fmt.Sprintf("No matched swap with swapID %v", msg.SwapID)).Result()
Expand Down
12 changes: 6 additions & 6 deletions plugins/tokens/timelock/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ func NewHandler(keeper Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case TimeLockMsg:
if sdk.IsUpgrade(sdk.BCFusionFirstHardFork) {
return sdk.ErrMsgNotSupported("").Result()
}
return handleTimeLock(ctx, keeper, msg)
case TimeUnlockMsg:
return handleTimeUnlock(ctx, keeper, msg)
case TimeRelockMsg:
if sdk.IsUpgrade(sdk.BCFusionFirstHardFork) {
return sdk.ErrMsgNotSupported("").Result()
}
return handleTimeRelock(ctx, keeper, msg)
default:
errMsg := fmt.Sprintf("unrecognized time lock message type: %T", msg)
Expand All @@ -24,9 +30,6 @@ func NewHandler(keeper Keeper) sdk.Handler {
}

func handleTimeLock(ctx sdk.Context, keeper Keeper, msg TimeLockMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
record, err := keeper.TimeLock(ctx, msg.From, msg.Description, msg.Amount, time.Unix(msg.LockTime, 0))
if err != nil {
return err.Result()
Expand All @@ -39,9 +42,6 @@ func handleTimeLock(ctx sdk.Context, keeper Keeper, msg TimeLockMsg) sdk.Result
}

func handleTimeRelock(ctx sdk.Context, keeper Keeper, msg TimeRelockMsg) sdk.Result {
if sdk.IsUpgrade(sdk.BEPXXX) {
return sdk.ErrMsgNotSupported("").Result()
}
newRecord := TimeLockRecord{
Description: msg.Description,
Amount: msg.Amount,
Expand Down

0 comments on commit 82ea9a8

Please sign in to comment.