canic_core/api/intent/
mod.rs1use crate::{
8 dto::error::Error,
9 workflow::runtime::intent::{LocalIntentWorkflow, ReceiptBackedIntentWorkflow},
10};
11
12pub use crate::{
13 ids::{IntentId, IntentResourceKey},
14 model::{
15 intent::{
16 BeginLocalIntentInput, BeginReceiptBackedIntentInput, BeginReceiptBackedIntentResult,
17 PayloadBinding, ReceiptBackedIntent, ReceiptBackedIntentState,
18 SettleReceiptBackedIntentInput, SettleReceiptBackedIntentResult, TerminalEvidence,
19 TerminalEvidenceDecision,
20 },
21 replay::OperationId,
22 },
23};
24
25pub struct LocalIntentApi;
27
28impl LocalIntentApi {
29 pub fn begin(input: BeginLocalIntentInput) -> Result<IntentId, Error> {
30 LocalIntentWorkflow::begin(input).map_err(Error::from)
31 }
32
33 pub fn commit(intent_id: IntentId) -> Result<(), Error> {
34 LocalIntentWorkflow::commit(intent_id).map_err(Error::from)
35 }
36
37 pub fn rollback(intent_id: IntentId) -> Result<(), Error> {
38 LocalIntentWorkflow::rollback(intent_id).map_err(Error::from)
39 }
40}
41
42pub struct ReceiptBackedIntentApi;
44
45impl ReceiptBackedIntentApi {
46 pub fn begin_or_load(
47 input: &BeginReceiptBackedIntentInput,
48 ) -> Result<BeginReceiptBackedIntentResult, Error> {
49 ReceiptBackedIntentWorkflow::begin_or_load(input).map_err(Error::from)
50 }
51
52 pub fn load(operation_id: OperationId) -> Result<Option<ReceiptBackedIntent>, Error> {
53 ReceiptBackedIntentWorkflow::load(operation_id).map_err(Error::from)
54 }
55
56 pub fn settle_if_pending(
57 input: &SettleReceiptBackedIntentInput,
58 ) -> Result<SettleReceiptBackedIntentResult, Error> {
59 ReceiptBackedIntentWorkflow::settle_if_pending(input).map_err(Error::from)
60 }
61}