diff --git a/processor/src/coins/monero.rs b/processor/src/coins/monero.rs index f1d96bc5..55226981 100644 --- a/processor/src/coins/monero.rs +++ b/processor/src/coins/monero.rs @@ -13,7 +13,7 @@ use monero_serai::{ frost::Ed25519, transaction::{Timelock, Transaction}, rpc::Rpc, - wallet::{SpendableOutput, SignableTransaction as MSignableTransaction, TransactionMachine} + wallet::{Fee, SpendableOutput, SignableTransaction as MSignableTransaction, TransactionMachine} }; use crate::{Transcript, CoinError, Output as OutputTrait, Coin, view_key}; @@ -59,7 +59,7 @@ pub struct SignableTransaction( #[derive(Clone, Debug)] pub struct Monero { - rpc: Rpc, + pub(crate) rpc: Rpc, view: Scalar, view_pub: PublicKey } @@ -79,6 +79,7 @@ impl Monero { impl Coin for Monero { type Curve = Ed25519; + type Fee = Fee; type Transaction = Transaction; type Block = Vec; @@ -132,7 +133,8 @@ impl Coin for Monero { transcript: Transcript, height: usize, mut inputs: Vec, - payments: &[(Address, u64)] + payments: &[(Address, u64)], + fee: Fee ) -> Result { let spend = keys.group_key(); Ok( @@ -143,8 +145,8 @@ impl Coin for Monero { MSignableTransaction::new( inputs.drain(..).map(|input| input.0).collect(), payments.to_vec(), - self.address(spend), - 100000000 // TODO + Some(self.address(spend)), + fee ).map_err(|_| CoinError::ConnectionError)? ) ) @@ -156,7 +158,6 @@ impl Coin for Monero { included: &[u16] ) -> Result { transaction.3.clone().multisig( - &mut OsRng, &self.rpc, (*transaction.0).clone(), transaction.1.clone(), @@ -213,8 +214,8 @@ impl Coin for Monero { let tx = MSignableTransaction::new( outputs, vec![(address, amount - fee)], - temp, - fee / 2000 + Some(temp), + self.rpc.get_fee().await.unwrap() ).unwrap().sign(&mut OsRng, &self.rpc, &Scalar::one()).await.unwrap(); self.rpc.publish_transaction(&tx).await.unwrap(); self.mine_block(temp).await; diff --git a/processor/src/lib.rs b/processor/src/lib.rs index 65862aed..2a615ea5 100644 --- a/processor/src/lib.rs +++ b/processor/src/lib.rs @@ -51,6 +51,7 @@ pub trait Output: Sized + Clone { pub trait Coin { type Curve: Curve; + type Fee: Copy; type Transaction; type Block; @@ -82,7 +83,8 @@ pub trait Coin { transcript: Transcript, height: usize, inputs: Vec, - payments: &[(Self::Address, u64)] + payments: &[(Self::Address, u64)], + fee: Self::Fee ) -> Result; async fn attempt_send( diff --git a/processor/src/scanner.rs b/processor/src/scanner.rs deleted file mode 100644 index 59cca8fe..00000000 --- a/processor/src/scanner.rs +++ /dev/null @@ -1,5 +0,0 @@ -struct Scanner {} - -impl Scanner { - -} diff --git a/processor/src/tests/mod.rs b/processor/src/tests/mod.rs index c23b8309..e7214b97 100644 --- a/processor/src/tests/mod.rs +++ b/processor/src/tests/mod.rs @@ -57,16 +57,17 @@ impl Network for LocalNetwork { } } -async fn test_send(coin: C) { +async fn test_send(coin: C, fee: C::Fee) { // Mine a block so there's a confirmed height coin.mine_block(coin.address(::G::generator())).await; let height = coin.get_height().await.unwrap(); - let mut networks = LocalNetwork::new(3); - let mut keys = frost::tests::key_gen::<_, C::Curve>(&mut OsRng); + let threshold = keys[&1].params().t(); + let mut networks = LocalNetwork::new(threshold); + let mut wallets = vec![]; - for i in 1 ..= 3 { + for i in 1 ..= threshold { let mut wallet = Wallet::new(MemCoinDb::new(), coin.clone()); wallet.acknowledge_height(0, height); wallet.add_keys( @@ -95,9 +96,12 @@ async fn test_send(coin: C) { wallet.acknowledge_height(1, height - 10); let signable = wallet.prepare_sends( 1, - vec![(wallet.address(), 10000000000)] + vec![(wallet.address(), 10000000000)], + fee ).await.unwrap().1.swap_remove(0); - futures.push(wallet.attempt_send(network, signable, &[1, 2, 3])); + futures.push( + wallet.attempt_send(network, signable, (1 ..= threshold).into_iter().collect::>()) + ); } println!( @@ -108,5 +112,7 @@ async fn test_send(coin: C) { #[tokio::test] async fn monero() { - test_send(Monero::new("http://127.0.0.1:18081".to_string())).await; + let monero = Monero::new("http://127.0.0.1:18081".to_string()); + let fee = monero.rpc.get_fee().await.unwrap(); + test_send(monero, fee).await; } diff --git a/processor/src/wallet.rs b/processor/src/wallet.rs index 27a1cb83..be58a838 100644 --- a/processor/src/wallet.rs +++ b/processor/src/wallet.rs @@ -281,7 +281,8 @@ impl Wallet { pub async fn prepare_sends( &mut self, canonical: usize, - payments: Vec<(C::Address, u64)> + payments: Vec<(C::Address, u64)>, + fee: C::Fee ) -> Result<(Vec<(C::Address, u64)>, Vec), CoinError> { if payments.len() == 0 { return Ok((vec![], vec![])); @@ -326,7 +327,8 @@ impl Wallet { transcript, acknowledged_height, inputs, - &outputs + &outputs, + fee ).await?; // self.db.save_tx(tx) // TODO txs.push(tx); @@ -340,11 +342,11 @@ impl Wallet { &mut self, network: &mut N, prepared: C::SignableTransaction, - included: &[u16] + included: Vec ) -> Result<(Vec, Vec<::Id>), SignError> { let mut attempt = self.coin.attempt_send( prepared, - included + &included ).await.map_err(|e| SignError::CoinError(e))?; let commitments = network.round(