Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client fork #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
73 changes: 73 additions & 0 deletions beacon-api-client/src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@ use ethereum_consensus::{
altair::SyncCommitteeMessage,
builder::SignedValidatorRegistration,
capella::{SignedBlsToExecutionChange, Withdrawal},
deneb::{
self,
mainnet::{
BYTES_PER_LOGS_BLOOM, EPOCHS_PER_HISTORICAL_VECTOR, EPOCHS_PER_SLASHINGS_VECTOR,
ETH1_DATA_VOTES_BOUND, HISTORICAL_ROOTS_LIMIT, MAX_EXTRA_DATA_BYTES,
MAX_VALIDATORS_PER_COMMITTEE, SLOTS_PER_HISTORICAL_ROOT, SYNC_COMMITTEE_SIZE,
VALIDATOR_REGISTRY_LIMIT,
},
minimal::BeaconState,
},
networking::PeerId,
phase0::{AttestationData, Fork, ProposerSlashing, SignedVoluntaryExit},
primitives::{
BlobIndex, Bytes32, CommitteeIndex, Epoch, RandaoReveal, Root, Slot, ValidatorIndex,
},
ssz::prelude::Deserialize,
Fork as Version,
};
use http::StatusCode;
Expand Down Expand Up @@ -599,6 +610,68 @@ impl<C: ClientTypes> Client<C> {
Ok(result.data)
}

pub async fn get_state_raw(&self, id: StateId) -> Result<C::BeaconState, Error> {
let path = format!("eth/v2/debug/beacon/states/{id}");
let target = self.endpoint.join(&path)?;
let response =
self.http.get(target).header("Accept", "application/octet-stream").send().await?;

let a = response.bytes().await?;
let b: &[u8] = &a;
// println!("b: {:?}", b);
// println!(
// "b: {:?}",
// deneb::BeaconState::<
// SLOTS_PER_HISTORICAL_ROOT,
// HISTORICAL_ROOTS_LIMIT,
// ETH1_DATA_VOTES_BOUND,
// VALIDATOR_REGISTRY_LIMIT,
// EPOCHS_PER_HISTORICAL_VECTOR,
// EPOCHS_PER_SLASHINGS_VECTOR,
// MAX_VALIDATORS_PER_COMMITTEE,
// SYNC_COMMITTEE_SIZE,
// BYTES_PER_LOGS_BLOOM,
// MAX_EXTRA_DATA_BYTES,
// >::deserialize(b)

let c = deneb::BeaconState::<
SLOTS_PER_HISTORICAL_ROOT,
HISTORICAL_ROOTS_LIMIT,
ETH1_DATA_VOTES_BOUND,
VALIDATOR_REGISTRY_LIMIT,
EPOCHS_PER_HISTORICAL_VECTOR,
EPOCHS_PER_SLASHINGS_VECTOR,
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
>::deserialize(b)
.unwrap();

println!("c.slot: {:?}", c.slot);

// );

return Err(Error::MissingExpectedData("Asd".into()));
}

// pub async fn get<T: serde::Serialize + serde::de::DeserializeOwned>(
// &self,
// path: &str,
// ) -> Result<T, Error> {
// let result: ApiResult<T> = self.http_get(path).await?.json().await?;
// match result {
// ApiResult::Ok(result) => Ok(result),
// ApiResult::Err(err) => Err(err.into()),
// }
// }

// pub async fn http_get(&self, path: &str) -> Result<reqwest::Response, Error> {
// let target = self.endpoint.join(path)?;
// let response = self.http.get(target).send().await?;
// Ok(response)
// }

// v2 endpoint
pub async fn get_heads(&self) -> Result<Vec<CoordinateWithMetadata>, Error> {
let result: Value<Vec<CoordinateWithMetadata>> =
Expand Down
10 changes: 5 additions & 5 deletions beacon-api-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use beacon_api_client::{mainnet::Client, run_cli, CliConfig};
use clap::Parser;
use beacon_api_client::{mainnet::Client, StateId};
use url::Url;

#[tokio::main]
async fn main() {
let args = CliConfig::parse();
let url = Url::parse(&args.endpoint).unwrap();
let url = Url::parse(&*std::env::var("BEACON_URL").unwrap()).unwrap();
// let url = Url::parse("http://localhost:5052/").unwrap();
let client = Client::new(url);
run_cli(&client, &args).await;
let state = client.get_state_raw(StateId::Slot(9568224)).await.unwrap();
// run_cli(&client, &args).await;
}