Skip to content

Commit

Permalink
feat: using abi.encode for update param tx
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinlink committed Jun 26, 2023
1 parent 7feb275 commit 77202f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
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"
)

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
}

0 comments on commit 77202f2

Please sign in to comment.