diff --git a/command/bridge/common/params.go b/command/bridge/common/params.go index 53f4657bde..3595044031 100644 --- a/command/bridge/common/params.go +++ b/command/bridge/common/params.go @@ -86,6 +86,19 @@ func (p *BridgeParams) RegisterCommonFlags(cmd *cobra.Command) { ) } +func (p *BridgeParams) Validate() error { + if p == nil { + return nil + } + + _, err := cmdHelper.ParseJSONRPCAddress(p.JSONRPCAddr) + if err != nil { + return fmt.Errorf("failed to parse json rpc address. Error: %w", err) + } + + return nil +} + type ERC20BridgeParams struct { *BridgeParams Amounts []string @@ -96,6 +109,10 @@ func NewERC20BridgeParams() *ERC20BridgeParams { } func (bp *ERC20BridgeParams) Validate() error { + if err := bp.BridgeParams.Validate(); err != nil { + return err + } + if len(bp.Receivers) != len(bp.Amounts) { return errInconsistentAmounts } @@ -113,6 +130,10 @@ func NewERC721BridgeParams() *ERC721BridgeParams { } func (bp *ERC721BridgeParams) Validate() error { + if err := bp.BridgeParams.Validate(); err != nil { + return err + } + if len(bp.Receivers) != len(bp.TokenIDs) { return errInconsistentTokenIds } @@ -131,6 +152,10 @@ func NewERC1155BridgeParams() *ERC1155BridgeParams { } func (bp *ERC1155BridgeParams) Validate() error { + if err := bp.BridgeParams.Validate(); err != nil { + return err + } + if len(bp.Receivers) != len(bp.Amounts) { return errInconsistentAmounts } diff --git a/command/helper/helper.go b/command/helper/helper.go index 2fe0647421..b934dbd2d4 100644 --- a/command/helper/helper.go +++ b/command/helper/helper.go @@ -209,7 +209,7 @@ func ParseGRPCAddress(grpcAddress string) (*net.TCPAddr, error) { func RegisterJSONRPCFlag(cmd *cobra.Command) { cmd.PersistentFlags().String( command.JSONRPCFlag, - fmt.Sprintf("%s:%d", AllInterfacesBinding, server.DefaultJSONRPCPort), + fmt.Sprintf("http://%s:%d", AllInterfacesBinding, server.DefaultJSONRPCPort), "the JSON-RPC interface", ) } diff --git a/command/rootchain/validators/params.go b/command/rootchain/validators/params.go index 6a5f1f7bfc..1b51d00034 100644 --- a/command/rootchain/validators/params.go +++ b/command/rootchain/validators/params.go @@ -18,6 +18,10 @@ type validatorInfoParams struct { } func (v *validatorInfoParams) validateFlags() error { + if _, err := helper.ParseJSONRPCAddress(v.jsonRPC); err != nil { + return fmt.Errorf("failed to parse json rpc address. Error: %w", err) + } + return sidechainHelper.ValidateSecretFlags(v.accountDir, v.accountConfig) } diff --git a/command/rootchain/withdraw/params.go b/command/rootchain/withdraw/params.go index dc60a8f674..33fc7734a7 100644 --- a/command/rootchain/withdraw/params.go +++ b/command/rootchain/withdraw/params.go @@ -29,6 +29,10 @@ func (v *withdrawParams) validateFlags() (err error) { return err } + if _, err = helper.ParseJSONRPCAddress(v.jsonRPC); err != nil { + return fmt.Errorf("failed to parse json rpc address. Error: %w", err) + } + return sidechainHelper.ValidateSecretFlags(v.accountDir, v.accountConfig) } diff --git a/command/sidechain/rewards/params.go b/command/sidechain/rewards/params.go index fcb60203a3..7b9db61523 100644 --- a/command/sidechain/rewards/params.go +++ b/command/sidechain/rewards/params.go @@ -20,6 +20,10 @@ type withdrawRewardResult struct { } func (w *withdrawRewardsParams) validateFlags() error { + if _, err := helper.ParseJSONRPCAddress(w.jsonRPC); err != nil { + return fmt.Errorf("failed to parse json rpc address. Error: %w", err) + } + return sidechainHelper.ValidateSecretFlags(w.accountDir, w.accountConfig) } diff --git a/command/sidechain/unstaking/params.go b/command/sidechain/unstaking/params.go index a0a6736a5f..4fa6cd9a15 100644 --- a/command/sidechain/unstaking/params.go +++ b/command/sidechain/unstaking/params.go @@ -27,6 +27,10 @@ func (v *unstakeParams) validateFlags() (err error) { return err } + if _, err = helper.ParseJSONRPCAddress(v.jsonRPC); err != nil { + return fmt.Errorf("failed to parse json rpc address. Error: %w", err) + } + return sidechainHelper.ValidateSecretFlags(v.accountDir, v.accountConfig) } diff --git a/command/sidechain/withdraw/params.go b/command/sidechain/withdraw/params.go index 2f41e1ab8b..0f10bf1532 100644 --- a/command/sidechain/withdraw/params.go +++ b/command/sidechain/withdraw/params.go @@ -16,6 +16,10 @@ type withdrawParams struct { } func (w *withdrawParams) validateFlags() error { + if _, err := helper.ParseJSONRPCAddress(w.jsonRPC); err != nil { + return fmt.Errorf("failed to parse json rpc address. Error: %w", err) + } + return sidechainHelper.ValidateSecretFlags(w.accountDir, w.accountConfig) }