This commit is contained in:
Giacomo Pasini 2023-10-30 12:44:23 +01:00
parent 74a24266fa
commit ded97ecc8d
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
2 changed files with 19 additions and 7 deletions

View File

@ -85,6 +85,8 @@ impl NomosChat {
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let node_addr = Some(self.node.clone());
let (payload_sender, payload_receiver) = tokio::sync::mpsc::unbounded_channel();
let (status_sender, status_updates) = std::sync::mpsc::channel();
@ -97,7 +99,7 @@ impl NomosChat {
timeout: DEFAULT_TIMEOUT,
da_protocol,
status_updates: status_sender,
node_addr: None,
node_addr,
output: None,
},
},
@ -168,7 +170,14 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) {
if !app.message_in_flight && !app.input.value().is_empty() {
app.message_in_flight = true;
app.payload_sender
.send(app.input.value().as_bytes().into())
.send(
wire::serialize(&ChatMessage {
author: app.username.clone().unwrap(),
message: app.input.value().into(),
})
.unwrap()
.into(),
)
.unwrap();
}
}
@ -187,7 +196,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) {
}
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
struct ChatMessage {
author: String,
message: String,
@ -209,7 +218,7 @@ async fn fetch_new_messages(
old_blocks: &mut HashSet<BlockId>,
node: Url,
) -> Result<Vec<ChatMessage>, Box<dyn std::error::Error>> {
const NODE_CARNOT_INFO_PATH: &str = "consensus/info";
const NODE_CARNOT_INFO_PATH: &str = "carnot/info";
let mut new_messages = Vec::new();
@ -221,7 +230,7 @@ async fn fetch_new_messages(
let new_blocks = info
.committed_blocks
.into_iter()
.filter(|id| !old_blocks.contains(id))
.filter(|id| !old_blocks.contains(id) && id != BlockId::zeros())
.collect::<Vec<_>>();
// note that number of attestations is ignored here since we only use the da protocol to

View File

@ -8,6 +8,9 @@ use nomos_node::Tx;
use reqwest::Url;
use thiserror::Error;
const BLOCK_PATH: &str = "storage/block";
const BLOBS_PATH: &str = "da/blobs";
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
@ -30,7 +33,7 @@ pub async fn get_block_contents(
block: BlockId,
) -> Result<Option<Block<Tx, Certificate>>, reqwest::Error> {
let block = reqwest::Client::new()
.post(node.join("storage/block").unwrap())
.post(node.join(BLOCK_PATH).unwrap())
.body(serde_json::to_string(&block).unwrap())
.send()
.await?
@ -44,7 +47,7 @@ pub async fn get_blobs(
ids: Vec<<Blob as blob::Blob>::Hash>,
) -> Result<Vec<Blob>, reqwest::Error> {
reqwest::Client::new()
.post(node)
.post(node.join(BLOBS_PATH).unwrap())
.body(serde_json::to_string(&ids).unwrap())
.send()
.await?