pub struct PaymentGateway<S: Storage, M: MonerodClient = RpcClient>(/* private fields */);
Expand description
The PaymentGateway
allows you to track new Invoice
s, remove
old Invoice
s from tracking, and subscribe to Invoice
s that are already
pending.
Implementations§
Source§impl<S: Storage + 'static, M: MonerodClient + 'static> PaymentGateway<S, M>
impl<S: Storage + 'static, M: MonerodClient + 'static> PaymentGateway<S, M>
Sourcepub fn builder(
private_view_key: String,
primary_address: String,
store: S,
) -> PaymentGatewayBuilder<S>
pub fn builder( private_view_key: String, primary_address: String, store: S, ) -> PaymentGatewayBuilder<S>
Returns a builder used to create a new payment gateway.
Sourcepub async fn run(&self) -> Result<(), AcceptXmrError>
pub async fn run(&self) -> Result<(), AcceptXmrError>
Runs the payment gateway. This function spawns a new thread, which
periodically scans new blocks and transactions from the configured
daemon and updates pending Invoice
s in the database.
§Errors
-
Returns an
AcceptXmrError::Storage
error if there was an underlying issue with the database. -
Returns an
AcceptXmrError::Rpc
error if there was an issue getting necessary data from the monero daemon while starting. -
Returns an
AcceptXmrError::AlreadyRunning
error if the payment gateway is already running. -
Returns an
AcceptXmrError::Scanner
error if there was an error with the scanning thread.
Sourcepub async fn status(&self) -> PaymentGatewayStatus
pub async fn status(&self) -> PaymentGatewayStatus
Returns the enum PaymentGatewayStatus
describing whether the payment
gateway is running, not running, or has experienced an error.
Sourcepub async fn stop(&self) -> Result<(), AcceptXmrError>
pub async fn stop(&self) -> Result<(), AcceptXmrError>
Stops the payment gateway, blocking until complete. If the payment gateway is not running, this method does nothing.
§Errors
-
Returns an
AcceptXmrError::StopSignal
error if the payment gateway could not be stopped. -
If the scanning thread exited with an error, returns the error encountered.
Sourcepub async fn new_invoice(
&self,
piconeros: u64,
confirmations_required: u64,
expiration_in: u64,
description: String,
) -> Result<InvoiceId, AcceptXmrError>
pub async fn new_invoice( &self, piconeros: u64, confirmations_required: u64, expiration_in: u64, description: String, ) -> Result<InvoiceId, AcceptXmrError>
Adds a new Invoice
to the payment gateway for tracking, and returns
the ID of the new invoice. Use a Subscriber
to receive updates
on the new invoice invoice as they occur.
§Errors
Returns an error if there are any underlying issues modifying data in the database.
Sourcepub async fn remove_invoice(
&self,
invoice_id: InvoiceId,
) -> Result<Option<Invoice>, AcceptXmrError>
pub async fn remove_invoice( &self, invoice_id: InvoiceId, ) -> Result<Option<Invoice>, AcceptXmrError>
Remove (i.e. stop tracking) invoice, returning the old invoice if it existed.
§Errors
Returns an error if there are any underlying issues modifying/retrieving data in the database.
Sourcepub fn subscribe(&self, invoice_id: InvoiceId) -> Option<Subscriber>
pub fn subscribe(&self, invoice_id: InvoiceId) -> Option<Subscriber>
Returns a Subscriber
for the given invoice ID. If a tracked invoice
exists for that ID, the subscriber can be used to receive updates for
that invoice.
Sourcepub fn subscribe_all(&self) -> Subscriber ⓘ
pub fn subscribe_all(&self) -> Subscriber ⓘ
Returns a Subscriber
for all invoices.
Sourcepub async fn daemon_height(&self) -> Result<u64, AcceptXmrError>
pub async fn daemon_height(&self) -> Result<u64, AcceptXmrError>
Get current height of daemon using a monero daemon remote procedure call.
§Errors
Returns an error if a connection can not be made to the daemon, or if the daemon’s response cannot be parsed.
Sourcepub async fn get_invoice(
&self,
invoice_id: InvoiceId,
) -> Result<Option<Invoice>, AcceptXmrError>
pub async fn get_invoice( &self, invoice_id: InvoiceId, ) -> Result<Option<Invoice>, AcceptXmrError>
Sourcepub async fn get_invoice_ids(&self) -> Result<Vec<InvoiceId>, AcceptXmrError>
pub async fn get_invoice_ids(&self) -> Result<Vec<InvoiceId>, AcceptXmrError>
Get a list of all currently tracked invoice IDs.
§Errors
Returns an error if there are any underlying issues retrieving data from the database.
Sourcepub fn daemon_url(&self) -> String
pub fn daemon_url(&self) -> String
Returns URL of configured daemon.
Trait Implementations§
Source§impl<S: Storage, M: MonerodClient> Clone for PaymentGateway<S, M>
impl<S: Storage, M: MonerodClient> Clone for PaymentGateway<S, M>
Auto Trait Implementations§
impl<S, M> Freeze for PaymentGateway<S, M>
impl<S, M = RpcClient> !RefUnwindSafe for PaymentGateway<S, M>
impl<S, M> Send for PaymentGateway<S, M>
impl<S, M> Sync for PaymentGateway<S, M>
impl<S, M> Unpin for PaymentGateway<S, M>
impl<S, M = RpcClient> !UnwindSafe for PaymentGateway<S, M>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more