Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: using abi.encode for update param tx #232

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions x/gov/keeper/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions x/gov/types/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
cosinlink marked this conversation as resolved.
Show resolved Hide resolved
)

const (
Expand All @@ -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
}