dispatch.rs (3829B)
1 //! The fresh native permit owns its one original exact-issuance invocation. 2 use super::{OperationError, StockDispatchPermit, StockSigningAttempt}; 3 use radroots_signing::{ 4 issuance::{ExactIssuer, OutcomeKind, RejectedArtifact, SignedArtifact}, 5 provider::ProviderError, 6 request::CancellationSignal, 7 signer::BoxFuture, 8 }; 9 10 /// Live observation from the owned original invocation on a qualified issuer. 11 /// Private construction prevents caller reports or later recovery refusals from 12 /// becoming this observation. It is neither durable evidence nor an operation- 13 /// wide/global nonissuance guarantee, and cannot release any stock by itself. 14 /// 15 /// ```compile_fail 16 /// use radroots_storage_sqlite::workspace::{StockSigningAttempt, StockUnissuedInvocation}; 17 /// fn forge(attempt: StockSigningAttempt) -> StockUnissuedInvocation { 18 /// StockUnissuedInvocation { attempt, reason: radroots_signing::provider::ProviderError::Cancelled } 19 /// } 20 /// ``` 21 /// ```compile_fail 22 /// use radroots_storage_sqlite::workspace::StockUnissuedInvocation; 23 /// fn duplicate(value: StockUnissuedInvocation) -> (StockUnissuedInvocation, StockUnissuedInvocation) { 24 /// (value.clone(), value) 25 /// } 26 /// ``` 27 pub struct StockUnissuedInvocation { 28 attempt: StockSigningAttempt, 29 reason: ProviderError, 30 } 31 impl StockUnissuedInvocation { 32 pub const fn attempt(&self) -> &StockSigningAttempt { 33 &self.attempt 34 } 35 pub const fn reason(&self) -> ProviderError { 36 self.reason 37 } 38 } 39 impl core::fmt::Debug for StockUnissuedInvocation { 40 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 41 f.write_str("StockUnissuedInvocation(<redacted>)") 42 } 43 } 44 45 /// Independent original invocation facts. None implies durable S or T2. 46 #[derive(Debug)] 47 pub enum StockDispatchOutcome { 48 Obtained { 49 attempt: StockSigningAttempt, 50 artifact: SignedArtifact, 51 }, 52 Unissued(StockUnissuedInvocation), 53 Unknown { 54 attempt: StockSigningAttempt, 55 reason: ProviderError, 56 }, 57 Rejected { 58 attempt: StockSigningAttempt, 59 rejection: RejectedArtifact, 60 }, 61 } 62 impl StockDispatchPermit { 63 /// Consumes the actual newly confirmed permit and invokes this issuer once. 64 /// The selected issuer must be qualified for its reported outcomes. Losing 65 /// this wait retains the durable claim's uncertainty; no second permit is 66 /// created. Exact recovery never enters this method. Caller-provided outcome 67 /// values cannot construct its original unissued observation. 68 pub fn dispatch( 69 self, 70 issuer: &dyn ExactIssuer, 71 cancellation: CancellationSignal, 72 ) -> BoxFuture<'_, Result<StockDispatchOutcome, OperationError>> { 73 Box::pin(async move { 74 let (intent, attempt) = self.into_intent(cancellation)?; 75 let binding = attempt.binding(); 76 let (_, kind) = issuer 77 .issue_exact(intent) 78 .await 79 .enforce_binding(binding) 80 .into_parts(); 81 Ok(match kind { 82 OutcomeKind::Obtained(artifact) => { 83 StockDispatchOutcome::Obtained { attempt, artifact } 84 } 85 OutcomeKind::NotDispatched(reason) => { 86 StockDispatchOutcome::Unissued(StockUnissuedInvocation { attempt, reason }) 87 } 88 OutcomeKind::Unknown(reason) => StockDispatchOutcome::Unknown { attempt, reason }, 89 OutcomeKind::Rejected(rejection) => { 90 StockDispatchOutcome::Rejected { attempt, rejection } 91 } 92 _ => StockDispatchOutcome::Unknown { 93 attempt, 94 reason: ProviderError::ProviderFailure, 95 }, 96 }) 97 }) 98 } 99 }