mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Outline of the transaction-chaining scheduler
This commit is contained in:
@@ -22,6 +22,7 @@ async-trait = { version = "0.1", default-features = false }
|
||||
group = { version = "0.13", default-features = false }
|
||||
|
||||
serai-primitives = { path = "../../substrate/primitives", default-features = false, features = ["std"] }
|
||||
serai-coins-primitives = { path = "../../substrate/coins/primitives", default-features = false, features = ["std"] }
|
||||
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std"] }
|
||||
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
||||
|
||||
@@ -21,6 +21,9 @@ pub use eventuality::*;
|
||||
mod block;
|
||||
pub use block::*;
|
||||
|
||||
mod payment;
|
||||
pub use payment::*;
|
||||
|
||||
/// An ID for an output/transaction/block/etc.
|
||||
///
|
||||
/// IDs don't need to implement `Copy`, enabling `[u8; 33]`, `[u8; 64]` to be used. IDs are still
|
||||
|
||||
42
processor/primitives/src/payment.rs
Normal file
42
processor/primitives/src/payment.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use serai_primitives::{Balance, Data};
|
||||
use serai_coins_primitives::OutInstructionWithBalance;
|
||||
|
||||
use crate::Address;
|
||||
|
||||
/// A payment to fulfill.
|
||||
#[derive(Clone)]
|
||||
pub struct Payment<A: Address> {
|
||||
address: A,
|
||||
balance: Balance,
|
||||
data: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl<A: Address> TryFrom<OutInstructionWithBalance> for Payment<A> {
|
||||
type Error = ();
|
||||
fn try_from(out_instruction_with_balance: OutInstructionWithBalance) -> Result<Self, ()> {
|
||||
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<A: Address> Payment<A> {
|
||||
/// Create a new Payment.
|
||||
pub fn new(address: A, balance: Balance, data: Option<Vec<u8>>) -> 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<Vec<u8>> {
|
||||
&self.data
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user