Skip to content

Commit

Permalink
Tweaks and add request children
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 17, 2024
1 parent 134ab7a commit ef76e5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 0 additions & 2 deletions crates/chia-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ mod event;
mod network;
mod peer;
mod request_map;
mod response;
mod tls;

pub use client::*;
pub use error::*;
pub use event::*;
pub use network::*;
pub use peer::*;
pub use response::*;
pub use tls::*;
23 changes: 14 additions & 9 deletions crates/chia-client/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::{fmt, net::IpAddr, sync::Arc};
use chia_protocol::{
Bytes32, ChiaProtocolMessage, CoinStateFilters, Message, PuzzleSolutionResponse,
RegisterForCoinUpdates, RegisterForPhUpdates, RejectCoinState, RejectPuzzleSolution,
RejectPuzzleState, RequestCoinState, RequestPeers, RequestPuzzleSolution, RequestPuzzleState,
RequestTransaction, RespondCoinState, RespondPeers, RespondPuzzleSolution, RespondPuzzleState,
RespondToCoinUpdates, RespondToPhUpdates, RespondTransaction, SendTransaction, SpendBundle,
TransactionAck,
RejectPuzzleState, RequestChildren, RequestCoinState, RequestPeers, RequestPuzzleSolution,
RequestPuzzleState, RequestTransaction, RespondChildren, RespondCoinState, RespondPeers,
RespondPuzzleSolution, RespondPuzzleState, RespondToCoinUpdates, RespondToPhUpdates,
RespondTransaction, SendTransaction, SpendBundle, TransactionAck,
};
use chia_traits::Streamable;
use futures_util::{
Expand All @@ -22,11 +22,12 @@ use tokio::{
};
use tokio_tungstenite::{Connector, MaybeTlsStream, WebSocketStream};

use crate::{request_map::RequestMap, Error, Response, Result};
use crate::{request_map::RequestMap, Error, Result};

type WebSocket = WebSocketStream<MaybeTlsStream<TcpStream>>;
type Sink = SplitSink<WebSocket, tungstenite::Message>;
type Stream = SplitStream<WebSocket>;
type Response<T, E> = std::result::Result<T, E>;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PeerId([u8; 32]);
Expand Down Expand Up @@ -199,11 +200,15 @@ impl Peer {
))
.await?
{
Response::Success(response) => Ok(Response::Success(response.response)),
Response::Rejection(rejection) => Ok(Response::Rejection(rejection)),
Ok(response) => Ok(Ok(response.response)),
Err(rejection) => Ok(Err(rejection)),
}
}

pub async fn request_children(&self, coin_id: Bytes32) -> Result<RespondChildren> {
self.request_infallible(RequestChildren::new(coin_id)).await
}

pub async fn request_peers(&self) -> Result<RespondPeers> {
self.request_infallible(RequestPeers::new()).await
}
Expand Down Expand Up @@ -235,9 +240,9 @@ impl Peer {
));
}
if message.msg_type == T::msg_type() {
Ok(Response::Success(T::from_bytes(&message.data)?))
Ok(Ok(T::from_bytes(&message.data)?))
} else {
Ok(Response::Rejection(E::from_bytes(&message.data)?))
Ok(Err(E::from_bytes(&message.data)?))
}
}

Expand Down
5 changes: 0 additions & 5 deletions crates/chia-client/src/response.rs

This file was deleted.

0 comments on commit ef76e5e

Please sign in to comment.