|
| 1 | +use derive_builder::Builder; |
| 2 | +use prost::Message; |
| 3 | +use std::borrow::Cow; |
| 4 | +use xmtp_proto::traits::{BodyError, Endpoint}; |
| 5 | +use xmtp_proto::xmtp::xmtpv4::message_api::EnvelopesQuery; |
| 6 | +use xmtp_proto::xmtp::xmtpv4::message_api::FILE_DESCRIPTOR_SET; |
| 7 | +use xmtp_proto::xmtp::xmtpv4::message_api::{QueryEnvelopesRequest, QueryEnvelopesResponse}; |
| 8 | + |
| 9 | +/// Query a single thing |
| 10 | +#[derive(Debug, Builder, Default, Clone)] |
| 11 | +pub struct QueryEnvelope { |
| 12 | + #[builder(setter(into))] |
| 13 | + topics: Vec<Vec<u8>>, |
| 14 | + #[builder(setter(into))] |
| 15 | + originator_node_ids: Vec<u32>, |
| 16 | +} |
| 17 | + |
| 18 | +impl QueryEnvelope { |
| 19 | + pub fn builder() -> QueryEnvelopeBuilder { |
| 20 | + Default::default() |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +impl Endpoint for QueryEnvelope { |
| 25 | + type Output = QueryEnvelopesResponse; |
| 26 | + |
| 27 | + fn http_endpoint(&self) -> Cow<'static, str> { |
| 28 | + todo!() |
| 29 | + } |
| 30 | + |
| 31 | + fn grpc_endpoint(&self) -> Cow<'static, str> { |
| 32 | + crate::path_and_query::<QueryEnvelopesRequest>(FILE_DESCRIPTOR_SET) |
| 33 | + } |
| 34 | + |
| 35 | + fn body(&self) -> Result<Vec<u8>, BodyError> { |
| 36 | + Ok(QueryEnvelopesRequest { |
| 37 | + query: Some(EnvelopesQuery { |
| 38 | + topics: self.topics.clone(), |
| 39 | + originator_node_ids: self.originator_node_ids.clone(), |
| 40 | + last_seen: None, |
| 41 | + }), |
| 42 | + limit: 1, |
| 43 | + } |
| 44 | + .encode_to_vec()) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +/// Batch Query |
| 49 | +#[derive(Debug, Builder, Default)] |
| 50 | +#[builder(setter(strip_option))] |
| 51 | +pub struct QueryEnvelopes { |
| 52 | + #[builder(setter(into))] |
| 53 | + envelopes: EnvelopesQuery, |
| 54 | + #[builder(setter(into))] |
| 55 | + limit: u32, |
| 56 | +} |
| 57 | + |
| 58 | +impl QueryEnvelopes { |
| 59 | + pub fn builder() -> QueryEnvelopesBuilder { |
| 60 | + Default::default() |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +impl Endpoint for QueryEnvelopes { |
| 65 | + type Output = QueryEnvelopesResponse; |
| 66 | + |
| 67 | + fn http_endpoint(&self) -> Cow<'static, str> { |
| 68 | + todo!() |
| 69 | + } |
| 70 | + |
| 71 | + fn grpc_endpoint(&self) -> Cow<'static, str> { |
| 72 | + crate::path_and_query::<QueryEnvelopesRequest>(FILE_DESCRIPTOR_SET) |
| 73 | + } |
| 74 | + |
| 75 | + fn body(&self) -> Result<Vec<u8>, BodyError> { |
| 76 | + Ok(QueryEnvelopesRequest { |
| 77 | + query: Some(self.envelopes.clone()), |
| 78 | + limit: self.limit, |
| 79 | + } |
| 80 | + .encode_to_vec()) |
| 81 | + } |
| 82 | +} |
0 commit comments