Remove Output::amount and move Payment from Amount to Balance

This code is still largely designed around the idea a payment for a network is
fungible with any other, which isn't true. This starts moving past that.

Asserts are added to ensure the integrity of coin to the scheduler (which is
now per key per coin, not per key alone) and in Bitcoin/Monero prepare_send.
This commit is contained in:
Luke Parker
2023-11-08 23:33:25 -05:00
parent ffedba7a05
commit 7d72e224f0
10 changed files with 201 additions and 87 deletions

View File

@@ -5,10 +5,9 @@ use ciphersuite::Ciphersuite;
pub use serai_db::*;
use scale::{Encode, Decode};
#[rustfmt::skip]
use serai_client::{
primitives::ExternalAddress,
in_instructions::primitives::InInstructionWithBalance
primitives::{Balance, ExternalAddress},
in_instructions::primitives::InInstructionWithBalance,
};
use crate::{
@@ -172,23 +171,23 @@ impl<N: Network, D: Db> MultisigsDb<N, D> {
res
}
fn forwarded_output_key(amount: u64) -> Vec<u8> {
Self::multisigs_key(b"forwarded_output", amount.to_le_bytes())
fn forwarded_output_key(balance: Balance) -> Vec<u8> {
Self::multisigs_key(b"forwarded_output", balance.encode())
}
pub fn save_forwarded_output(
txn: &mut D::Transaction<'_>,
instruction: InInstructionWithBalance,
) {
let key = Self::forwarded_output_key(instruction.balance.amount.0);
let key = Self::forwarded_output_key(instruction.balance);
let mut existing = txn.get(&key).unwrap_or(vec![]);
existing.extend(instruction.encode());
txn.put(key, existing);
}
pub fn take_forwarded_output(
txn: &mut D::Transaction<'_>,
amount: u64,
balance: Balance,
) -> Option<InInstructionWithBalance> {
let key = Self::forwarded_output_key(amount);
let key = Self::forwarded_output_key(balance);
let outputs = txn.get(&key)?;
let mut outputs_ref = outputs.as_slice();