Finish the tree logic in the transaction-chaining scheduler

Also completes the DB functions, makes Scheduler never instantiated, and
ensures tree roots have change outputs.
This commit is contained in:
Luke Parker
2024-09-04 01:44:21 -04:00
parent 8ff019265f
commit 653ead1e8c
6 changed files with 477 additions and 368 deletions

View File

@@ -1,3 +1,7 @@
use std::io;
use scale::{Encode, Decode, IoReader};
use serai_primitives::{Balance, Data};
use serai_coins_primitives::OutInstructionWithBalance;
@@ -27,6 +31,7 @@ impl<A: Address> Payment<A> {
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
@@ -39,4 +44,20 @@ impl<A: Address> Payment<A> {
pub fn data(&self) -> &Option<Vec<u8>> {
&self.data
}
/// Read a Payment.
pub fn read(reader: &mut impl io::Read) -> io::Result<Self> {
let address = A::read(reader)?;
let reader = &mut IoReader(reader);
let balance = Balance::decode(reader).map_err(io::Error::other)?;
let data = Option::<Vec<u8>>::decode(reader).map_err(io::Error::other)?;
Ok(Self { address, balance, data })
}
/// Write the Payment.
pub fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
self.address.write(writer).unwrap();
self.balance.encode_to(writer);
self.data.encode_to(writer);
Ok(())
}
}