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

@@ -10,6 +10,8 @@ use frost::{
use serai_db::{DbTxn, Db, MemDb};
use serai_client::primitives::{NetworkId, Coin, Amount, Balance};
use messages::sign::*;
use crate::{
Payment, Plan,
@@ -170,7 +172,19 @@ pub async fn test_signer<N: Network>(network: N) {
Plan {
key,
inputs: outputs.clone(),
payments: vec![Payment { address: N::address(key), data: None, amount }],
payments: vec![Payment {
address: N::address(key),
data: None,
balance: Balance {
coin: match N::NETWORK {
NetworkId::Serai => panic!("test_signer called with Serai"),
NetworkId::Bitcoin => Coin::Bitcoin,
NetworkId::Ethereum => Coin::Ether,
NetworkId::Monero => Coin::Monero,
},
amount: Amount(amount),
},
}],
change: Some(N::change_address(key)),
},
0,
@@ -201,7 +215,7 @@ pub async fn test_signer<N: Network>(network: N) {
// Adjust the amount for the fees
let amount = amount - tx.fee(&network).await;
// Check either output since Monero will randomize its output order
assert!((outputs[0].amount() == amount) || (outputs[1].amount() == amount));
assert!((outputs[0].balance().amount.0 == amount) || (outputs[1].balance().amount.0 == amount));
// Check the eventualities pass
for eventuality in eventualities {