Skip to content

Commit 1dcd07d

Browse files
ci: Add pricefeeder configuration functions to interactive installer [DEV-5761] (#963)
* chore: Add pricefeeder configuration funtions to interactive installer * Replaced dead links --------- Co-authored-by: Tasos Derisiotis <tasosderiziotis@gmail.com>
1 parent 8111438 commit 1dcd07d

2 files changed

Lines changed: 81 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Once installed, `cheqd-node` can be controlled using the [cheqd Cosmos CLI guide
5454

5555
## 🛠 Developing & contributing to cheqd
5656

57-
`cheqd-node` is written in Go and built using Cosmos SDK. The [Cosmos SDK Developer Guide](https://docs.cosmos.network/main) explains a lot of the [basic concepts](https://docs.cosmos.network/main/basics/app-anatomy) of how the cheqd network functions.
57+
`cheqd-node` is written in Go and built using Cosmos SDK. The [Cosmos SDK Developer Guide](https://docs.cosmos.network) explains a lot of the [basic concepts](https://docs.cosmos.network/sdk/v0.50/learn/beginner/app-anatomy) of how the cheqd network functions.
5858

5959
If you want to build a node from source or contribute to the code, please read our guide to [building and testing](https://docs.cheqd.io/node/developing-on-cheqd/build-and-networks).
6060

installer/installer.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ def install(self) -> bool:
494494
logging.error("Failed to configure cheqd-noded settings")
495495
return False
496496

497+
# Configure pricefeeder settings
498+
if self.configure_pricefeeder():
499+
logging.info("Successfully configured pricefeeder settings")
500+
else:
501+
logging.error("Failed to configure pricefeeder settings")
502+
return False
503+
497504
# Configure state sync only for fresh installs
498505
if self.interviewer.is_from_scratch and getattr(self.interviewer, 'use_statesync', False):
499506
logging.info("Configuring state sync (default)")
@@ -1270,6 +1277,79 @@ def remove_mempool_section(self, app_toml_path: str) -> bool:
12701277
logging.exception(f"Failed to comment out [mempool] section in app.toml. Reason: {e}")
12711278
return False
12721279

1280+
def configure_pricefeeder(self) -> bool:
1281+
# Download price-feeder.toml and configure pricefeeder section in app.toml
1282+
# This is required for the node to function properly with the oracle module
1283+
try:
1284+
app_toml_path = os.path.join(self.cheqd_config_dir, "app.toml")
1285+
price_feeder_config_path = os.path.join(self.cheqd_config_dir, "price-feeder.toml")
1286+
price_feeder_url = f"https://raw.githubusercontent.com/cheqd/cheqd-node/{DEFAULT_DEBUG_BRANCH}/pricefeeder/price-feeder.toml"
1287+
1288+
# Download price-feeder.toml if it doesn't exist
1289+
if os.path.exists(price_feeder_config_path):
1290+
logging.info(f"price-feeder.toml already exists at {price_feeder_config_path}. Skipping download...")
1291+
else:
1292+
logging.info("Downloading price-feeder.toml configuration file...")
1293+
if is_valid_url(price_feeder_url):
1294+
with request.urlopen(price_feeder_url) as response:
1295+
price_feeder_content = response.read().decode("utf-8")
1296+
with open(price_feeder_config_path, "w") as file:
1297+
file.write(price_feeder_content)
1298+
logging.info(f"Successfully downloaded price-feeder.toml to {price_feeder_config_path}")
1299+
else:
1300+
logging.error(f"Invalid URL for price-feeder.toml: {price_feeder_url}")
1301+
return False
1302+
1303+
# Update pricefeeder settings in app.toml
1304+
if not os.path.exists(app_toml_path):
1305+
logging.debug(f"app.toml not found at {app_toml_path}. Skipping pricefeeder configuration...")
1306+
return True
1307+
1308+
logging.info("Configuring pricefeeder settings in app.toml...")
1309+
with open(app_toml_path, "r") as file:
1310+
lines = file.readlines()
1311+
1312+
# Remove existing [pricefeeder] section entirely
1313+
in_pricefeeder_section = False
1314+
modified_lines = []
1315+
1316+
for line in lines:
1317+
stripped = line.strip()
1318+
1319+
if stripped == "[pricefeeder]":
1320+
in_pricefeeder_section = True
1321+
continue
1322+
1323+
if in_pricefeeder_section and stripped.startswith("[") and stripped != "[pricefeeder]":
1324+
in_pricefeeder_section = False
1325+
1326+
if in_pricefeeder_section:
1327+
continue
1328+
1329+
modified_lines.append(line)
1330+
1331+
# Add pricefeeder config params
1332+
pricefeeder_config = f"""
1333+
###############################################################################
1334+
### Pricefeeder ###
1335+
###############################################################################
1336+
1337+
[pricefeeder]
1338+
config_path = "{price_feeder_config_path}"
1339+
log_level = "info"
1340+
enable = true
1341+
"""
1342+
modified_lines.append(pricefeeder_config)
1343+
1344+
with open(app_toml_path, "w") as file:
1345+
file.writelines(modified_lines)
1346+
1347+
logging.info("Successfully configured pricefeeder in app.toml")
1348+
return True
1349+
except Exception as e:
1350+
logging.exception(f"Failed to configure pricefeeder. Reason: {e}")
1351+
return False
1352+
12731353
def _get_latest_block_height(self, rpc_endpoint: str) -> int:
12741354
try:
12751355
req = request.Request(f"{rpc_endpoint}/status")

0 commit comments

Comments
 (0)