mirror of
https://github.com/logos-blockchain/logos-blockchain-pocs.git
synced 2026-02-03 12:43:08 +00:00
cryptarchia info and block fetch loop
This commit is contained in:
parent
dedbc5fa16
commit
606f80f846
@ -1,15 +1,13 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use executor_http_client::{BasicAuthCredentials, ExecutorHttpClient};
|
||||
use nomos::{CryptarchiaInfo, HeaderId};
|
||||
use reqwest::{RequestBuilder, Url};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use reqwest::Url;
|
||||
use tracing::{error, info};
|
||||
|
||||
pub const CRYPTARCHIA_INFO: &str = "cryptarchia/info";
|
||||
pub const STORAGE_BLOCK: &str = "storage/block";
|
||||
|
||||
mod nomos;
|
||||
pub mod nomos;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Credentials {
|
||||
@ -36,14 +34,11 @@ impl NomosClient {
|
||||
let url = self.base_url.join(CRYPTARCHIA_INFO).expect("Invalid URL");
|
||||
|
||||
info!("Requesting cryptarchia info from {}", url);
|
||||
|
||||
let request = self.reqwest_client.get(url).basic_auth(
|
||||
&self.basic_auth.username,
|
||||
self.basic_auth.password.as_deref(),
|
||||
);
|
||||
|
||||
info!("Sending request with creds {:?}", self.basic_auth);
|
||||
|
||||
let response = request.send().await.map_err(|e| {
|
||||
error!("Failed to send request: {}", e);
|
||||
"Failed to send request".to_string()
|
||||
@ -65,7 +60,6 @@ impl NomosClient {
|
||||
let url = self.base_url.join(STORAGE_BLOCK).expect("Invalid URL");
|
||||
|
||||
info!("Requesting block with HeaderId {}", id);
|
||||
|
||||
let request = self
|
||||
.reqwest_client
|
||||
.post(url)
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
use clap::Parser;
|
||||
use evm_lightnode::{Credentials, NomosClient};
|
||||
use executor_http_client::BasicAuthCredentials;
|
||||
use evm_lightnode::{Credentials, NomosClient, nomos::HeaderId};
|
||||
use url::Url;
|
||||
|
||||
use std::error;
|
||||
@ -34,11 +33,18 @@ async fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
|
||||
let consensus = NomosClient::new(Url::parse(&url).unwrap(), basic_auth);
|
||||
|
||||
let info = consensus.get_cryptarchia_info().await?;
|
||||
println!("Cryptarchia Info: {:?}", info);
|
||||
let mut current_tip = HeaderId::default();
|
||||
loop {
|
||||
let info = consensus.get_cryptarchia_info().await?;
|
||||
println!("Cryptarchia Info: {:?}", info);
|
||||
|
||||
let block = consensus.get_block(info.tip).await?;
|
||||
println!("Block: {:?}", block);
|
||||
if info.tip != current_tip {
|
||||
current_tip = info.tip;
|
||||
println!("New tip: {:?}", current_tip);
|
||||
let block = consensus.get_block(info.tip).await?;
|
||||
println!("Block: {:?}", block);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ pub struct CryptarchiaInfo {
|
||||
pub height: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Copy, Hash, PartialOrd, Ord)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Copy, Hash, PartialOrd, Ord, Default)]
|
||||
pub struct HeaderId([u8; 32]);
|
||||
|
||||
impl<'de> Deserialize<'de> for HeaderId {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user