Skip to content

Commit

Permalink
next:
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Jul 5, 2024
1 parent 6958232 commit 7a0ef6b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion price-pusher/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions price-pusher/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ pragma-sdk = { path = "../pragma-sdk", develop = true }
pragma-utils = { path = "../pragma-utils", develop = true }
click = "^8.1.0"
pydantic = "^2.7.4"
boto3 = "^1.28.61"
moto = { extras = ["s3", "secretsmanager"], version = "^4.2.5" }

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.26.1"
Expand Down
2 changes: 1 addition & 1 deletion vrf-listener/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions vrf-listener/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ python = ">=3.10,<3.13"
pragma-sdk = { path = "../pragma-sdk", develop = true }
pragma-utils = { path = "../pragma-utils", develop = true }
click = "^8.1.0"
pydantic = "^2.7.4"
boto3 = "^1.28.61"
moto = { extras = ["s3", "secretsmanager"], version = "^4.2.5" }

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.26.1"
Expand Down Expand Up @@ -102,7 +99,7 @@ exclude = []
generate-setup-file = true

[tool.coverage.run]
source = ["price-pusher"]
source = ["vrf-listener"]

[tool.coverage.report]
omit = ["*_test.py", "tests/*"]
Expand Down
70 changes: 48 additions & 22 deletions vrf-listener/vrf_listener/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,35 @@
from pragma_utils.logger import setup_logging
from pragma_utils.cli import load_private_key_from_cli_arg

from pragma_sdk.onchain.client import PragmaOnChainClient

logger = logging.getLogger(__name__)


async def main():
pass
# client = PragmaOnChainClient(
# network=RPC_URL,
# account_private_key=admin_private_key,
# account_contract_address=ADMIN_CONTRACT_ADDRESS,
# chain_name=NETWORK,
# )
# client.init_randomness_contract(VRF_CONTRACT_ADDRESS)
async def main(
network: str,
rpc_url: Optional[str],
vrf_address: str,
admin_address: str,
private_key: str,
start_block: int,
update_time_interval: int,
) -> None:
client = PragmaOnChainClient(
network=rpc_url,
account_contract_address=admin_address,
account_private_key=private_key,
chain_name=network,
)
client.init_randomness_contract(vrf_address)

# while True:
# logger.info("Checking for randomness requests...")
# try:
# await client.handle_random(admin_private_key, START_BLOCK)
# except Exception as e:
# logger.error("Error handling randomness requests: %s", e)
# await asyncio.sleep(VRF_UPDATE_TIME_SECONDS)
while True:
logger.info("Checking for randomness requests...")
try:
await client.handle_random(private_key, start_block)
except Exception as e:
logger.error("Error handling randomness requests: %s", e)
await asyncio.sleep(update_time_interval)


@click.command()
Expand All @@ -39,9 +48,10 @@ async def main():
@click.option(
"-n",
"--network",
required=True,
required=False,
default="sepolia",
type=click.Choice(["sepolia", "mainnet"], case_sensitive=False),
help="At which network the price corresponds.",
help="Which network to listen. Defaults to SEPOLIA.",
)
@click.option(
"--rpc-url",
Expand All @@ -50,14 +60,12 @@ async def main():
help="RPC url used by the onchain client.",
)
@click.option(
"-v",
"--vrf-address",
type=click.STRING,
required=True,
help="Address of the VRF contract",
)
@click.option(
"-a",
"--admin-address",
type=click.STRING,
required=True,
Expand All @@ -71,12 +79,19 @@ async def main():
help="Secret key of the signer. Format: aws:secret_name, plain:secret_key, or env:ENV_VAR_NAME",
)
@click.option(
"--start-block",
"-b" "--start-block",
type=click.INT,
required=False,
default=0,
help="At which block to start listening for VRF requests. Defaults to 0.",
)
@click.option(
"-t" "--update-time-interval",
type=click.INT,
required=False,
default=10,
help="Delay in seconds between VRF checks. Defaults to 10 seconds.",
)
def cli_entrypoint(
log_level: str,
network: str,
Expand All @@ -85,6 +100,7 @@ def cli_entrypoint(
admin_address: str,
private_key: str,
start_block: int,
update_time_interval: int,
) -> None:
"""
Click does not support async functions.
Expand All @@ -95,7 +111,17 @@ def cli_entrypoint(
setup_logging(logger, log_level)
private_key = load_private_key_from_cli_arg(private_key)

asyncio.run(main())
asyncio.run(
main(
network,
rpc_url,
vrf_address,
admin_address,
private_key,
start_block,
update_time_interval,
)
)


if __name__ == "__main__":
Expand Down

0 comments on commit 7a0ef6b

Please sign in to comment.