diff --git a/crates/chia-client/src/lib.rs b/crates/chia-client/src/lib.rs index 3c990dc94..de7c1f601 100644 --- a/crates/chia-client/src/lib.rs +++ b/crates/chia-client/src/lib.rs @@ -4,7 +4,6 @@ mod event; mod network; mod peer; mod request_map; -mod response; mod tls; pub use client::*; @@ -12,5 +11,4 @@ pub use error::*; pub use event::*; pub use network::*; pub use peer::*; -pub use response::*; pub use tls::*; diff --git a/crates/chia-client/src/peer.rs b/crates/chia-client/src/peer.rs index 58db888d0..29b958cb3 100644 --- a/crates/chia-client/src/peer.rs +++ b/crates/chia-client/src/peer.rs @@ -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::{ @@ -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>; type Sink = SplitSink; type Stream = SplitStream; +type Response = std::result::Result; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct PeerId([u8; 32]); @@ -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 { + self.request_infallible(RequestChildren::new(coin_id)).await + } + pub async fn request_peers(&self) -> Result { self.request_infallible(RequestPeers::new()).await } @@ -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)?)) } } diff --git a/crates/chia-client/src/response.rs b/crates/chia-client/src/response.rs deleted file mode 100644 index f09f3add0..000000000 --- a/crates/chia-client/src/response.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[derive(Debug, Clone, Copy)] -pub enum Response { - Success(T), - Rejection(E), -}