Skip to content

Commit

Permalink
fix: some regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstevens19 committed Jul 26, 2024
1 parent 8f23bf4 commit 82a1ccb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 22 deletions.
16 changes: 8 additions & 8 deletions cli/src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use ethers_etherscan::Client;
use rindexer::{
manifest::{
contract::{Contract, ContractDetails},
yaml::{read_manifest, write_manifest, YAML_CONFIG_NAME},
yaml::{read_manifest_raw, write_manifest, YAML_CONFIG_NAME},
},
write_file,
public_read_env_value, write_file,
};

use crate::{
Expand All @@ -28,7 +28,7 @@ pub async fn handle_add_contract_command(

let rindexer_yaml_path = project_path.join(YAML_CONFIG_NAME);

let mut manifest = read_manifest(&rindexer_yaml_path).inspect_err(|e| {
let mut manifest = read_manifest_raw(&rindexer_yaml_path).inspect_err(|e| {
print_error_message(&format!("Could not read the rindexer.yaml file: {}", e))
})?;

Expand Down Expand Up @@ -66,11 +66,11 @@ pub async fn handle_add_contract_command(
let contract_address =
prompt_for_input(&format!("Enter {} Contract Address", network), None, None, None);

let etherscan_api_key = manifest
.global
.as_ref()
.and_then(|global| global.etherscan_api_key.as_ref())
.map_or(BACKUP_ETHERSCAN_API_KEY, String::as_str);
let etherscan_api_key =
manifest.global.as_ref().and_then(|global| global.etherscan_api_key.as_ref()).map_or_else(
|| BACKUP_ETHERSCAN_API_KEY.to_string(),
|key| public_read_env_value(key).unwrap_or_else(|_| key.to_string()),
);

let client = Client::builder()
.with_api_key(etherscan_api_key)
Expand Down
23 changes: 17 additions & 6 deletions cli/src/commands/phantom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ use rindexer::{
manifest::{
network::Network,
phantom::{Phantom, PhantomDyrpc, PhantomShadow},
yaml::{read_manifest, write_manifest, YAML_CONFIG_NAME},
yaml::{read_manifest, read_manifest_raw, write_manifest, YAML_CONFIG_NAME},
},
phantom::{
common::{read_compiled_contract, read_contract_clone_metadata},
create_dyrpc_api_key, deploy_dyrpc_contract,
shadow::deploy_shadow_contract,
},
write_file,
public_read_env_value, write_file,
};

use crate::{
Expand Down Expand Up @@ -97,7 +97,7 @@ async fn handle_phantom_init(project_path: &Path) -> Result<(), Box<dyn Error>>
let env_file = project_path.join(".env");
let rindexer_yaml_path = project_path.join(YAML_CONFIG_NAME);

let mut manifest = read_manifest(&rindexer_yaml_path).inspect_err(|e| {
let mut manifest = read_manifest_raw(&rindexer_yaml_path).inspect_err(|e| {
print_error_message(&format!("Could not read the rindexer.yaml file: {}", e))
})?;

Expand Down Expand Up @@ -197,6 +197,7 @@ fn forge_clone_contract(
network: &Network,
address: &Address,
contract_name: &str,
etherscan_api_key: &str,
) -> Result<(), Box<dyn Error>> {
print_success_message(&format!(
"Cloning contract {} on network {} at address {:?} this may take a little moment...",
Expand All @@ -208,7 +209,7 @@ fn forge_clone_contract(
.arg(format!("{:?}", address))
//.arg(format!("--chain {}", network.chain_id))
.arg("--etherscan-api-key")
.arg(BACKUP_ETHERSCAN_API_KEY)
.arg(etherscan_api_key)
.arg(contract_name)
.current_dir(clone_in)
.output()?;
Expand Down Expand Up @@ -284,11 +285,21 @@ fn handle_phantom_clone(project_path: &Path, args: &PhantomBaseArgs) -> Result<(
fs::create_dir(&clone_in)?;
}

let etherscan_api_key = manifest
.global
.as_ref()
.and_then(|global| global.etherscan_api_key.as_ref())
.map_or_else(
|| BACKUP_ETHERSCAN_API_KEY.to_string(),
|key| public_read_env_value(key).unwrap_or_else(|_| key.to_string()),
);

forge_clone_contract(
&clone_in,
network.unwrap(),
address,
contract.name.as_str(),
&etherscan_api_key,
)
.map_err(|e| format!("Failed to clone contract: {}", e))?;

Expand Down Expand Up @@ -436,7 +447,7 @@ async fn handle_phantom_deploy(
) -> Result<(), Box<dyn Error>> {
let rindexer_yaml_path = project_path.join(YAML_CONFIG_NAME);

let mut manifest = read_manifest(&rindexer_yaml_path).inspect_err(|e| {
let mut manifest = read_manifest_raw(&rindexer_yaml_path).inspect_err(|e| {
print_error_message(&format!("Could not read the rindexer.yaml file: {}", e))
})?;

Expand Down Expand Up @@ -532,7 +543,7 @@ async fn handle_phantom_deploy(
rpc: rpc_url.to_string(),
compute_units_per_second: None,
max_block_range: if phantom.dyrpc_enabled() {
Some(U64::from(100_000))
Some(U64::from(20_000))
} else {
Some(U64::from(2_000))
},
Expand Down
3 changes: 1 addition & 2 deletions cli/src/rindexer_yaml.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fs;
use std::path::Path;
use std::{fs, path::Path};

use rindexer::manifest::yaml::YAML_CONFIG_NAME;

Expand Down
18 changes: 18 additions & 0 deletions core/src/manifest/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ pub enum ReadManifestError {
NoProjectPathFoundUsingParentOfManifestPath,
}

pub fn read_manifest_raw(file_path: &PathBuf) -> Result<Manifest, ReadManifestError> {
let mut file = File::open(file_path)?;
let mut contents = String::new();

file.read_to_string(&mut contents)?;

let manifest: Manifest = serde_yaml::from_str(&contents)?;

let project_path = file_path.parent();
match project_path {
None => Err(ReadManifestError::NoProjectPathFoundUsingParentOfManifestPath),
Some(project_path) => {
validate_manifest(project_path, &manifest)?;
Ok(manifest)
}
}
}

pub fn read_manifest(file_path: &PathBuf) -> Result<Manifest, ReadManifestError> {
let mut file = File::open(file_path)?;
let mut contents = String::new();
Expand Down
5 changes: 2 additions & 3 deletions core/src/phantom/dyrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub struct DeployDyrpcContractResponse {
// pub overlay_hash: String,
//
// pub addresses: Vec<String>,

#[serde(rename = "overlayRpcUrl")]
pub rpc_url: String,
}
Expand Down Expand Up @@ -80,9 +79,9 @@ pub async fn deploy_dyrpc_contract(

let re = Regex::new(r"/eth/([a-fA-F0-9]{64})/").unwrap();
let rpc_url = re
.replace(&result.rpc_url, "/eth/{RINDEXER_PHANTOM_API_ENV_KEY}/")
.replace(&result.rpc_url, "/eth/{RINDEXER_PHANTOM_API_KEY}/")
.to_string()
.replace("{RINDEXER_PHANTOM_API_ENV_KEY}", "${RINDEXER_PHANTOM_API_ENV_KEY}");
.replace("{RINDEXER_PHANTOM_API_KEY}", "${RINDEXER_PHANTOM_API_KEY}");

Ok(rpc_url)
}
Expand Down
3 changes: 2 additions & 1 deletion documentation/docs/pages/docs/start-building/phantom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ rindexer phantom init
- API key (generate on the dyRPC portal or use "new" to generate a new one)

You will be asked to pick your provider and add your API key. It will save the API key
int the `.env` file in your project directory. It will also add your phantom provider to the `rindexer.yaml` file.
int the `.env` file under `RINDEXER_PHANTOM_API_KEY` in your project directory.
It will also add your phantom provider to the `rindexer.yaml` file.

## Clone

Expand Down
4 changes: 2 additions & 2 deletions examples/rindexer_demo_cli/rindexer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
address: 0xae78736cd615f374d3085123a210448e74fc6393
start_block: '18600000'
end_block: '18718056'
abi: ./abis/RocketTokenRETH.abi.json
abi: ./abis/phantom_ethereum_RocketPoolETH.abi.json
include_events:
- Transfer

0 comments on commit 82a1ccb

Please sign in to comment.