-
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: use proposal for cross chain parameter governance (#110)
- Loading branch information
1 parent
14f91ec
commit 7707c68
Showing
22 changed files
with
864 additions
and
66 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
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,84 @@ | ||
package keeper | ||
|
||
import ( | ||
"encoding/hex" | ||
"math/big" | ||
|
||
"github.com/cosmos/cosmos-sdk/bsc/rlp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
types "github.com/cosmos/cosmos-sdk/x/params/types/proposal" | ||
) | ||
|
||
func (k Keeper) RegisterCrossChainSyncParamsApp() error { | ||
return (*k.crossChainKeeper).RegisterChannel(types.SyncParamsChannel, types.SyncParamsChannelID, k) | ||
} | ||
|
||
func (k Keeper) SyncParams(ctx sdk.Context, p *types.ParameterChangeProposal) error { | ||
// this validates content and size of changes is not empty | ||
if err := p.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
values := make([]byte, 0) | ||
addresses := make([]byte, 0) | ||
|
||
for i, c := range p.Changes { | ||
var value []byte | ||
var err error | ||
if c.Key == types.KeyUpgrade { | ||
value, err = sdk.AccAddressFromHexUnsafe(c.Value) | ||
if err != nil { | ||
return sdkerrors.Wrapf(types.ErrAddressNotValid, "smart contract address is not valid %s", c.Value) | ||
} | ||
} else { | ||
value, err = hex.DecodeString(c.Value) | ||
if err != nil { | ||
return sdkerrors.Wrapf(types.ErrInvalidValue, "value is not valid %s", c.Value) | ||
} | ||
} | ||
values = append(values, value...) | ||
addr, err := sdk.AccAddressFromHexUnsafe(p.Addresses[i]) | ||
if err != nil { | ||
return sdkerrors.Wrapf(types.ErrAddressNotValid, "smart contract address is not valid %s", p.Addresses[i]) | ||
} | ||
addresses = append(addresses, addr.Bytes()...) | ||
} | ||
|
||
pack := types.SyncParamsPackage{ | ||
Key: p.Changes[0].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 | ||
} | ||
|
||
// Need these in order to register paramsKeeper to be a CrosschainApp so that it can register channel(3) | ||
|
||
func (k Keeper) ExecuteSynPackage(ctx sdk.Context, appCtx *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, header *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, header *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
Oops, something went wrong.