Skip to content
Draft
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
879506c
chore: remove flag_loader
minhd-vu Oct 3, 2025
4a835f5
fix: revert ecrecover
minhd-vu Oct 3, 2025
d144bba
fix: more flags
minhd-vu Oct 3, 2025
3c6a40d
Merge branch 'main' into minhd-vu/flag-loader
minhd-vu Oct 3, 2025
4e62514
feat: flag package
minhd-vu Oct 3, 2025
97fcfc5
fix: lint
minhd-vu Oct 3, 2025
68662d8
fix: fmt cdk.go
minhd-vu Oct 3, 2025
f627a6a
fix: rename flag names
minhd-vu Oct 3, 2025
365447f
fix: remove rpc check
minhd-vu Oct 3, 2025
1b48141
fix: typo
minhd-vu Oct 3, 2025
a6f712c
fix: remove as required if there is a default
minhd-vu Oct 3, 2025
503a67f
fix: use helper functions
minhd-vu Oct 3, 2025
8eac7c4
fix: remove fatalIfError
minhd-vu Oct 3, 2025
2375c5a
fix: missing import
minhd-vu Oct 3, 2025
d033c59
fix: metricsToDash
minhd-vu Oct 3, 2025
694be37
chore: refactor flag_loader
minhd-vu Oct 6, 2025
91c3fd5
chore: mark some stuff
minhd-vu Oct 6, 2025
de18bb0
fix: ecrecover
minhd-vu Oct 6, 2025
1a39a24
fix: fixnoncegap
minhd-vu Oct 6, 2025
31a4107
fix: mark flag required
minhd-vu Oct 6, 2025
d8366cf
fix: validate url
minhd-vu Oct 6, 2025
b6035c3
fix: ulxly
minhd-vu Oct 6, 2025
cf1a273
Merge branch 'main' into minhd-vu/flag-loader
minhd-vu Oct 6, 2025
27b050d
fix: merge
minhd-vu Oct 6, 2025
ee1a753
docs: make gen-doc
minhd-vu Oct 6, 2025
98c6a7f
fix: don't bind env
minhd-vu Oct 6, 2025
c2ec610
chore: order root imports
minhd-vu Oct 6, 2025
b2c9c28
docs: cdk
minhd-vu Oct 6, 2025
fa21fc3
fix: docs
minhd-vu Oct 6, 2025
31c9b1b
fix: monitor prerun
minhd-vu Oct 6, 2025
d95ff47
Merge branch 'main' into minhd-vu/flag-loader
minhd-vu Oct 6, 2025
8f1aa40
docs: make gen-doc
minhd-vu Oct 6, 2025
2a5db56
Merge branch 'main' into minhd-vu/flag-loader
minhd-vu Oct 6, 2025
8269906
Merge branch 'main' into minhd-vu/flag-loader
minhd-vu Oct 7, 2025
bce58b2
fix: make rpc fuzz required
minhd-vu Oct 7, 2025
e909947
chore: rename marking flags funcs
minhd-vu Oct 7, 2025
8416aad
Merge branch 'main' into minhd-vu/flag-loader
minhd-vu Oct 7, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
sudo apt-get install ethereum
geth --version
fi
- name: Run loadtest againt ${{ matrix.tool }}
- name: Run loadtest against ${{ matrix.tool }}
run: |
${{ matrix.tool }} --version
make ${{ matrix.tool }} &
Expand Down
15 changes: 7 additions & 8 deletions cmd/cdk/cdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strings"
"time"

"github.com/0xPolygon/polygon-cli/cmd/flag_loader"
"github.com/0xPolygon/polygon-cli/custommarshaller"
"github.com/0xPolygon/polygon-cli/flag"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -44,7 +44,6 @@ import (
)

const (
ArgRpcURL = "rpc-url"
ArgForkID = "fork-id"

ArgRollupManagerAddress = "rollup-manager-address"
Expand All @@ -55,7 +54,6 @@ const (
ArgBridgeAddress = "bridge-address"
ArgGERAddress = "ger-address"

defaultRPCURL = "http://localhost:8545"
defaultForkId = "12"

// forks
Expand Down Expand Up @@ -106,11 +104,12 @@ var CDKCmd = &cobra.Command{
Use: "cdk",
Short: "Utilities for interacting with CDK networks.",
Long: "Basic utility commands for interacting with the cdk contracts.",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
rpcURL := flag_loader.GetRpcUrlFlagValue(cmd)
if rpcURL != nil {
cdkInputArgs.rpcURL = *rpcURL
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
cdkInputArgs.rpcURL, err = flag.GetRPCURL(cmd)
if err != nil {
return err
}
return nil
},
Args: cobra.NoArgs,
}
Expand Down Expand Up @@ -636,7 +635,7 @@ func mustPrintLogs(logs []types.Log, contractInstance reflect.Value, contractABI
func init() {
// cdk
f := CDKCmd.PersistentFlags()
f.StringVar(&cdkInputArgs.rpcURL, ArgRpcURL, defaultRPCURL, "RPC URL of network containing CDK contracts")
f.StringVar(&cdkInputArgs.rpcURL, flag.RPCURL, flag.DefaultRPCURL, "RPC URL of network containing CDK contracts")
f.StringVar(&cdkInputArgs.forkID, ArgForkID, defaultForkId, "fork ID of CDK networks")
f.StringVar(&cdkInputArgs.rollupManagerAddress, ArgRollupManagerAddress, "", "address of rollup contract")

Expand Down
20 changes: 10 additions & 10 deletions cmd/contract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"math/big"
"strings"

"github.com/0xPolygon/polygon-cli/cmd/flag_loader"
"github.com/0xPolygon/polygon-cli/flag"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -17,9 +17,7 @@ import (
)

const (
ArgRpcURL = "rpc-url"
ArgAddress = "address"
defaultRPCURL = "http://localhost:8545"
ArgAddress = "address"
)

var (
Expand All @@ -45,9 +43,12 @@ var Cmd = &cobra.Command{
Use: "contract",
Short: "Interact with smart contracts and fetch contract information from the blockchain.",
Long: usage,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
rpcURL := flag_loader.GetRpcUrlFlagValue(cmd)
inputArgs.rpcURL = *rpcURL
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
inputArgs.rpcURL, err = flag.GetRPCURL(cmd)
if err != nil {
return err
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return contract(cmd)
Expand Down Expand Up @@ -170,8 +171,7 @@ func fetchContractCreationTx(ctx context.Context, client *ethclient.Client, cont

func init() {
f := Cmd.Flags()
f.StringVar(&inputArgs.rpcURL, ArgRpcURL, defaultRPCURL, "RPC URL of network containing contract")
f.StringVar(&inputArgs.rpcURL, flag.RPCURL, flag.DefaultRPCURL, "RPC URL of network containing contract")
f.StringVar(&inputArgs.address, ArgAddress, "", "contract address")

_ = Cmd.MarkFlagRequired(ArgAddress)
flag.MarkFlagRequired(Cmd, ArgAddress)
}
25 changes: 8 additions & 17 deletions cmd/dumpblocks/dumpblocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

_ "embed"

"github.com/0xPolygon/polygon-cli/cmd/flag_loader"
"github.com/0xPolygon/polygon-cli/flag"
"github.com/0xPolygon/polygon-cli/proto/gen/pb"
"github.com/0xPolygon/polygon-cli/rpctypes"
"github.com/0xPolygon/polygon-cli/util"
Expand Down Expand Up @@ -55,12 +55,12 @@ var DumpblocksCmd = &cobra.Command{
Use: "dumpblocks start end",
Short: "Export a range of blocks from a JSON-RPC endpoint.",
Long: usage,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
rpcUrlFlagValue := flag_loader.GetRpcUrlFlagValue(cmd)
inputDumpblocks.RpcUrl = *rpcUrlFlagValue
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return checkFlags()
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
inputDumpblocks.RpcUrl, err = flag.GetRPCURL(cmd)
if err != nil {
return err
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down Expand Up @@ -186,7 +186,7 @@ var DumpblocksCmd = &cobra.Command{

func init() {
f := DumpblocksCmd.Flags()
f.StringVarP(&inputDumpblocks.RpcUrl, "rpc-url", "r", "http://localhost:8545", "the RPC endpoint URL")
f.StringVarP(&inputDumpblocks.RpcUrl, flag.RPCURL, "r", flag.DefaultRPCURL, "the RPC endpoint URL")
f.UintVarP(&inputDumpblocks.Threads, "concurrency", "c", 1, "how many go routines to leverage")
f.BoolVarP(&inputDumpblocks.ShouldDumpBlocks, "dump-blocks", "B", true, "dump blocks to output")
f.BoolVar(&inputDumpblocks.ShouldDumpReceipts, "dump-receipts", true, "dump receipts to output")
Expand All @@ -196,15 +196,6 @@ func init() {
f.StringVarP(&inputDumpblocks.FilterStr, "filter", "F", "{}", "filter output based on tx to and from (not setting a filter means all are allowed)")
}

func checkFlags() error {
// Check rpc url flag.
if err := util.ValidateUrl(inputDumpblocks.RpcUrl); err != nil {
return err
}

return nil
}

// writeResponses writes the data to either stdout or a file if one is provided.
// The message type can be either "block" or "transaction". The format of the
// output is either "json" or "proto" depending on the mode.
Expand Down
28 changes: 8 additions & 20 deletions cmd/ecrecover/ecrecover.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math/big"
"os"

"github.com/0xPolygon/polygon-cli/cmd/flag_loader"
"github.com/0xPolygon/polygon-cli/flag"
"github.com/0xPolygon/polygon-cli/util"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -32,12 +32,12 @@ var EcRecoverCmd = &cobra.Command{
Short: "Recovers and returns the public key of the signature.",
Long: usage,
Args: cobra.NoArgs,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
rpcUrlFlagValue := flag_loader.GetRpcUrlFlagValue(cmd)
rpcUrl = *rpcUrlFlagValue
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return checkFlags()
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
rpcUrl, err = flag.GetRPCURL(cmd)
if err != nil {
return err
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand Down Expand Up @@ -128,21 +128,9 @@ var EcRecoverCmd = &cobra.Command{

func init() {
f := EcRecoverCmd.Flags()
f.StringVarP(&rpcUrl, "rpc-url", "r", "", "the RPC endpoint URL")
f.StringVarP(&rpcUrl, flag.RPCURL, "r", "", "the RPC endpoint URL")
f.Uint64VarP(&blockNumber, "block-number", "b", 0, "block number to check the extra data for (default: latest)")
f.StringVarP(&filePath, "file", "f", "", "path to a file containing block information in JSON format")
f.StringVarP(&txData, "tx", "t", "", "transaction data in hex format")

// The sources of decoding are mutually exclusive
EcRecoverCmd.MarkFlagsMutuallyExclusive("file", "block-number", "tx")
}

func checkFlags() error {
var err error
if rpcUrl != "" {
if err = util.ValidateUrl(rpcUrl); err != nil {
return err
}
}
return err
}
27 changes: 12 additions & 15 deletions cmd/fixnoncegap/fixnoncegap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/0xPolygon/polygon-cli/cmd/flag_loader"
"github.com/0xPolygon/polygon-cli/flag"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -25,18 +25,17 @@ var FixNonceGapCmd = &cobra.Command{
Short: "Send txs to fix the nonce gap for a specific account.",
Long: fixNonceGapUsage,
Args: cobra.NoArgs,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error
rpcURL := flag_loader.GetRpcUrlFlagValue(cmd)
inputFixNonceGapArgs.rpcURL = *rpcURL
privateKey, err := flag_loader.GetRequiredPrivateKeyFlagValue(cmd)
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
inputFixNonceGapArgs.rpcURL, err = flag.GetRPCURL(cmd)
if err != nil {
return err
}
inputFixNonceGapArgs.privateKey = *privateKey
return nil
inputFixNonceGapArgs.privateKey, err = flag.GetRequiredPrivateKey(cmd)
if err != nil {
return err
}
return prepareRpcClient(cmd, args)
},
PreRunE: prepareRpcClient,
RunE: fixNonceGap,
SilenceUsage: true,
}
Expand All @@ -55,10 +54,8 @@ type fixNonceGapArgs struct {
var inputFixNonceGapArgs = fixNonceGapArgs{}

const (
ArgPrivateKey = "private-key"
ArgRpcURL = "rpc-url"
ArgReplace = "replace"
ArgMaxNonce = "max-nonce"
ArgReplace = "replace"
ArgMaxNonce = "max-nonce"
)

//go:embed FixNonceGapUsage.md
Expand Down Expand Up @@ -236,8 +233,8 @@ func fixNonceGap(cmd *cobra.Command, args []string) error {

func init() {
f := FixNonceGapCmd.Flags()
f.StringVarP(&inputFixNonceGapArgs.rpcURL, ArgRpcURL, "r", "http://localhost:8545", "the RPC endpoint URL")
f.StringVar(&inputFixNonceGapArgs.privateKey, ArgPrivateKey, "", "private key to be used when sending txs to fix nonce gap")
f.StringVarP(&inputFixNonceGapArgs.rpcURL, flag.RPCURL, "r", flag.DefaultRPCURL, "the RPC endpoint URL")
f.StringVar(&inputFixNonceGapArgs.privateKey, flag.PrivateKey, "", "private key to be used when sending txs to fix nonce gap")
f.BoolVar(&inputFixNonceGapArgs.replace, ArgReplace, false, "replace the existing txs in the pool")
f.Uint64Var(&inputFixNonceGapArgs.maxNonce, ArgMaxNonce, 0, "override max nonce value instead of getting it from the pool")
}
Expand Down
78 changes: 0 additions & 78 deletions cmd/flag_loader/flag_loader.go

This file was deleted.

Loading
Loading