mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
add specific network/coin/balance types (#619)
* add specific network/coin/balance types * misc fixes * fix clippy * misc fixes * fix pr comments * Make halting for external networks * fix encode/decode
This commit is contained in:
@@ -17,7 +17,7 @@ use frost_schnorrkel::Schnorrkel;
|
||||
use log::{info, debug, warn};
|
||||
|
||||
use serai_client::{
|
||||
primitives::{NetworkId, BlockHash},
|
||||
primitives::{ExternalNetworkId, BlockHash},
|
||||
in_instructions::primitives::{Batch, SignedBatch, batch_message},
|
||||
validator_sets::primitives::Session,
|
||||
};
|
||||
@@ -41,7 +41,7 @@ type SignatureShare = <AlgorithmSignMachine<Ristretto, Schnorrkel> as SignMachin
|
||||
pub struct BatchSigner<D: Db> {
|
||||
db: PhantomData<D>,
|
||||
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
session: Session,
|
||||
keys: Vec<ThresholdKeys<Ristretto>>,
|
||||
|
||||
@@ -65,7 +65,7 @@ impl<D: Db> fmt::Debug for BatchSigner<D> {
|
||||
|
||||
impl<D: Db> BatchSigner<D> {
|
||||
pub fn new(
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
session: Session,
|
||||
keys: Vec<ThresholdKeys<Ristretto>>,
|
||||
) -> BatchSigner<D> {
|
||||
|
||||
@@ -9,7 +9,7 @@ use log::{info, warn};
|
||||
use tokio::time::sleep;
|
||||
|
||||
use serai_client::{
|
||||
primitives::{BlockHash, NetworkId},
|
||||
primitives::{BlockHash, ExternalNetworkId},
|
||||
validator_sets::primitives::{Session, KeyPair},
|
||||
};
|
||||
|
||||
@@ -736,19 +736,23 @@ async fn main() {
|
||||
"http://".to_string() + &login + "@" + &hostname + ":" + &port
|
||||
};
|
||||
let network_id = match env::var("NETWORK").expect("network wasn't specified").as_str() {
|
||||
"bitcoin" => NetworkId::Bitcoin,
|
||||
"ethereum" => NetworkId::Ethereum,
|
||||
"monero" => NetworkId::Monero,
|
||||
"bitcoin" => ExternalNetworkId::Bitcoin,
|
||||
"ethereum" => ExternalNetworkId::Ethereum,
|
||||
"monero" => ExternalNetworkId::Monero,
|
||||
_ => panic!("unrecognized network"),
|
||||
};
|
||||
|
||||
let coordinator = MessageQueue::from_env(Service::Processor(network_id));
|
||||
|
||||
// This allow is necessary since each configuration deletes the other networks from the following
|
||||
// match arms. So we match all cases but since all cases already there according to the compiler
|
||||
// we put this to allow clippy to get pass this.
|
||||
#[allow(unreachable_patterns)]
|
||||
match network_id {
|
||||
#[cfg(feature = "bitcoin")]
|
||||
NetworkId::Bitcoin => run(db, Bitcoin::new(url).await, coordinator).await,
|
||||
ExternalNetworkId::Bitcoin => run(db, Bitcoin::new(url).await, coordinator).await,
|
||||
#[cfg(feature = "ethereum")]
|
||||
NetworkId::Ethereum => {
|
||||
ExternalNetworkId::Ethereum => {
|
||||
let relayer_hostname = env::var("ETHEREUM_RELAYER_HOSTNAME")
|
||||
.expect("ethereum relayer hostname wasn't specified")
|
||||
.to_string();
|
||||
@@ -758,7 +762,7 @@ async fn main() {
|
||||
run(db.clone(), Ethereum::new(db, url, relayer_url).await, coordinator).await
|
||||
}
|
||||
#[cfg(feature = "monero")]
|
||||
NetworkId::Monero => run(db, Monero::new(url).await, coordinator).await,
|
||||
ExternalNetworkId::Monero => run(db, Monero::new(url).await, coordinator).await,
|
||||
_ => panic!("spawning a processor for an unsupported network"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,11 @@ use ciphersuite::Ciphersuite;
|
||||
pub use serai_db::*;
|
||||
|
||||
use scale::{Encode, Decode};
|
||||
use serai_client::{primitives::Balance, in_instructions::primitives::InInstructionWithBalance};
|
||||
#[rustfmt::skip]
|
||||
use serai_client::{
|
||||
in_instructions::primitives::InInstructionWithBalance,
|
||||
primitives::ExternalBalance
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Get, Plan,
|
||||
@@ -69,7 +73,7 @@ create_db!(
|
||||
OperatingCostsDb: () -> u64,
|
||||
ResolvedDb: (tx: &[u8]) -> [u8; 32],
|
||||
SigningDb: (key: &[u8]) -> Vec<u8>,
|
||||
ForwardedOutputDb: (balance: Balance) -> Vec<u8>,
|
||||
ForwardedOutputDb: (balance: ExternalBalance) -> Vec<u8>,
|
||||
DelayedOutputDb: () -> Vec<u8>
|
||||
}
|
||||
);
|
||||
@@ -224,7 +228,7 @@ impl ForwardedOutputDb {
|
||||
|
||||
pub fn take_forwarded_output(
|
||||
txn: &mut impl DbTxn,
|
||||
balance: Balance,
|
||||
balance: ExternalBalance,
|
||||
) -> Option<InInstructionWithBalance> {
|
||||
let outputs = Self::get(txn, balance)?;
|
||||
let mut outputs_ref = outputs.as_slice();
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::io;
|
||||
|
||||
use ciphersuite::Ciphersuite;
|
||||
|
||||
use serai_client::primitives::{NetworkId, Balance};
|
||||
use serai_client::primitives::{ExternalBalance, ExternalNetworkId};
|
||||
|
||||
use crate::{networks::Network, Db, Payment, Plan};
|
||||
|
||||
@@ -34,18 +34,18 @@ pub trait Scheduler<N: Network>: Sized + Clone + PartialEq + Debug {
|
||||
fn new<D: Db>(
|
||||
txn: &mut D::Transaction<'_>,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> Self;
|
||||
|
||||
/// Load a Scheduler from the DB.
|
||||
fn from_db<D: Db>(
|
||||
db: &D,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> io::Result<Self>;
|
||||
|
||||
/// Check if a branch is usable.
|
||||
fn can_use_branch(&self, balance: Balance) -> bool;
|
||||
fn can_use_branch(&self, balance: ExternalBalance) -> bool;
|
||||
|
||||
/// Schedule a series of outputs/payments.
|
||||
fn schedule<D: Db>(
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{io, collections::HashSet};
|
||||
|
||||
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||
|
||||
use serai_client::primitives::{NetworkId, Coin, Balance};
|
||||
use serai_client::primitives::{ExternalBalance, ExternalCoin, ExternalNetworkId};
|
||||
|
||||
use crate::{
|
||||
Get, DbTxn, Db, Payment, Plan, create_db,
|
||||
@@ -13,7 +13,7 @@ use crate::{
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Scheduler<N: Network> {
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
coins: HashSet<Coin>,
|
||||
coins: HashSet<ExternalCoin>,
|
||||
rotated: bool,
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ impl<N: Network<Scheduler = Self>> SchedulerTrait<N> for Scheduler<N> {
|
||||
fn new<D: Db>(
|
||||
_txn: &mut D::Transaction<'_>,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> Self {
|
||||
assert!(N::branch_address(key).is_none());
|
||||
assert!(N::change_address(key).is_none());
|
||||
@@ -91,7 +91,7 @@ impl<N: Network<Scheduler = Self>> SchedulerTrait<N> for Scheduler<N> {
|
||||
fn from_db<D: Db>(
|
||||
db: &D,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> io::Result<Self> {
|
||||
Ok(Scheduler {
|
||||
key,
|
||||
@@ -100,7 +100,7 @@ impl<N: Network<Scheduler = Self>> SchedulerTrait<N> for Scheduler<N> {
|
||||
})
|
||||
}
|
||||
|
||||
fn can_use_branch(&self, _balance: Balance) -> bool {
|
||||
fn can_use_branch(&self, _balance: ExternalBalance) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::{
|
||||
|
||||
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||
|
||||
use serai_client::primitives::{NetworkId, Coin, Amount, Balance};
|
||||
use serai_client::primitives::{ExternalNetworkId, ExternalCoin, Amount, ExternalBalance};
|
||||
|
||||
use crate::{
|
||||
DbTxn, Db, Payment, Plan,
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Scheduler<N: UtxoNetwork> {
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
coin: Coin,
|
||||
coin: ExternalCoin,
|
||||
|
||||
// Serai, when it has more outputs expected than it can handle in a single transaction, will
|
||||
// schedule the outputs to be handled later. Immediately, it just creates additional outputs
|
||||
@@ -57,7 +57,7 @@ impl<N: UtxoNetwork<Scheduler = Self>> Scheduler<N> {
|
||||
|
||||
fn read<R: Read>(
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
coin: Coin,
|
||||
coin: ExternalCoin,
|
||||
reader: &mut R,
|
||||
) -> io::Result<Self> {
|
||||
let mut read_plans = || -> io::Result<_> {
|
||||
@@ -145,7 +145,7 @@ impl<N: UtxoNetwork<Scheduler = Self>> Scheduler<N> {
|
||||
pub fn new<D: Db>(
|
||||
txn: &mut D::Transaction<'_>,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> Self {
|
||||
assert!(N::branch_address(key).is_some());
|
||||
assert!(N::change_address(key).is_some());
|
||||
@@ -173,7 +173,7 @@ impl<N: UtxoNetwork<Scheduler = Self>> Scheduler<N> {
|
||||
pub fn from_db<D: Db>(
|
||||
db: &D,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> io::Result<Self> {
|
||||
let coin = {
|
||||
let coins = network.coins();
|
||||
@@ -190,7 +190,7 @@ impl<N: UtxoNetwork<Scheduler = Self>> Scheduler<N> {
|
||||
Self::read(key, coin, reader)
|
||||
}
|
||||
|
||||
pub fn can_use_branch(&self, balance: Balance) -> bool {
|
||||
pub fn can_use_branch(&self, balance: ExternalBalance) -> bool {
|
||||
assert_eq!(balance.coin, self.coin);
|
||||
self.plans.contains_key(&balance.amount.0)
|
||||
}
|
||||
@@ -249,7 +249,7 @@ impl<N: UtxoNetwork<Scheduler = Self>> Scheduler<N> {
|
||||
Payment {
|
||||
address: branch_address.clone(),
|
||||
data: None,
|
||||
balance: Balance { coin: self.coin, amount: Amount(amount) },
|
||||
balance: ExternalBalance { coin: self.coin, amount: Amount(amount) },
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -536,7 +536,7 @@ impl<N: UtxoNetwork<Scheduler = Self>> SchedulerTrait<N> for Scheduler<N> {
|
||||
fn new<D: Db>(
|
||||
txn: &mut D::Transaction<'_>,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> Self {
|
||||
Scheduler::new::<D>(txn, key, network)
|
||||
}
|
||||
@@ -545,13 +545,13 @@ impl<N: UtxoNetwork<Scheduler = Self>> SchedulerTrait<N> for Scheduler<N> {
|
||||
fn from_db<D: Db>(
|
||||
db: &D,
|
||||
key: <N::Curve as Ciphersuite>::G,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
) -> io::Result<Self> {
|
||||
Scheduler::from_db::<D>(db, key, network)
|
||||
}
|
||||
|
||||
/// Check if a branch is usable.
|
||||
fn can_use_branch(&self, balance: Balance) -> bool {
|
||||
fn can_use_branch(&self, balance: ExternalBalance) -> bool {
|
||||
Scheduler::can_use_branch(self, balance)
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ impl<N: UtxoNetwork<Scheduler = Self>> SchedulerTrait<N> for Scheduler<N> {
|
||||
|
||||
/// Note a branch output as having been created, with the amount it was actually created with,
|
||||
/// or not having been created due to being too small.
|
||||
// TODO: Move this to Balance.
|
||||
// TODO: Move this to ExternalBalance.
|
||||
fn created_output<D: Db>(
|
||||
&mut self,
|
||||
txn: &mut D::Transaction<'_>,
|
||||
|
||||
@@ -42,7 +42,7 @@ use bitcoin_serai::bitcoin::{
|
||||
};
|
||||
|
||||
use serai_client::{
|
||||
primitives::{MAX_DATA_LEN, Coin, NetworkId, Amount, Balance},
|
||||
primitives::{MAX_DATA_LEN, ExternalCoin, ExternalNetworkId, Amount, ExternalBalance},
|
||||
networks::bitcoin::Address,
|
||||
};
|
||||
|
||||
@@ -125,8 +125,8 @@ impl OutputTrait<Bitcoin> for Output {
|
||||
self.presumed_origin.clone()
|
||||
}
|
||||
|
||||
fn balance(&self) -> Balance {
|
||||
Balance { coin: Coin::Bitcoin, amount: Amount(self.output.value()) }
|
||||
fn balance(&self) -> ExternalBalance {
|
||||
ExternalBalance { coin: ExternalCoin::Bitcoin, amount: Amount(self.output.value()) }
|
||||
}
|
||||
|
||||
fn data(&self) -> &[u8] {
|
||||
@@ -423,7 +423,7 @@ impl Bitcoin {
|
||||
calculating_fee: bool,
|
||||
) -> Result<Option<BSignableTransaction>, NetworkError> {
|
||||
for payment in payments {
|
||||
assert_eq!(payment.balance.coin, Coin::Bitcoin);
|
||||
assert_eq!(payment.balance.coin, ExternalCoin::Bitcoin);
|
||||
}
|
||||
|
||||
// TODO2: Use an fee representative of several blocks, cached inside Self
|
||||
@@ -598,7 +598,7 @@ impl Network for Bitcoin {
|
||||
|
||||
type Address = Address;
|
||||
|
||||
const NETWORK: NetworkId = NetworkId::Bitcoin;
|
||||
const NETWORK: ExternalNetworkId = ExternalNetworkId::Bitcoin;
|
||||
const ID: &'static str = "Bitcoin";
|
||||
const ESTIMATED_BLOCK_TIME_IN_SECONDS: usize = 600;
|
||||
const CONFIRMATIONS: usize = 6;
|
||||
|
||||
@@ -38,7 +38,7 @@ use tokio::{
|
||||
};
|
||||
|
||||
use serai_client::{
|
||||
primitives::{Coin, Amount, Balance, NetworkId},
|
||||
primitives::{ExternalCoin, Amount, ExternalBalance, ExternalNetworkId},
|
||||
validator_sets::primitives::Session,
|
||||
};
|
||||
|
||||
@@ -68,20 +68,20 @@ const DAI: [u8; 20] =
|
||||
Err(_) => panic!("invalid test DAI hex address"),
|
||||
};
|
||||
|
||||
fn coin_to_serai_coin(coin: &EthereumCoin) -> Option<Coin> {
|
||||
fn coin_to_serai_coin(coin: &EthereumCoin) -> Option<ExternalCoin> {
|
||||
match coin {
|
||||
EthereumCoin::Ether => Some(Coin::Ether),
|
||||
EthereumCoin::Ether => Some(ExternalCoin::Ether),
|
||||
EthereumCoin::Erc20(token) => {
|
||||
if *token == DAI {
|
||||
return Some(Coin::Dai);
|
||||
return Some(ExternalCoin::Dai);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn amount_to_serai_amount(coin: Coin, amount: U256) -> Amount {
|
||||
assert_eq!(coin.network(), NetworkId::Ethereum);
|
||||
fn amount_to_serai_amount(coin: ExternalCoin, amount: U256) -> Amount {
|
||||
assert_eq!(coin.network(), ExternalNetworkId::Ethereum);
|
||||
assert_eq!(coin.decimals(), 8);
|
||||
// Remove 10 decimals so we go from 18 decimals to 8 decimals
|
||||
let divisor = U256::from(10_000_000_000u64);
|
||||
@@ -89,8 +89,8 @@ fn amount_to_serai_amount(coin: Coin, amount: U256) -> Amount {
|
||||
Amount(u64::try_from(amount / divisor).unwrap())
|
||||
}
|
||||
|
||||
fn balance_to_ethereum_amount(balance: Balance) -> U256 {
|
||||
assert_eq!(balance.coin.network(), NetworkId::Ethereum);
|
||||
fn balance_to_ethereum_amount(balance: ExternalBalance) -> U256 {
|
||||
assert_eq!(balance.coin.network(), ExternalNetworkId::Ethereum);
|
||||
assert_eq!(balance.coin.decimals(), 8);
|
||||
// Restore 10 decimals so we go from 8 decimals to 18 decimals
|
||||
let factor = U256::from(10_000_000_000u64);
|
||||
@@ -201,14 +201,14 @@ impl<D: Db> Output<Ethereum<D>> for EthereumInInstruction {
|
||||
Some(Address(self.from))
|
||||
}
|
||||
|
||||
fn balance(&self) -> Balance {
|
||||
fn balance(&self) -> ExternalBalance {
|
||||
let coin = coin_to_serai_coin(&self.coin).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"requesting coin for an EthereumInInstruction with a coin {}",
|
||||
"we don't handle. this never should have been yielded"
|
||||
)
|
||||
});
|
||||
Balance { coin, amount: amount_to_serai_amount(coin, self.amount) }
|
||||
ExternalBalance { coin, amount: amount_to_serai_amount(coin, self.amount) }
|
||||
}
|
||||
fn data(&self) -> &[u8] {
|
||||
&self.data
|
||||
@@ -394,7 +394,7 @@ impl<D: Db> Network for Ethereum<D> {
|
||||
|
||||
type Address = Address;
|
||||
|
||||
const NETWORK: NetworkId = NetworkId::Ethereum;
|
||||
const NETWORK: ExternalNetworkId = ExternalNetworkId::Ethereum;
|
||||
const ID: &'static str = "Ethereum";
|
||||
const ESTIMATED_BLOCK_TIME_IN_SECONDS: usize = 32 * 12;
|
||||
const CONFIRMATIONS: usize = 1;
|
||||
@@ -681,7 +681,7 @@ impl<D: Db> Network for Ethereum<D> {
|
||||
OutInstructionTarget::Direct(payment.address.0)
|
||||
},
|
||||
value: {
|
||||
assert_eq!(payment.balance.coin, Coin::Ether); // TODO
|
||||
assert_eq!(payment.balance.coin, ExternalCoin::Ether); // TODO
|
||||
balance_to_ethereum_amount(payment.balance)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@ use frost::{
|
||||
sign::PreprocessMachine,
|
||||
};
|
||||
|
||||
use serai_client::primitives::{NetworkId, Balance};
|
||||
use serai_client::primitives::{ExternalBalance, ExternalNetworkId};
|
||||
|
||||
use log::error;
|
||||
|
||||
@@ -115,7 +115,7 @@ pub trait Output<N: Network>: Send + Sync + Sized + Clone + PartialEq + Eq + Deb
|
||||
|
||||
fn presumed_origin(&self) -> Option<N::Address>;
|
||||
|
||||
fn balance(&self) -> Balance;
|
||||
fn balance(&self) -> ExternalBalance;
|
||||
fn data(&self) -> &[u8];
|
||||
|
||||
fn write<W: io::Write>(&self, writer: &mut W) -> io::Result<()>;
|
||||
@@ -126,13 +126,13 @@ pub trait Output<N: Network>: Send + Sync + Sized + Clone + PartialEq + Eq + Deb
|
||||
pub trait Transaction<N: Network>: Send + Sync + Sized + Clone + PartialEq + Debug {
|
||||
type Id: 'static + Id;
|
||||
fn id(&self) -> Self::Id;
|
||||
// TODO: Move to Balance
|
||||
// TODO: Move to ExternalBalance
|
||||
#[cfg(test)]
|
||||
async fn fee(&self, network: &N) -> u64;
|
||||
}
|
||||
|
||||
pub trait SignableTransaction: Send + Sync + Clone + Debug {
|
||||
// TODO: Move to Balance
|
||||
// TODO: Move to ExternalBalance
|
||||
fn fee(&self) -> u64;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ pub trait Network: 'static + Send + Sync + Clone + PartialEq + Debug {
|
||||
+ TryFrom<Vec<u8>>;
|
||||
|
||||
/// Network ID for this network.
|
||||
const NETWORK: NetworkId;
|
||||
const NETWORK: ExternalNetworkId;
|
||||
/// String ID for this network.
|
||||
const ID: &'static str;
|
||||
/// The estimated amount of time a block will take.
|
||||
@@ -297,7 +297,7 @@ pub trait Network: 'static + Send + Sync + Clone + PartialEq + Debug {
|
||||
/// For any received output, there's the cost to spend the output. This value MUST exceed the
|
||||
/// cost to spend said output, and should by a notable margin (not just 2x, yet an order of
|
||||
/// magnitude).
|
||||
// TODO: Dust needs to be diversified per Coin
|
||||
// TODO: Dust needs to be diversified per ExternalCoin
|
||||
const DUST: u64;
|
||||
|
||||
/// The cost to perform input aggregation with a 2-input 1-output TX.
|
||||
|
||||
@@ -31,7 +31,7 @@ use monero_wallet::Scanner;
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub use serai_client::{
|
||||
primitives::{MAX_DATA_LEN, Coin, NetworkId, Amount, Balance},
|
||||
primitives::{MAX_DATA_LEN, ExternalCoin, ExternalNetworkId, Amount, ExternalBalance},
|
||||
networks::monero::Address,
|
||||
};
|
||||
|
||||
@@ -85,8 +85,8 @@ impl OutputTrait<Monero> for Output {
|
||||
None
|
||||
}
|
||||
|
||||
fn balance(&self) -> Balance {
|
||||
Balance { coin: Coin::Monero, amount: Amount(self.0.commitment().amount) }
|
||||
fn balance(&self) -> ExternalBalance {
|
||||
ExternalBalance { coin: ExternalCoin::Monero, amount: Amount(self.0.commitment().amount) }
|
||||
}
|
||||
|
||||
fn data(&self) -> &[u8] {
|
||||
@@ -308,7 +308,7 @@ impl Monero {
|
||||
calculating_fee: bool,
|
||||
) -> Result<Option<MakeSignableTransactionResult>, NetworkError> {
|
||||
for payment in payments {
|
||||
assert_eq!(payment.balance.coin, Coin::Monero);
|
||||
assert_eq!(payment.balance.coin, ExternalCoin::Monero);
|
||||
}
|
||||
|
||||
// TODO2: Use an fee representative of several blocks, cached inside Self
|
||||
@@ -363,7 +363,7 @@ impl Monero {
|
||||
.legacy_address(MoneroNetwork::Mainnet),
|
||||
)
|
||||
.unwrap(),
|
||||
balance: Balance { coin: Coin::Monero, amount: Amount(0) },
|
||||
balance: ExternalBalance { coin: ExternalCoin::Monero, amount: Amount(0) },
|
||||
data: None,
|
||||
});
|
||||
}
|
||||
@@ -470,7 +470,7 @@ impl Network for Monero {
|
||||
|
||||
type Address = Address;
|
||||
|
||||
const NETWORK: NetworkId = NetworkId::Monero;
|
||||
const NETWORK: ExternalNetworkId = ExternalNetworkId::Monero;
|
||||
const ID: &'static str = "Monero";
|
||||
const ESTIMATED_BLOCK_TIME_IN_SECONDS: usize = 120;
|
||||
const CONFIRMATIONS: usize = 10;
|
||||
|
||||
@@ -6,7 +6,7 @@ use transcript::{Transcript, RecommendedTranscript};
|
||||
use ciphersuite::group::GroupEncoding;
|
||||
use frost::curve::Ciphersuite;
|
||||
|
||||
use serai_client::primitives::Balance;
|
||||
use serai_client::primitives::ExternalBalance;
|
||||
|
||||
use crate::{
|
||||
networks::{Output, Network},
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
pub struct Payment<N: Network> {
|
||||
pub address: N::Address,
|
||||
pub data: Option<Vec<u8>>,
|
||||
pub balance: Balance,
|
||||
pub balance: ExternalBalance,
|
||||
}
|
||||
|
||||
impl<N: Network> Payment<N> {
|
||||
@@ -69,7 +69,7 @@ impl<N: Network> Payment<N> {
|
||||
None
|
||||
};
|
||||
|
||||
let balance = Balance::decode(&mut scale::IoReader(reader))
|
||||
let balance = ExternalBalance::decode(&mut scale::IoReader(reader))
|
||||
.map_err(|_| io::Error::other("invalid balance"))?;
|
||||
|
||||
Ok(Payment { address, data, balance })
|
||||
|
||||
@@ -17,9 +17,9 @@ use frost_schnorrkel::Schnorrkel;
|
||||
use log::{info, warn};
|
||||
|
||||
use serai_client::{
|
||||
primitives::ExternalNetworkId,
|
||||
validator_sets::primitives::{report_slashes_message, ExternalValidatorSet, Session},
|
||||
Public,
|
||||
primitives::NetworkId,
|
||||
validator_sets::primitives::{Session, ValidatorSet, report_slashes_message},
|
||||
};
|
||||
|
||||
use messages::coordinator::*;
|
||||
@@ -38,7 +38,7 @@ type SignatureShare = <AlgorithmSignMachine<Ristretto, Schnorrkel> as SignMachin
|
||||
>>::SignatureShare;
|
||||
|
||||
pub struct SlashReportSigner {
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
session: Session,
|
||||
keys: Vec<ThresholdKeys<Ristretto>>,
|
||||
report: Vec<([u8; 32], u32)>,
|
||||
@@ -66,7 +66,7 @@ impl fmt::Debug for SlashReportSigner {
|
||||
impl SlashReportSigner {
|
||||
pub fn new(
|
||||
txn: &mut impl DbTxn,
|
||||
network: NetworkId,
|
||||
network: ExternalNetworkId,
|
||||
session: Session,
|
||||
keys: Vec<ThresholdKeys<Ristretto>>,
|
||||
report: Vec<([u8; 32], u32)>,
|
||||
@@ -178,7 +178,7 @@ impl SlashReportSigner {
|
||||
let (machine, share) = match machine.sign(
|
||||
preprocesses,
|
||||
&report_slashes_message(
|
||||
&ValidatorSet { network: self.network, session: self.session },
|
||||
&ExternalValidatorSet { network: self.network, session: self.session },
|
||||
&self
|
||||
.report
|
||||
.clone()
|
||||
|
||||
@@ -33,17 +33,17 @@ fn test_batch_signer() {
|
||||
let block = BlockHash([0xaa; 32]);
|
||||
|
||||
let batch = Batch {
|
||||
network: NetworkId::Monero,
|
||||
network: ExternalNetworkId::Monero,
|
||||
id,
|
||||
block,
|
||||
instructions: vec![
|
||||
InInstructionWithBalance {
|
||||
instruction: InInstruction::Transfer(SeraiAddress([0xbb; 32])),
|
||||
balance: Balance { coin: Coin::Bitcoin, amount: Amount(1000) },
|
||||
balance: ExternalBalance { coin: ExternalCoin::Bitcoin, amount: Amount(1000) },
|
||||
},
|
||||
InInstructionWithBalance {
|
||||
instruction: InInstruction::Dex(DexCall::SwapAndAddLiquidity(SeraiAddress([0xbb; 32]))),
|
||||
balance: Balance { coin: Coin::Monero, amount: Amount(9999999999999999) },
|
||||
balance: ExternalBalance { coin: ExternalCoin::Monero, amount: Amount(9999999999999999) },
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -70,7 +70,7 @@ fn test_batch_signer() {
|
||||
let i = Participant::new(u16::try_from(i).unwrap()).unwrap();
|
||||
let keys = keys.get(&i).unwrap().clone();
|
||||
|
||||
let mut signer = BatchSigner::<MemDb>::new(NetworkId::Monero, Session(0), vec![keys]);
|
||||
let mut signer = BatchSigner::<MemDb>::new(ExternalNetworkId::Monero, Session(0), vec![keys]);
|
||||
let mut db = MemDb::new();
|
||||
|
||||
let mut txn = db.txn();
|
||||
|
||||
@@ -12,7 +12,7 @@ use frost::{
|
||||
use serai_db::{DbTxn, Db, MemDb};
|
||||
|
||||
use serai_client::{
|
||||
primitives::{NetworkId, Coin, Amount, Balance},
|
||||
primitives::{ExternalNetworkId, ExternalCoin, Amount, ExternalBalance},
|
||||
validator_sets::primitives::Session,
|
||||
};
|
||||
|
||||
@@ -185,12 +185,11 @@ pub async fn test_signer<N: Network>(
|
||||
let payments = vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
balance: ExternalBalance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_signer called with Serai"),
|
||||
NetworkId::Bitcoin => Coin::Bitcoin,
|
||||
NetworkId::Ethereum => Coin::Ether,
|
||||
NetworkId::Monero => Coin::Monero,
|
||||
ExternalNetworkId::Bitcoin => ExternalCoin::Bitcoin,
|
||||
ExternalNetworkId::Ethereum => ExternalCoin::Ether,
|
||||
ExternalNetworkId::Monero => ExternalCoin::Monero,
|
||||
},
|
||||
amount: Amount(amount),
|
||||
},
|
||||
@@ -224,7 +223,7 @@ pub async fn test_signer<N: Network>(
|
||||
.await;
|
||||
// Don't run if Ethereum as the received output will revert by the contract
|
||||
// (and therefore not actually exist)
|
||||
if N::NETWORK != NetworkId::Ethereum {
|
||||
if N::NETWORK != ExternalNetworkId::Ethereum {
|
||||
assert_eq!(outputs.len(), 1 + usize::from(u8::from(plan.change.is_some())));
|
||||
// Adjust the amount for the fees
|
||||
let amount = amount - tx.fee(&network).await;
|
||||
|
||||
@@ -11,7 +11,7 @@ use tokio::time::timeout;
|
||||
use serai_db::{DbTxn, Db, MemDb};
|
||||
|
||||
use serai_client::{
|
||||
primitives::{NetworkId, Coin, Amount, Balance},
|
||||
primitives::{ExternalNetworkId, ExternalCoin, Amount, ExternalBalance},
|
||||
validator_sets::primitives::Session,
|
||||
};
|
||||
|
||||
@@ -89,12 +89,11 @@ pub async fn test_wallet<N: Network>(
|
||||
vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
balance: ExternalBalance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_wallet called with Serai"),
|
||||
NetworkId::Bitcoin => Coin::Bitcoin,
|
||||
NetworkId::Ethereum => Coin::Ether,
|
||||
NetworkId::Monero => Coin::Monero,
|
||||
ExternalNetworkId::Bitcoin => ExternalCoin::Bitcoin,
|
||||
ExternalNetworkId::Ethereum => ExternalCoin::Ether,
|
||||
ExternalNetworkId::Monero => ExternalCoin::Monero,
|
||||
},
|
||||
amount: Amount(amount),
|
||||
},
|
||||
@@ -117,12 +116,11 @@ pub async fn test_wallet<N: Network>(
|
||||
vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
balance: ExternalBalance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_wallet called with Serai"),
|
||||
NetworkId::Bitcoin => Coin::Bitcoin,
|
||||
NetworkId::Ethereum => Coin::Ether,
|
||||
NetworkId::Monero => Coin::Monero,
|
||||
ExternalNetworkId::Bitcoin => ExternalCoin::Bitcoin,
|
||||
ExternalNetworkId::Ethereum => ExternalCoin::Ether,
|
||||
ExternalNetworkId::Monero => ExternalCoin::Monero,
|
||||
},
|
||||
amount: Amount(amount),
|
||||
}
|
||||
@@ -160,7 +158,7 @@ pub async fn test_wallet<N: Network>(
|
||||
|
||||
// Don't run if Ethereum as the received output will revert by the contract
|
||||
// (and therefore not actually exist)
|
||||
if N::NETWORK != NetworkId::Ethereum {
|
||||
if N::NETWORK != ExternalNetworkId::Ethereum {
|
||||
assert_eq!(outputs.len(), 1 + usize::from(u8::from(plans[0].change.is_some())));
|
||||
// Adjust the amount for the fees
|
||||
let amount = amount - tx.fee(&network).await;
|
||||
@@ -183,7 +181,7 @@ pub async fn test_wallet<N: Network>(
|
||||
network.mine_block().await;
|
||||
}
|
||||
|
||||
if N::NETWORK != NetworkId::Ethereum {
|
||||
if N::NETWORK != ExternalNetworkId::Ethereum {
|
||||
match timeout(Duration::from_secs(30), scanner.events.recv()).await.unwrap().unwrap() {
|
||||
ScannerEvent::Block { is_retirement_block, block: block_id, outputs: these_outputs } => {
|
||||
scanner.multisig_completed.send(false).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user