pub struct MovementManager { /* private fields */ }Expand description
A minimalist helper class to handle movement registration and updating based on unique SubsystemId values.
Implementations§
Source§impl MovementManager
impl MovementManager
Sourcepub fn new(db: Arc<dyn BarkPersister>) -> Self
pub fn new(db: Arc<dyn BarkPersister>) -> Self
Creates an instances of the MovementManager.
Sourcepub async fn register_subsystem(
&self,
name: String,
) -> Result<SubsystemId, MovementError>
pub async fn register_subsystem( &self, name: String, ) -> Result<SubsystemId, MovementError>
Registers a subsystem with the movement manager. Subsystems are identified using unique names, to maintain this guarantee a unique SubsystemId will be generated and returned by this function. Future calls to register or modify movements must provide this ID.
Sourcepub async fn new_movement(
&self,
subsystem_id: SubsystemId,
movement_kind: String,
) -> Result<MovementId, MovementError>
pub async fn new_movement( &self, subsystem_id: SubsystemId, movement_kind: String, ) -> Result<MovementId, MovementError>
Similar to MovementManager::new_movement_at but it sets the [Movement::created_at] field to the current time.
Sourcepub async fn new_movement_at(
&self,
subsystem_id: SubsystemId,
movement_kind: String,
at: DateTime<Local>,
) -> Result<MovementId, MovementError>
pub async fn new_movement_at( &self, subsystem_id: SubsystemId, movement_kind: String, at: DateTime<Local>, ) -> Result<MovementId, MovementError>
Begins the process of creating a new movement. This newly created movement will be defaulted to a MovementStatus::Pending state. It can then be updated by using MovementUpdate in combination with MovementManager::update_movement.
MovementManager::finish_movement can be used once a movement has finished (whether successful or not).
Parameters:
- subsystem_id: The ID of the subsystem that wishes to start a new movement.
- movement_kind: A descriptor for the type of movement being performed, e.g. “send”, “receive”, “round”.
- at: The timestamp to set the [MovementTimestamp::created_at] field to.
Errors:
- If the subsystem ID is not recognized.
- If a database error occurs.
Sourcepub async fn new_finished_movement(
&self,
subsystem_id: SubsystemId,
movement_kind: String,
status: MovementStatus,
details: MovementUpdate,
) -> Result<MovementId, MovementError>
pub async fn new_finished_movement( &self, subsystem_id: SubsystemId, movement_kind: String, status: MovementStatus, details: MovementUpdate, ) -> Result<MovementId, MovementError>
Similar to MovementManager::new_finished_movement_at but it sets the [Movement::created_at] field to the current time.
Sourcepub async fn new_finished_movement_at(
&self,
subsystem_id: SubsystemId,
movement_kind: String,
status: MovementStatus,
details: MovementUpdate,
at: DateTime<Local>,
) -> Result<MovementId, MovementError>
pub async fn new_finished_movement_at( &self, subsystem_id: SubsystemId, movement_kind: String, status: MovementStatus, details: MovementUpdate, at: DateTime<Local>, ) -> Result<MovementId, MovementError>
Creates and marks a Movement as finished based on the given parameters. This is useful for one-shot movements where the details are known at time of creation, an example would be when receiving funds asynchronously from a third party.
Parameters:
- subsystem_id: The ID of the subsystem that wishes to start a new movement.
- movement_kind: A descriptor for the type of movement being performed, e.g. “send”, “receive”, “round”.
- status: The MovementStatus to set. This can’t be MovementStatus::Pending.
- details: Contains information about the movement, e.g. what VTXOs were consumed or produced.
- at: The timestamp to set the Movement::time field to.
Errors:
- If the subsystem ID is not recognized.
- If MovementStatus::Pending is given.
- If a database error occurs.
Sourcepub async fn update_movement(
&self,
id: MovementId,
update: MovementUpdate,
) -> Result<(), MovementError>
pub async fn update_movement( &self, id: MovementId, update: MovementUpdate, ) -> Result<(), MovementError>
Similar to MovementManager::update_movement_at but it sets the [MovementTimestamp::updated_at] field to the current time.
Sourcepub async fn update_movement_at(
&self,
id: MovementId,
update: MovementUpdate,
at: DateTime<Local>,
) -> Result<(), MovementError>
pub async fn update_movement_at( &self, id: MovementId, update: MovementUpdate, at: DateTime<Local>, ) -> Result<(), MovementError>
Updates a movement with the given parameters.
See also: [MovementManager::create_movement] and MovementManager::finish_movement
Parameters:
- id: The ID of the movement previously created by MovementManager::new_movement.
- update: Specifies properties to set on the movement.
Optionfields will be ignored if they areNone.Somewill result in that particular field being overwritten. - at: The timestamp to set the [MovementTimestamp::completed_at] field to.
Errors:
- If the MovementId is not recognized.
- If a movement is not MovementStatus::Pending.
- If a database error occurs.
Sourcepub async fn finish_movement(
&self,
id: MovementId,
new_status: MovementStatus,
) -> Result<(), MovementError>
pub async fn finish_movement( &self, id: MovementId, new_status: MovementStatus, ) -> Result<(), MovementError>
Similar to MovementManager::finish_movement but it sets the [MovementTimestamp::completed_at] field to the current time.
Sourcepub async fn finish_movement_at(
&self,
id: MovementId,
new_status: MovementStatus,
at: DateTime<Local>,
) -> Result<(), MovementError>
pub async fn finish_movement_at( &self, id: MovementId, new_status: MovementStatus, at: DateTime<Local>, ) -> Result<(), MovementError>
Finalizes a movement, setting it to the given MovementStatus.
See also: [MovementManager::create_movement] and MovementManager::update_movement
Parameters:
- id: The ID of the movement previously created by MovementManager::new_movement.
- new_status: The final MovementStatus to set. This can’t be MovementStatus::Pending.
- at: The timestamp to set the [MovementTimestamp::completed_at] field to.
Errors:
- If the movement ID is not recognized.
- If MovementStatus::Pending is given.
- If a database error occurs.
Auto Trait Implementations§
impl !Freeze for MovementManager
impl !RefUnwindSafe for MovementManager
impl Send for MovementManager
impl Sync for MovementManager
impl Unpin for MovementManager
impl !UnwindSafe for MovementManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request