Struct MovementManager

Source
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

Source

pub fn new(db: Arc<dyn BarkPersister>) -> Self

Creates an instances of the MovementManager.

Source

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.

Source

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.

Source

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.
Source

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.

Source

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:

Source

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.

Source

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. Option fields will be ignored if they are None. Some will result in that particular field being overwritten.
  • at: The timestamp to set the [MovementTimestamp::completed_at] field to.

Errors:

Source

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.

Source

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:

Errors:

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,