mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 01:41:48 +00:00
client/cli: add network option to the RPC client
It doesn't affect anything yet, but it's going to be used in the future for network-specific behavior. It also renames short '--timeout' form to '-s' avoiding conlict with '-t' used for '--testnet'.
This commit is contained in:
parent
16ce63e653
commit
d22286cbbc
5 changed files with 23 additions and 19 deletions
|
@ -22,11 +22,7 @@ const RPCEndpointFlag = "rpc-endpoint"
|
|||
|
||||
// Network is a set of flags for choosing the network to operate on
|
||||
// (privnet/mainnet/testnet).
|
||||
var Network = []cli.Flag{
|
||||
cli.BoolFlag{Name: "privnet, p"},
|
||||
cli.BoolFlag{Name: "mainnet, m"},
|
||||
cli.BoolFlag{Name: "testnet, t"},
|
||||
}
|
||||
var Network = RPC[2:]
|
||||
|
||||
// RPC is a set of flags used for RPC connections (endpoint and timeout).
|
||||
var RPC = []cli.Flag{
|
||||
|
@ -35,9 +31,12 @@ var RPC = []cli.Flag{
|
|||
Usage: "RPC node address",
|
||||
},
|
||||
cli.DurationFlag{
|
||||
Name: "timeout, t",
|
||||
Name: "timeout, s",
|
||||
Usage: "Timeout for the operation (10 seconds by default)",
|
||||
},
|
||||
cli.BoolFlag{Name: "privnet, p"},
|
||||
cli.BoolFlag{Name: "mainnet, m"},
|
||||
cli.BoolFlag{Name: "testnet, t"},
|
||||
}
|
||||
|
||||
var errNoEndpoint = errors.New("no RPC endpoint specified, use option '--" + RPCEndpointFlag + "' or '-r'")
|
||||
|
@ -70,7 +69,7 @@ func GetRPCClient(gctx context.Context, ctx *cli.Context) (*client.Client, cli.E
|
|||
if len(endpoint) == 0 {
|
||||
return nil, cli.NewExitError(errNoEndpoint, 1)
|
||||
}
|
||||
c, err := client.New(gctx, endpoint, client.Options{})
|
||||
c, err := client.New(gctx, endpoint, client.Options{Network: GetNetwork(ctx)})
|
||||
if err != nil {
|
||||
return nil, cli.NewExitError(err, 1)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue