mirror of
https://github.com/logos-blockchain/logos-blockchain-pocs.git
synced 2026-01-10 09:03:12 +00:00
add code for getting shares for blob id from id
This commit is contained in:
parent
667846c602
commit
a218d147fa
@ -1,7 +1,9 @@
|
||||
use clap::Parser;
|
||||
use evm_lightnode::proofcheck;
|
||||
use evm_lightnode::{Credentials, NomosClient, nomos::HeaderId, proofcheck};
|
||||
use futures::StreamExt;
|
||||
use std::error;
|
||||
use std::path::PathBuf;
|
||||
use tracing::info;
|
||||
use tracing_subscriber::{EnvFilter, fmt};
|
||||
use url::Url;
|
||||
|
||||
@ -27,6 +29,8 @@ struct Args {
|
||||
zeth_binary_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
const TESTNET_EXECUTOR: &str = "https://testnet.nomos.tech/node/3/";
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
let args = Args::parse();
|
||||
@ -48,5 +52,69 @@ async fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
)
|
||||
.await?;
|
||||
|
||||
//todo: use check_da_periodically to check for new blocks from da
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn check_da_periodically() -> Result<(), Box<dyn error::Error>> {
|
||||
let url = std::env::var("NOMOS_EXECUTOR").unwrap_or(TESTNET_EXECUTOR.to_string());
|
||||
let user = std::env::var("NOMOS_USER").unwrap_or_default();
|
||||
let password = std::env::var("NOMOS_PASSWORD").unwrap_or_default();
|
||||
let basic_auth = Credentials {
|
||||
username: user,
|
||||
password: Some(password),
|
||||
};
|
||||
|
||||
let nomos_client = NomosClient::new(Url::parse(&url).unwrap(), basic_auth);
|
||||
|
||||
let mut current_tip = HeaderId::default();
|
||||
|
||||
loop {
|
||||
let info = nomos_client.get_cryptarchia_info().await?;
|
||||
|
||||
if info.tip != current_tip {
|
||||
current_tip = info.tip;
|
||||
info!("New tip: {:?}", current_tip);
|
||||
let block = nomos_client.get_block(info.tip).await?;
|
||||
info!("Block: {:?}", block);
|
||||
|
||||
let blobs = block.get("bl_blobs");
|
||||
|
||||
if blobs.is_none() {
|
||||
info!("Parsing error");
|
||||
continue;
|
||||
};
|
||||
|
||||
let blobs = blobs.unwrap().as_array().unwrap();
|
||||
if blobs.is_empty() {
|
||||
info!("No blobs found in block");
|
||||
continue;
|
||||
}
|
||||
for blob in blobs {
|
||||
let id_array = blob.get("id").unwrap().as_array().unwrap();
|
||||
|
||||
let mut blob_id = [0u8; 32];
|
||||
for (i, num) in id_array.iter().enumerate() {
|
||||
if i < 32 {
|
||||
blob_id[i] = num.as_u64().unwrap() as u8;
|
||||
}
|
||||
}
|
||||
|
||||
info!("fetching stream");
|
||||
let shares_stream = nomos_client.get_shares(blob_id).await?;
|
||||
|
||||
let shares = shares_stream.collect::<Vec<_>>().await;
|
||||
|
||||
info!("Shares for blob_id {:?}: {:?}", blob_id, shares);
|
||||
|
||||
// todo: verify proof
|
||||
}
|
||||
} else {
|
||||
info!("No new tip, sleeping...");
|
||||
}
|
||||
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,10 +2,6 @@ use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
use hex::FromHex;
|
||||
|
||||
// tip "4f573735fb987453f7467688ea4e034b9161e3ca200526faf5c8ce6db09da180"
|
||||
// slot 5085
|
||||
// height 1245
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct CryptarchiaInfo {
|
||||
pub tip: HeaderId,
|
||||
|
||||
@ -46,7 +46,7 @@ impl NomosDa {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn disperse(&self, data: Vec<u8>, metadata: Metadata) -> Result<(), Error> {
|
||||
pub async fn disperse(&self, data: Vec<u8>, metadata: Metadata) -> Result<[u8; 32], Error> {
|
||||
self.client
|
||||
.publish_blob(self.url.clone(), data, metadata)
|
||||
.await
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user