logo
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Contains implementation of a standard payment contract implementation.
mod account_provider;
mod constants;
mod entry_points;
mod handle_payment_provider;
mod mint_provider;

use core::marker::Sized;

use crate::{ApiError, U512};

pub use crate::system::standard_payment::{
    account_provider::AccountProvider, constants::*, entry_points::standard_payment_entry_points,
    handle_payment_provider::HandlePaymentProvider, mint_provider::MintProvider,
};

/// Implementation of a standard payment contract.
pub trait StandardPayment: AccountProvider + MintProvider + HandlePaymentProvider + Sized {
    /// Pay `amount` to a payment purse.
    fn pay(&mut self, amount: U512) -> Result<(), ApiError> {
        let main_purse = self.get_main_purse()?;
        let payment_purse = self.get_payment_purse()?;
        self.transfer_purse_to_purse(main_purse, payment_purse, amount)
    }
}