refactor: migrate blockchain CLI commands to use centralized config and update port assignments
- Replace load_multichain_config() with ctx.obj['config'] in all blockchain commands - Update blockchain RPC port from 8003 to 8006 throughout CLI - Add blockchain_rpc_url and wallet_url fields to Config class with environment variable support - Update node status command to use new port logic (8006 for primary, 8026 for dev) - Update installation docs to reflect new blockchain RPC port (8006) - Update
This commit is contained in:
@@ -5,14 +5,11 @@ import httpx
|
||||
|
||||
def _get_node_endpoint(ctx):
|
||||
try:
|
||||
from ..core.config import load_multichain_config
|
||||
config = load_multichain_config()
|
||||
if not config.nodes:
|
||||
return "http://127.0.0.1:8082"
|
||||
# Return the first node's endpoint
|
||||
return list(config.nodes.values())[0].endpoint
|
||||
config = ctx.obj['config']
|
||||
# Use the new blockchain_rpc_url from config
|
||||
return config.blockchain_rpc_url
|
||||
except:
|
||||
return "http://127.0.0.1:8082"
|
||||
return "http://127.0.0.1:8006" # Use new blockchain RPC port
|
||||
|
||||
from typing import Optional, List
|
||||
from ..utils import output, error
|
||||
@@ -34,12 +31,8 @@ def blockchain(ctx):
|
||||
def blocks(ctx, limit: int, from_height: Optional[int]):
|
||||
"""List recent blocks"""
|
||||
try:
|
||||
from ..core.config import load_multichain_config
|
||||
config = load_multichain_config()
|
||||
if not config.nodes:
|
||||
node_url = "http://127.0.0.1:8003"
|
||||
else:
|
||||
node_url = list(config.nodes.values())[0].endpoint
|
||||
config = ctx.obj['config']
|
||||
node_url = config.blockchain_rpc_url # Use new blockchain RPC port
|
||||
|
||||
# Get blocks from the local blockchain node
|
||||
with httpx.Client() as client:
|
||||
@@ -82,12 +75,8 @@ def blocks(ctx, limit: int, from_height: Optional[int]):
|
||||
def block(ctx, block_hash: str):
|
||||
"""Get details of a specific block"""
|
||||
try:
|
||||
from ..core.config import load_multichain_config
|
||||
config = load_multichain_config()
|
||||
if not config.nodes:
|
||||
node_url = "http://127.0.0.1:8003"
|
||||
else:
|
||||
node_url = list(config.nodes.values())[0].endpoint
|
||||
config = ctx.obj['config']
|
||||
node_url = config.blockchain_rpc_url # Use new blockchain RPC port
|
||||
|
||||
# Try to get block from local blockchain node
|
||||
with httpx.Client() as client:
|
||||
@@ -163,10 +152,10 @@ def status(ctx, node: int):
|
||||
"""Get blockchain node status"""
|
||||
config = ctx.obj['config']
|
||||
|
||||
# Map node to RPC URL
|
||||
# Map node to RPC URL using new port logic
|
||||
node_urls = {
|
||||
1: "http://localhost:8003",
|
||||
2: "http://localhost:9080/rpc", # Use RPC API with correct endpoint
|
||||
1: "http://localhost:8006", # Primary Blockchain RPC
|
||||
2: "http://localhost:8026", # Development Blockchain RPC
|
||||
3: "http://aitbc.keisanki.net/rpc"
|
||||
}
|
||||
|
||||
@@ -224,12 +213,8 @@ def sync_status(ctx):
|
||||
def peers(ctx):
|
||||
"""List connected peers"""
|
||||
try:
|
||||
from ..core.config import load_multichain_config
|
||||
config = load_multichain_config()
|
||||
if not config.nodes:
|
||||
node_url = "http://127.0.0.1:8003"
|
||||
else:
|
||||
node_url = list(config.nodes.values())[0].endpoint
|
||||
config = ctx.obj['config']
|
||||
node_url = config.blockchain_rpc_url # Use new blockchain RPC port
|
||||
|
||||
# Try to get peers from the local blockchain node
|
||||
with httpx.Client() as client:
|
||||
@@ -258,12 +243,8 @@ def peers(ctx):
|
||||
def info(ctx):
|
||||
"""Get blockchain information"""
|
||||
try:
|
||||
from ..core.config import load_multichain_config
|
||||
config = load_multichain_config()
|
||||
if not config.nodes:
|
||||
node_url = "http://127.0.0.1:8003"
|
||||
else:
|
||||
node_url = list(config.nodes.values())[0].endpoint
|
||||
config = ctx.obj['config']
|
||||
node_url = config.blockchain_rpc_url # Use new blockchain RPC port
|
||||
|
||||
with httpx.Client() as client:
|
||||
# Get head block for basic info
|
||||
@@ -295,12 +276,8 @@ def info(ctx):
|
||||
def supply(ctx):
|
||||
"""Get token supply information"""
|
||||
try:
|
||||
from ..core.config import load_multichain_config
|
||||
config = load_multichain_config()
|
||||
if not config.nodes:
|
||||
node_url = "http://127.0.0.1:8003"
|
||||
else:
|
||||
node_url = list(config.nodes.values())[0].endpoint
|
||||
config = ctx.obj['config']
|
||||
node_url = config.blockchain_rpc_url # Use new blockchain RPC port
|
||||
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
@@ -322,12 +299,8 @@ def supply(ctx):
|
||||
def validators(ctx):
|
||||
"""List blockchain validators"""
|
||||
try:
|
||||
from ..core.config import load_multichain_config
|
||||
config = load_multichain_config()
|
||||
if not config.nodes:
|
||||
node_url = "http://127.0.0.1:8003"
|
||||
else:
|
||||
node_url = list(config.nodes.values())[0].endpoint
|
||||
config = ctx.obj['config']
|
||||
node_url = config.blockchain_rpc_url # Use new blockchain RPC port
|
||||
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
|
||||
@@ -16,6 +16,8 @@ class Config:
|
||||
role: Optional[str] = None # admin, client, miner, etc.
|
||||
config_dir: Path = field(default_factory=lambda: Path.home() / ".aitbc")
|
||||
config_file: Optional[str] = None
|
||||
blockchain_rpc_url: str = "http://127.0.0.1:8006"
|
||||
wallet_url: str = "http://127.0.0.1:8002"
|
||||
|
||||
def __post_init__(self):
|
||||
"""Initialize configuration"""
|
||||
@@ -39,6 +41,10 @@ class Config:
|
||||
self.api_key = os.getenv("AITBC_API_KEY")
|
||||
if os.getenv("AITBC_ROLE"):
|
||||
self.role = os.getenv("AITBC_ROLE")
|
||||
if os.getenv("AITBC_BLOCKCHAIN_RPC_URL"):
|
||||
self.blockchain_rpc_url = os.getenv("AITBC_BLOCKCHAIN_RPC_URL")
|
||||
if os.getenv("AITBC_WALLET_URL"):
|
||||
self.wallet_url = os.getenv("AITBC_WALLET_URL")
|
||||
|
||||
def load_from_file(self):
|
||||
"""Load configuration from YAML file"""
|
||||
@@ -50,6 +56,8 @@ class Config:
|
||||
self.coordinator_url = data.get('coordinator_url', self.coordinator_url)
|
||||
self.api_key = data.get('api_key', self.api_key)
|
||||
self.role = data.get('role', self.role)
|
||||
self.blockchain_rpc_url = data.get('blockchain_rpc_url', self.blockchain_rpc_url)
|
||||
self.wallet_url = data.get('wallet_url', self.wallet_url)
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not load config file: {e}")
|
||||
|
||||
@@ -63,7 +71,9 @@ class Config:
|
||||
|
||||
data = {
|
||||
'coordinator_url': self.coordinator_url,
|
||||
'api_key': self.api_key
|
||||
'api_key': self.api_key,
|
||||
'blockchain_rpc_url': self.blockchain_rpc_url,
|
||||
'wallet_url': self.wallet_url
|
||||
}
|
||||
|
||||
if self.role:
|
||||
|
||||
Reference in New Issue
Block a user