Skip to content

Commit 9835c8c

Browse files
committed
Adjust PysuiConfiguration.initialize_config
1 parent b2ca7b2 commit 9835c8c

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

doc/source/graphql_qnodes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
QueryNodes
3-
==========
2+
GraphQL QueryNodes
3+
==================
44

55
General
66
-------

doc/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Welcome to pysui's documentation!
2323
logging
2424
builders
2525
utilities
26-
grpc
26+
pyconfig
2727
graphql
2828
graphql_prog_txn
29-
graphql_pyconfig
3029
graphql_qnodes
3130
graphql_serial_exc
31+
grpc
3232
aliases
3333
multi_sig
3434
prog_txn

doc/source/graphql_pyconfig.rst renamed to doc/source/pyconfig.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
GraphQL PysuiConfiguration
2-
""""""""""""""""""""""""""
1+
PysuiConfiguration
2+
""""""""""""""""""
33

4-
PysuiConfiguration is the GraphQL replacement for the
4+
PysuiConfiguration is the gRPC and GraphQL replacement for the
55
legacy SuiConfig and this new class must be used when creating GraphQL
66
clients and SuiTransactions.
77

@@ -49,22 +49,29 @@ First time instantiation
4949

5050
For the initial setup of PysuiConfiguration you would use the ``PysuiConfiguration.initialize_config`` class method.
5151

52-
Here is an example that sets up a configuration for standard GraphQL:
52+
Here is an example that sets up a configuration for standard GraphQL and gRPC:
5353

5454
.. code-block:: python
5555
:linenos:
5656
5757
# Identify the path where PysuiConfig.json goes
5858
fpath = Path("~/cfgamp1")
59-
# Create a group definition. In this case, the
60-
# 'graphql_from_sui' flag says to load urls, private keys
61-
# and aliases from the `~/.sui/sui_config` folder
59+
# Create a group definitions and load base from ~/.sui/sui_config.
6260
init_groups = [
61+
# GraphQL standard, make it active
6362
{
64-
"name": "sui_gql_config",
63+
"name": PysuiConfiguration.SUI_GQL_RPC_GROUP,
6564
"graphql_from_sui": True,
65+
"grpc_from_sui": False,
6666
"make_active": True,
67-
}
67+
},
68+
# gRPC standard
69+
{
70+
"name": PysuiConfiguration.SUI_GRPC_GROUP,
71+
"graphql_from_sui": False,
72+
"grpc_from_sui": True,
73+
"make_active": False,
74+
},
6875
]
6976
cfg = PysuiConfiguration.initialize_config(
7077
in_folder=fpath, # if parm not supplied, defaults to `~/.pysui`

pysui/sui/sui_pgql/config/pysui_config.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ def initialize_config(
9090
in_folder: Optional[Path] = None,
9191
init_groups: list[dict],
9292
) -> "PysuiConfiguration":
93-
"""."""
93+
"""Initialize a PysuiConfiguration (PysuiConfig.json)."""
9494
if len(init_groups) == 0:
9595
raise ValueError("At least 1 group needed in initialize_config")
9696
_config_root = in_folder if in_folder else Path("~/.pysui")
9797
_config_root = _config_root.expanduser()
9898
_config_file = _config_root / "PysuiConfig.json"
9999
if not _config_root.exists():
100100
_config_root.mkdir(parents=True, exist_ok=True)
101+
if _config_file.exists():
102+
raise ValueError(f"{_config_file} already exists.")
101103

102104
instance = cls.__new__(cls)
103105

@@ -130,8 +132,24 @@ def initialize_config(
130132
prf.url = "https://sui-mainnet.mystenlabs.com/graphql"
131133
else:
132134
raise ValueError(
133-
f"Initialize {group['name']} from sui config failure. sui config does not exist."
135+
f"Initialize {group['name']} from sui config failure. Sui config does not exist."
134136
)
137+
if group.get("grpc_from_sui", None):
138+
if _suicfg.exists():
139+
group_cfg = deepcopy(_faux_group)
140+
group_cfg.group_name = group["name"]
141+
for prf in group_cfg.profiles:
142+
if prf.profile_name == "devnet":
143+
prf.url = "fullnode.devnet.sui.io:443"
144+
elif prf.profile_name == "testnet":
145+
prf.url = "fullnode.testnet.sui.io:443"
146+
elif prf.profile_name == "mainnet":
147+
prf.url = "fullnode.mainnet.sui.io:443"
148+
else:
149+
raise ValueError(
150+
f"Initialize {group['name']} from sui config failure. Sui config does not exist."
151+
)
152+
135153
instance.model.add_group(
136154
group=group_cfg, make_active=group.get("make_active", False)
137155
)

0 commit comments

Comments
 (0)