Skip to content

Commit

Permalink
Merge pull request #220 from bogdant36/CTX-6016
Browse files Browse the repository at this point in the history
CTX-6016: Added prompt for endpoint invocation price if near wallet i…
  • Loading branch information
dule1322 committed Jul 1, 2024
2 parents 8fe02cb + b604ce0 commit 217a596
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions coretex/cli/modules/config_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
DEFAULT_NODE_SECRET = ""
DEFAULT_INIT_SCRIPT = ""
DEFAULT_NEAR_WALLET_ID = ""
DEFAULT_ENDPOINT_INVOCATION_PRICE = 0.0
34 changes: 31 additions & 3 deletions coretex/cli/modules/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,15 @@ def shouldUpdate(image: str) -> bool:
return True


def registerNode(name: str, nodeMode: NodeMode, publicKey: Optional[bytes] = None, nearWalletId: Optional[str] = None) -> str:
params = {
def registerNode(
name: str,
nodeMode: NodeMode,
publicKey: Optional[bytes] = None,
nearWalletId: Optional[str] = None,
endpointInvocationPrice: Optional[float] = None
) -> str:

params: Dict[str, Any] = {
"machine_name": name,
"mode": nodeMode.value
}
Expand All @@ -184,6 +191,9 @@ def registerNode(name: str, nodeMode: NodeMode, publicKey: Optional[bytes] = Non
if nearWalletId is not None:
params["near_wallet_id"] = nearWalletId

if endpointInvocationPrice is not None:
params["endpoint_invocation_price"] = endpointInvocationPrice

response = networkManager.post("service", params)

if response.hasFailed():
Expand Down Expand Up @@ -255,6 +265,20 @@ def promptRam(config: Dict[str, Any], ramLimit: int) -> int:
return nodeRam


def promptInvocationPrice() -> float:
invocationPrice: float = clickPrompt(
"Enter the price of a single endpoint invocation",
config_defaults.DEFAULT_ENDPOINT_INVOCATION_PRICE,
type = float
)

if invocationPrice < 0:
errorEcho("Endpoint invocation price cannot be less than 0!")
return promptInvocationPrice()

return invocationPrice


def _configureInitScript() -> str:
initScript = clickPrompt("Enter a path to sh script which will be executed before Node starts", config_defaults.DEFAULT_INIT_SCRIPT, type = str)

Expand Down Expand Up @@ -347,6 +371,7 @@ def configureNode(config: Dict[str, Any], verbose: bool) -> None:

publicKey: Optional[bytes] = None
nearWalletId: Optional[str] = None
endpointInvocationPrice: Optional[float] = None
nodeMode = NodeMode.any

if verbose:
Expand Down Expand Up @@ -378,13 +403,16 @@ def configureNode(config: Dict[str, Any], verbose: bool) -> None:

if nearWalletId != config_defaults.DEFAULT_NEAR_WALLET_ID:
config["nearWalletId"] = nearWalletId
endpointInvocationPrice = promptInvocationPrice()
else:
config["nearWalletId"] = None
config["endpointInvocationPrice"] = None
nearWalletId = None
endpointInvocationPrice = None
else:
stdEcho("To configure node manually run coretex node config with --verbose flag.")

config["nodeAccessToken"] = registerNode(config["nodeName"], nodeMode, publicKey, nearWalletId)
config["nodeAccessToken"] = registerNode(config["nodeName"], nodeMode, publicKey, nearWalletId, endpointInvocationPrice)
config["nodeMode"] = nodeMode


Expand Down
3 changes: 3 additions & 0 deletions coretex/cli/modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def previewConfig(config: Dict[str, Any]) -> None:
if config.get("nearWalletId") is not None:
table.append(["NEAR wallet id", config["nearWalletId"]])

if config.get("endpointInvocationPrice") is not None:
table.append(["Endpoint invocation price", config["endpointInvocationPrice"]])

stdEcho(tabulate(table))


Expand Down

0 comments on commit 217a596

Please sign in to comment.