use serai_primitives::{Balance, Data}; use serai_coins_primitives::OutInstructionWithBalance; use crate::Address; /// A payment to fulfill. #[derive(Clone)] pub struct Payment { address: A, balance: Balance, data: Option>, } impl TryFrom for Payment { type Error = (); fn try_from(out_instruction_with_balance: OutInstructionWithBalance) -> Result { Ok(Payment { address: out_instruction_with_balance.instruction.address.try_into().map_err(|_| ())?, balance: out_instruction_with_balance.balance, data: out_instruction_with_balance.instruction.data.map(Data::consume), }) } } impl Payment { /// Create a new Payment. pub fn new(address: A, balance: Balance, data: Option>) -> Self { Payment { address, balance, data } } /// The address to pay. pub fn address(&self) -> &A { &self.address } /// The balance to transfer. pub fn balance(&self) -> Balance { self.balance } /// The data to associate with this payment. pub fn data(&self) -> &Option> { &self.data } }