order.rs (6102B)
1 pub use radroots_events::ids::{RadrootsIdParseError, RadrootsListingAddress}; 2 pub use radroots_events::order::*; 3 pub use radroots_events::trade_validation::*; 4 pub use radroots_events_codec::error::EventEncodeError; 5 #[cfg(feature = "serde_json")] 6 pub use radroots_events_codec::order::{ 7 RadrootsOrderEnvelopeParseError, RadrootsOrderEventContext, 8 }; 9 pub use radroots_trade::listing::validation::RadrootsTradeListing as TradeListingValidateResult; 10 11 #[cfg(feature = "serde_json")] 12 use radroots_events::{RadrootsNostrEvent, RadrootsNostrEventPtr, ids::RadrootsEventId}; 13 use radroots_events_codec::wire::WireEventParts; 14 15 #[derive(Debug, Clone)] 16 pub struct RadrootsOrderRequestDraft { 17 parts: WireEventParts, 18 } 19 20 #[derive(Debug, Clone)] 21 pub struct RadrootsOrderDecisionDraft { 22 parts: WireEventParts, 23 } 24 25 #[derive(Debug, Clone)] 26 pub struct RadrootsOrderRevisionProposalDraft { 27 parts: WireEventParts, 28 } 29 30 #[derive(Debug, Clone)] 31 pub struct RadrootsOrderRevisionDecisionDraft { 32 parts: WireEventParts, 33 } 34 35 #[derive(Debug, Clone)] 36 pub struct RadrootsOrderCancellationDraft { 37 parts: WireEventParts, 38 } 39 40 impl RadrootsOrderRequestDraft { 41 pub fn as_wire_parts(&self) -> &WireEventParts { 42 &self.parts 43 } 44 45 pub fn into_wire_parts(self) -> WireEventParts { 46 self.parts 47 } 48 } 49 50 impl RadrootsOrderDecisionDraft { 51 pub fn as_wire_parts(&self) -> &WireEventParts { 52 &self.parts 53 } 54 55 pub fn into_wire_parts(self) -> WireEventParts { 56 self.parts 57 } 58 } 59 60 impl RadrootsOrderRevisionProposalDraft { 61 pub fn as_wire_parts(&self) -> &WireEventParts { 62 &self.parts 63 } 64 65 pub fn into_wire_parts(self) -> WireEventParts { 66 self.parts 67 } 68 } 69 70 impl RadrootsOrderRevisionDecisionDraft { 71 pub fn as_wire_parts(&self) -> &WireEventParts { 72 &self.parts 73 } 74 75 pub fn into_wire_parts(self) -> WireEventParts { 76 self.parts 77 } 78 } 79 80 impl RadrootsOrderCancellationDraft { 81 pub fn as_wire_parts(&self) -> &WireEventParts { 82 &self.parts 83 } 84 85 pub fn into_wire_parts(self) -> WireEventParts { 86 self.parts 87 } 88 } 89 90 #[cfg(feature = "serde_json")] 91 pub fn build_order_request_draft( 92 listing_event: &RadrootsNostrEventPtr, 93 payload: &RadrootsOrderRequest, 94 ) -> Result<RadrootsOrderRequestDraft, EventEncodeError> { 95 Ok(RadrootsOrderRequestDraft { 96 parts: radroots_events_codec::order::order_request_event_build(listing_event, payload)?, 97 }) 98 } 99 100 #[cfg(feature = "serde_json")] 101 pub fn build_order_decision_draft( 102 root_event_id: &RadrootsEventId, 103 prev_event_id: &RadrootsEventId, 104 payload: &RadrootsOrderDecision, 105 ) -> Result<RadrootsOrderDecisionDraft, EventEncodeError> { 106 Ok(RadrootsOrderDecisionDraft { 107 parts: radroots_events_codec::order::order_decision_event_build( 108 root_event_id, 109 prev_event_id, 110 payload, 111 )?, 112 }) 113 } 114 115 #[cfg(feature = "serde_json")] 116 pub fn build_order_revision_proposal_draft( 117 root_event_id: &RadrootsEventId, 118 prev_event_id: &RadrootsEventId, 119 payload: &RadrootsOrderRevisionProposal, 120 ) -> Result<RadrootsOrderRevisionProposalDraft, EventEncodeError> { 121 Ok(RadrootsOrderRevisionProposalDraft { 122 parts: radroots_events_codec::order::order_revision_proposal_event_build( 123 root_event_id, 124 prev_event_id, 125 payload, 126 )?, 127 }) 128 } 129 130 #[cfg(feature = "serde_json")] 131 pub fn build_order_revision_decision_draft( 132 root_event_id: &RadrootsEventId, 133 prev_event_id: &RadrootsEventId, 134 payload: &RadrootsOrderRevisionDecision, 135 ) -> Result<RadrootsOrderRevisionDecisionDraft, EventEncodeError> { 136 Ok(RadrootsOrderRevisionDecisionDraft { 137 parts: radroots_events_codec::order::order_revision_decision_event_build( 138 root_event_id, 139 prev_event_id, 140 payload, 141 )?, 142 }) 143 } 144 145 #[cfg(feature = "serde_json")] 146 pub fn build_order_cancellation_draft( 147 root_event_id: &RadrootsEventId, 148 prev_event_id: &RadrootsEventId, 149 payload: &RadrootsOrderCancellation, 150 ) -> Result<RadrootsOrderCancellationDraft, EventEncodeError> { 151 Ok(RadrootsOrderCancellationDraft { 152 parts: radroots_events_codec::order::order_cancellation_event_build( 153 root_event_id, 154 prev_event_id, 155 payload, 156 )?, 157 }) 158 } 159 160 #[cfg(feature = "serde_json")] 161 pub fn parse_order_request( 162 event: &RadrootsNostrEvent, 163 ) -> Result<RadrootsOrderEnvelope<RadrootsOrderRequest>, RadrootsOrderEnvelopeParseError> { 164 radroots_events_codec::order::order_request_from_event(event) 165 } 166 167 #[cfg(feature = "serde_json")] 168 pub fn parse_order_decision( 169 event: &RadrootsNostrEvent, 170 ) -> Result<RadrootsOrderEnvelope<RadrootsOrderDecision>, RadrootsOrderEnvelopeParseError> { 171 radroots_events_codec::order::order_decision_from_event(event) 172 } 173 174 #[cfg(feature = "serde_json")] 175 pub fn parse_order_revision_proposal( 176 event: &RadrootsNostrEvent, 177 ) -> Result<RadrootsOrderEnvelope<RadrootsOrderRevisionProposal>, RadrootsOrderEnvelopeParseError> { 178 radroots_events_codec::order::order_revision_proposal_from_event(event) 179 } 180 181 #[cfg(feature = "serde_json")] 182 pub fn parse_order_revision_decision( 183 event: &RadrootsNostrEvent, 184 ) -> Result<RadrootsOrderEnvelope<RadrootsOrderRevisionDecision>, RadrootsOrderEnvelopeParseError> { 185 radroots_events_codec::order::order_revision_decision_from_event(event) 186 } 187 188 #[cfg(feature = "serde_json")] 189 pub fn parse_order_cancellation( 190 event: &RadrootsNostrEvent, 191 ) -> Result<RadrootsOrderEnvelope<RadrootsOrderCancellation>, RadrootsOrderEnvelopeParseError> { 192 radroots_events_codec::order::order_cancellation_from_event(event) 193 } 194 195 #[cfg(feature = "serde_json")] 196 pub fn parse_listing_address( 197 listing_addr: &str, 198 ) -> Result<RadrootsListingAddress, RadrootsIdParseError> { 199 RadrootsListingAddress::parse(listing_addr) 200 } 201 202 #[cfg(feature = "serde_json")] 203 pub fn validate_listing_event( 204 event: &RadrootsNostrEvent, 205 ) -> Result<TradeListingValidateResult, RadrootsTradeValidationListingError> { 206 radroots_trade::listing::validation::validate_listing_event(event) 207 }