Skip to content

Commit

Permalink
Default value of JSON RPC flag in commands (0xPolygon#1939)
Browse files Browse the repository at this point in the history
* Fixed default value of JSON RPC flag in commands

* Added JSON RPC flag value validation in bridge commands
  • Loading branch information
dusan-maksimovic authored Sep 27, 2023
1 parent 4b2770e commit 19687bc
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
25 changes: 25 additions & 0 deletions command/bridge/common/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion command/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
Expand Down
4 changes: 4 additions & 0 deletions command/rootchain/validators/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions command/rootchain/withdraw/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions command/sidechain/rewards/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions command/sidechain/unstaking/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions command/sidechain/withdraw/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 19687bc

Please sign in to comment.