Jayant Krishnamurthy 2 years ago
parent
commit
58e7199110
5 changed files with 28 additions and 17 deletions
  1. 2 2
      pyth-rng/src/api.rs
  2. 2 3
      pyth-rng/src/command/run.rs
  3. 12 8
      pyth-rng/src/config.rs
  4. 12 3
      pyth-rng/src/config/run.rs
  5. 0 1
      pyth-rng/src/ethereum.rs

+ 2 - 2
pyth-rng/src/api.rs

@@ -1,6 +1,6 @@
 use {
     crate::{
-        ethereum::SignablePythContract,
+        ethereum::PythContract,
         state::HashChainState,
     },
     axum::{
@@ -37,7 +37,7 @@ pub struct BlockchainState {
     /// The hash chain(s) required to serve random numbers for this blockchain
     pub state:            Arc<HashChainState>,
     /// The EVM contract where the protocol is running.
-    pub contract:         Arc<SignablePythContract>,
+    pub contract:         Arc<PythContract>,
     /// The EVM address of the provider that this server is operating for.
     pub provider_address: Address,
 }

+ 2 - 3
pyth-rng/src/command/run.rs

@@ -5,7 +5,7 @@ use {
             Config,
             RunOptions,
         },
-        ethereum::SignablePythContract,
+        ethereum::PythContract,
         state::{
             HashChainState,
             PebbleHashChain,
@@ -47,8 +47,7 @@ pub async fn run(opts: &RunOptions) -> Result<(), Box<dyn Error>> {
     )]
     struct ApiDoc;
 
-
-    let contract = Arc::new(SignablePythContract::from_opts(&opts.config, &opts.chain_id).await?);
+    let contract = Arc::new(PythContract::from_opts(&opts.config, &opts.chain_id).await?);
     let provider_info = contract.get_provider_info(opts.provider).call().await?;
 
     // Reconstruct the hash chain based on the metadata and check that it matches the on-chain commitment.

+ 12 - 8
pyth-rng/src/config.rs

@@ -107,14 +107,18 @@ impl Config {
         Ok(())
     }
 
-    pub fn get_chain_config(&self, chain_id: &ChainId) -> Result<&EthereumConfig, Box<dyn Error>> {
-        self.chains.iter().find(|x| x.chain_id == chain_id).ok_or(
-            anyhow!(format!(
-                "Could not find chain_id {} in the configuration file",
-                &chain_id
-            ))
-            .into(),
-        )
+    pub fn get_chain_config(&self, chain_id: &ChainId) -> Result<EthereumConfig, Box<dyn Error>> {
+        self.chains
+            .iter()
+            .find(|x| x.chain_id == *chain_id)
+            .map(|c| c.clone())
+            .ok_or(
+                anyhow!(format!(
+                    "Could not find chain_id {} in the configuration file",
+                    &chain_id
+                ))
+                .into(),
+            )
     }
 }
 

+ 12 - 3
pyth-rng/src/config/run.rs

@@ -1,7 +1,10 @@
 use {
-    crate::config::{
-        ConfigOptions,
-        RandomnessOptions,
+    crate::{
+        api::ChainId,
+        config::{
+            ConfigOptions,
+            RandomnessOptions,
+        },
     },
     clap::Args,
     ethers::types::Address,
@@ -17,6 +20,12 @@ pub struct RunOptions {
     #[command(flatten)]
     pub randomness: RandomnessOptions,
 
+    // FIXME: delete this
+    /// Retrieve a randomness request to this provider
+    #[arg(long = "chain-id")]
+    #[arg(env = "PYTH_CHAIN_ID")]
+    pub chain_id: ChainId,
+
     /// Address and port the HTTP server will bind to.
     #[arg(long = "rpc-listen-addr")]
     #[arg(default_value = super::DEFAULT_RPC_ADDR)]

+ 0 - 1
pyth-rng/src/ethereum.rs

@@ -51,7 +51,6 @@ impl SignablePythContract {
 
         let wallet__ = private_key
             .clone()
-            .ok_or(anyhow!("No private key specified"))?
             .parse::<LocalWallet>()?
             .with_chain_id(chain_id.as_u64());