From 2881155b298f28d3a5a9c55379534bd4a59722fc Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 6 Jul 2023 10:55:49 +0800 Subject: [PATCH] feat: using abi.encode for update param tx (#232) Co-authored-by: randyahx <62416962+randyahx@users.noreply.github.com> --- x/gov/keeper/crosschain.go | 9 +++------ x/gov/types/crosschain.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/x/gov/keeper/crosschain.go b/x/gov/keeper/crosschain.go index 7f514e6ec5..f245387a23 100644 --- a/x/gov/keeper/crosschain.go +++ b/x/gov/keeper/crosschain.go @@ -5,7 +5,6 @@ import ( "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" @@ -44,11 +43,9 @@ func (k Keeper) SyncParams(ctx sdk.Context, cpc govv1.CrossChainParamsChange) er Target: addresses, } - encodedPackage, err := rlp.EncodeToBytes(pack) - if err != nil { - return sdkerrors.Wrapf(types.ErrInvalidUpgradeProposal, "encode sync params package error") - } - _, err = k.crossChainKeeper.CreateRawIBCPackageWithFee( + encodedPackage := pack.MustSerialize() + + _, err := k.crossChainKeeper.CreateRawIBCPackageWithFee( ctx, types.SyncParamsChannelID, sdk.SynCrossChainPackageType, diff --git a/x/gov/types/crosschain.go b/x/gov/types/crosschain.go index 7c33fb8ff2..b2a7c29261 100644 --- a/x/gov/types/crosschain.go +++ b/x/gov/types/crosschain.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/accounts/abi" ) const ( @@ -19,3 +20,23 @@ type SyncParamsPackage struct { // Target is the smart contract address(es) Target []byte } + +var ( + syncParamsPackageType, _ = abi.NewType("tuple", "", []abi.ArgumentMarshaling{ + {Name: "Key", Type: "string"}, + {Name: "Value", Type: "bytes"}, + {Name: "Target", Type: "bytes"}, + }) + + syncParamsPackageArgs = abi.Arguments{ + {Type: syncParamsPackageType}, + } +) + +func (p SyncParamsPackage) MustSerialize() []byte { + encodedBytes, err := syncParamsPackageArgs.Pack(&p) + if err != nil { + panic("encode params change sync package error") + } + return encodedBytes +}