Skip to content

Commit

Permalink
add store-block-list cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed May 2, 2024
1 parent 6366747 commit 0553bd4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
40 changes: 40 additions & 0 deletions x/cronos/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cli
import (
"encoding/json"
"fmt"
"io"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -46,6 +48,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdUpdateTokenMapping())
cmd.AddCommand(CmdTurnBridge())
cmd.AddCommand(CmdUpdatePermissions())
cmd.AddCommand(CmdStoreBlockList())
cmd.AddCommand(MigrateGenesisCmd())
return cmd
}
Expand Down Expand Up @@ -319,6 +322,43 @@ func CmdUpdatePermissions() *cobra.Command {
return cmd
}

// CmdStoreBlockList returns a CLI command handler for updating cronos permissions
func CmdStoreBlockList() *cobra.Command {
cmd := &cobra.Command{
Use: "store-block-list [encrypted-block-list-file]",
Short: "Store encrypted block list",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

fp, err := os.Open(args[0])
if err != nil {
return err
}
defer fp.Close()

// Read the file
blob, err := io.ReadAll(fp)
if err != nil {
return err
}

msg := types.NewMsgStoreBlockList(clientCtx.GetFromAddress().String(), blob)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

type ExportEvmGenesisState struct {
evmtypes.GenesisState
Params ExportEvmParams `json:"params"`
Expand Down
25 changes: 25 additions & 0 deletions x/cronos/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
_ sdk.Msg = &MsgUpdateParams{}
_ sdk.Msg = &MsgTurnBridge{}
_ sdk.Msg = &MsgUpdatePermissions{}
_ sdk.Msg = &MsgStoreBlockList{}
)

func NewMsgConvertVouchers(address string, coins sdk.Coins) *MsgConvertVouchers {
Expand Down Expand Up @@ -318,3 +319,27 @@ func (msg *MsgUpdatePermissions) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func NewMsgStoreBlockList(from string, blob []byte) *MsgStoreBlockList {
return &MsgStoreBlockList{
From: from,
Blob: blob,
}
}

func (msg *MsgStoreBlockList) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.From)
if err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err)
}
return nil
}

func (msg *MsgStoreBlockList) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.From)
if err != nil {
panic(err)
}

return []sdk.AccAddress{addr}
}

0 comments on commit 0553bd4

Please sign in to comment.