-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update crosschain gov v0.47 (#171)
- Loading branch information
1 parent
e801e09
commit c324261
Showing
29 changed files
with
1,289 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package keeper | ||
|
||
import ( | ||
"encoding/hex" | ||
"math/big" | ||
|
||
sdkerrors "cosmossdk.io/errors" | ||
"github.com/cosmos/cosmos-sdk/bsc/rlp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
) | ||
|
||
func (k Keeper) RegisterCrossChainSyncParamsApp() error { | ||
return k.crossChainKeeper.RegisterChannel(types.SyncParamsChannel, types.SyncParamsChannelID, k) | ||
} | ||
|
||
func (k Keeper) SyncParams(ctx sdk.Context, cpc govv1.CrossChainParamsChange) error { | ||
if err := cpc.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
values := make([]byte, 0) | ||
addresses := make([]byte, 0) | ||
|
||
for i, v := range cpc.Values { | ||
var value []byte | ||
var err error | ||
if cpc.Key == types.KeyUpgrade { | ||
value = sdk.MustAccAddressFromHex(v) | ||
} else { | ||
value, err = hex.DecodeString(v) | ||
if err != nil { | ||
return sdkerrors.Wrapf(types.ErrInvalidValue, "value is not valid %s", v) | ||
} | ||
} | ||
values = append(values, value...) | ||
addr := sdk.MustAccAddressFromHex(cpc.Targets[i]) | ||
addresses = append(addresses, addr.Bytes()...) | ||
} | ||
|
||
pack := types.SyncParamsPackage{ | ||
Key: cpc.Key, | ||
Value: values, | ||
Target: addresses, | ||
} | ||
|
||
encodedPackage, err := rlp.EncodeToBytes(pack) | ||
if err != nil { | ||
return sdkerrors.Wrapf(types.ErrInvalidUpgradeProposal, "encode sync params package error") | ||
} | ||
_, err = k.crossChainKeeper.CreateRawIBCPackageWithFee( | ||
ctx, | ||
types.SyncParamsChannelID, | ||
sdk.SynCrossChainPackageType, | ||
encodedPackage, | ||
big.NewInt(0), | ||
big.NewInt(0), | ||
) | ||
return err | ||
} | ||
|
||
func (k Keeper) ExecuteSynPackage(ctx sdk.Context, _ *sdk.CrossChainAppContext, payload []byte) sdk.ExecuteResult { | ||
k.Logger(ctx).Error("received sync params sync package", "payload", hex.EncodeToString(payload)) | ||
return sdk.ExecuteResult{} | ||
} | ||
|
||
func (k Keeper) ExecuteAckPackage(ctx sdk.Context, _ *sdk.CrossChainAppContext, payload []byte) sdk.ExecuteResult { | ||
k.Logger(ctx).Error("received sync params in ack package", "payload", hex.EncodeToString(payload)) | ||
return sdk.ExecuteResult{} | ||
} | ||
|
||
func (k Keeper) ExecuteFailAckPackage(ctx sdk.Context, _ *sdk.CrossChainAppContext, payload []byte) sdk.ExecuteResult { | ||
k.Logger(ctx).Error("received sync params fail ack package", "payload", hex.EncodeToString(payload)) | ||
return sdk.ExecuteResult{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.