Skip to content

Commit

Permalink
Feature: Implement VRF test endpoint just using 1 node as executor.
Browse files Browse the repository at this point in the history
  • Loading branch information
nesitor committed Apr 11, 2024
1 parent d8e09a6 commit a305a2e
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/aleph_vrf/coordinator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pydantic import BaseModel

from aleph_vrf.coordinator.executor_selection import UsePredeterminedExecutors
from aleph_vrf.settings import settings

logger = logging.getLogger(__name__)
Expand All @@ -16,7 +17,7 @@

logger.debug("local imports")
from aleph_vrf.coordinator.vrf import generate_vrf
from aleph_vrf.models import APIError, APIResponse, PublishedVRFResponse
from aleph_vrf.models import APIError, APIResponse, PublishedVRFResponse, Executor, Node

logger.debug("imports done")

Expand All @@ -41,7 +42,7 @@ async def index():

@app.post("/vrf")
async def receive_vrf(
request: Optional[VRFRequest] = None,
request: Optional[VRFRequest] = None,
) -> APIResponse[Union[PublishedVRFResponse, APIError]]:
"""
Goes through the VRF random number generation process and returns a random number
Expand All @@ -59,3 +60,33 @@ async def receive_vrf(
raise HTTPException(status_code=500, detail=str(err))

return APIResponse(data=response)


@app.post("/test_vrf")
async def receive_vrf(
request: Optional[VRFRequest] = None,
) -> APIResponse[Union[PublishedVRFResponse, APIError]]:
"""
Goes through the VRF random number generation process and returns a random number
along with details on how the number was generated.
"""

account = settings.aleph_account()

response: Union[PublishedVRFResponse, APIError]

request_id = request.request_id if request and request.request_id else None
try:
executor_url = "https://CRN_URL" # CRN main URL, like https://ovh.staging.aleph.sh/
executors = [Executor(node=Node(address=executor_url))]
executor_policy = UsePredeterminedExecutors(executors)
response = await generate_vrf(
account=account,
request_id=request_id,
nb_executors=1,
executor_selection_policy=executor_policy
)
except Exception as err:
raise HTTPException(status_code=500, detail=str(err))

return APIResponse(data=response)

0 comments on commit a305a2e

Please sign in to comment.