Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/CRISP/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ PROGRAM_SERVER_URL=http://127.0.0.1:13151
WS_RPC_URL=ws://127.0.0.1:8545
CHAIN_ID=31337

# Bitquery API key
BITQUERY_API_KEY=""
# Etherscan API key
ETHERSCAN_API_KEY=""

# Cron-job API key to trigger new rounds
CRON_API_KEY=1234567890
Expand All @@ -275,8 +275,8 @@ E3_COMPUTE_PROVIDER_NAME="RISC0"
E3_COMPUTE_PROVIDER_PARALLEL=false
E3_COMPUTE_PROVIDER_BATCH_SIZE=4 # Must be a power of 2

# Bitquery API Key (optional, leave empty if not using)
BITQUERY_API_KEY=""
# ETHERSCAN API Key (optional, leave empty if not using)
ETHERSCAN_API_KEY=""
```

## Running Ciphernodes
Expand Down
4 changes: 2 additions & 2 deletions examples/CRISP/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ PROGRAM_SERVER_URL=http://127.0.0.1:13151
WS_RPC_URL=ws://127.0.0.1:8545
CHAIN_ID=31337

# Bitquery API key
BITQUERY_API_KEY=""
# Etherscan API key
ETHERSCAN_API_KEY=""

# Cron-job API key to trigger new rounds
CRON_API_KEY=1234567890
Expand Down
2 changes: 1 addition & 1 deletion examples/CRISP/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Config {
pub e3_compute_provider_name: String,
pub e3_compute_provider_parallel: bool,
pub e3_compute_provider_batch_size: u32,
pub bitquery_api_key: String,
pub etherscan_api_key: String,
}

impl Config {
Expand Down
2 changes: 1 addition & 1 deletion examples/CRISP/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.

pub mod config;
pub mod logger;
pub mod server;
pub mod config;
32 changes: 19 additions & 13 deletions examples/CRISP/server/src/server/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.

use crate::server::token_holders::{get_mock_token_holders, BitqueryClient};
use crate::server::token_holders::{get_mock_token_holders, EtherscanClient};
use crate::server::{
models::{CurrentRound, CustomParams},
program_server_request::run_compute,
Expand All @@ -14,7 +14,7 @@ use crate::server::{
};
use alloy::providers::{Provider, ProviderBuilder};
use alloy::sol_types::{sol_data, SolType};
use alloy_primitives::Address;
use alloy_primitives::{Address, U256};
use e3_sdk::{
evm_helpers::{
contracts::{
Expand Down Expand Up @@ -74,8 +74,8 @@ pub async fn register_e3_requested(
repo.initialize_round(custom_params.token_address, custom_params.balance_threshold)
.await?;

// Get token holders from Bitquery API or mocked data.
let token_holders = if matches!(CONFIG.chain_id, 31337 | 1337 | 11155111) {
// Get token holders from Etherscan API or mocked data.
let token_holders = if matches!(CONFIG.chain_id, 31337 | 1337) {
info!(
"Using mocked token holders for local network (chain_id: {})",
CONFIG.chain_id
Expand All @@ -84,22 +84,28 @@ pub async fn register_e3_requested(
get_mock_token_holders()
} else {
info!(
"Using Bitquery API for network (chain_id: {})",
"Using Etherscan API for network (chain_id: {})",
CONFIG.chain_id
);

let bitquery_client = BitqueryClient::new(CONFIG.bitquery_api_key.clone());
bitquery_client
.get_token_holders(
let etherscan_client =
EtherscanClient::new(CONFIG.etherscan_api_key.clone(), CONFIG.chain_id);
etherscan_client
.get_token_holders_with_voting_power(
token_address,
balance_threshold,
event.e3.requestBlock.to::<u64>(),
CONFIG.chain_id,
10000, // TODO: this is fine for now, but we need pagination or chunking strategies
// to retrieve large datasets efficiently.
&CONFIG.http_rpc_url,
U256::from_str_radix(&balance_threshold.to_string(), 10).map_err(
|e| {
eyre::eyre!(
"Failed to convert balance threshold to U256: {}",
e
)
},
)?,
)
.await
.with_context(|| "Bitquery error")?
.map_err(|e| eyre::eyre!("Etherscan error: {}", e))?
};

if token_holders.is_empty() {
Expand Down
5 changes: 1 addition & 4 deletions examples/CRISP/server/src/server/program_server_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ where
serializer.serialize_str(&hex_string)
}

fn serialize_hex_tuple<S>(
tuples: &Vec<(Vec<u8>, u64)>,
serializer: S,
) -> Result<S::Ok, S::Error>
fn serialize_hex_tuple<S>(tuples: &Vec<(Vec<u8>, u64)>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
Expand Down
8 changes: 6 additions & 2 deletions examples/CRISP/server/src/server/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ impl<S: DataStore> CrispE3Repository<S> {
self.set_crisp(e3_crisp).await
}

pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String) -> Result<()> {
pub async fn initialize_round(
&mut self,
token_address: String,
balance_threshold: String,
) -> Result<()> {
self.set_crisp(E3Crisp {
has_voted: vec![],
start_time: 0u64,
Expand Down Expand Up @@ -254,7 +258,7 @@ impl<S: DataStore> CrispE3Repository<S> {
})
.await
.map_err(|_| eyre::eyre!("Could not set token_holder_hashes for '{key}'"))?;

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion examples/CRISP/server/src/server/routes/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::server::{
use actix_web::{web, HttpResponse, Responder};
use alloy::{
dyn_abi::DynSolValue,
primitives::{Bytes, U256, Address},
primitives::{Address, Bytes, U256},
};
use e3_sdk::evm_helpers::contracts::{EnclaveContract, EnclaveWrite};
use eyre::Error;
Expand Down
Loading
Loading