Skip to content

Commit 7dd53bf

Browse files
authored
Merge pull request #321 from oasisprotocol/amela/feat/net-add-chain-context-optional
2 parents 5c43594 + e7a6eb6 commit 7dd53bf

File tree

8 files changed

+45
-14
lines changed

8 files changed

+45
-14
lines changed

cmd/network/add.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,47 @@
11
package network
22

33
import (
4+
"context"
5+
46
"github.com/spf13/cobra"
57

68
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
9+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
710

811
cliConfig "github.com/oasisprotocol/cli/config"
912
)
1013

1114
var addCmd = &cobra.Command{
12-
Use: "add <name> <chain-context> <rpc-endpoint>",
15+
Use: "add <name> <rpc-endpoint> [chain-context]",
1316
Short: "Add a new network",
14-
Args: cobra.ExactArgs(3),
17+
Args: cobra.RangeArgs(2, 3),
1518
Run: func(cmd *cobra.Command, args []string) {
1619
cfg := cliConfig.Global()
17-
name, chainContext, rpc := args[0], args[1], args[2]
20+
name, rpc := args[0], args[1]
1821

19-
net := config.Network{
20-
ChainContext: chainContext,
21-
RPC: rpc,
22-
}
2322
// Validate initial network configuration early.
2423
cobra.CheckErr(config.ValidateIdentifier(name))
24+
25+
net := config.Network{
26+
RPC: rpc,
27+
}
28+
29+
if len(args) >= 3 {
30+
net.ChainContext = args[2]
31+
} else {
32+
// Connect to the network and query the chain context.
33+
network := config.Network{
34+
RPC: net.RPC,
35+
}
36+
ctx := context.Background()
37+
conn, err := connection.ConnectNoVerify(ctx, &network)
38+
cobra.CheckErr(err)
39+
chainCtx, err := conn.Consensus().GetChainContext(ctx)
40+
cobra.CheckErr(err)
41+
net.ChainContext = chainCtx
42+
cobra.CheckErr(net.Validate())
43+
}
44+
2545
cobra.CheckErr(net.Validate())
2646

2747
// Ask user for some additional parameters.

docs/network.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,29 @@ the current Mainnet and Testnet endpoints.
3232

3333
## Add a Network {#add}
3434

35-
Invoke `network add <name> <chain-context> <rpc-endpoint>` to add a new
35+
Invoke `network add <name> <rpc-endpoint> [chain-context]` to add a new
3636
endpoint with a specific chain domain separation context and a gRPC address.
3737
This command is useful, if you want to connect to your own instance of the Oasis
3838
node instead of relying on the public gRPC endpoints.
3939

4040
For TCP/IP endpoints, run:
4141

42-
![code shell](../examples/network/add-tcpip.in.static)
42+
![code shell](../examples/network/add-tcpip-ctx.in.static)
4343

44-
![code](../examples/network/add-tcpip.out.static)
44+
![code](../examples/network/add-tcpip-ctx.out.static)
4545

4646
For Unix sockets, use:
4747

48-
![code shell](../examples/network/add-unix.in.static)
48+
![code shell](../examples/network/add-unix-ctx.in.static)
49+
50+
![code](../examples/network/add-unix-ctx.out.static)
51+
52+
To automatically detect the chain context, simply omit the `[chain-context]`
53+
argument:
54+
55+
![code shell](../examples/network/add-tcpip.in.static)
4956

50-
![code](../examples/network/add-unix.out.static)
57+
![code](../examples/network/add-tcpip.out.static)
5158

5259
## Add a Local Network {#add-local}
5360

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis network add testnet_alt testnet2.grpc.oasis.io:443 0b91b8e4e44b2003a7c5e23ddadb5e14ef5345c0ebcb3ddcae07fa2f244cab76
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
? Description: Testnet alternative
2+
? Denomination symbol: TEST
3+
? Denomination decimal places: (9)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
oasis network add testnet_alt 0b91b8e4e44b2003a7c5e23ddadb5e14ef5345c0ebcb3ddcae07fa2f244cab76 testnet2.grpc.oasis.io:443
1+
oasis network add testnet_alt testnet2.grpc.oasis.io:443
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis network add testnet_local unix:/node_testnet/data/internal.sock 0b91b8e4e44b2003a7c5e23ddadb5e14ef5345c0ebcb3ddcae07fa2f244cab76

examples/network/add-unix.in.static

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)