Route networking through Wallet, not Coin

This commit is contained in:
Luke Parker
2022-06-10 09:36:07 -04:00
parent 4b8822cb74
commit 32473d9976
6 changed files with 61 additions and 36 deletions

View File

@@ -1,10 +1,12 @@
use std::{sync::Arc, collections::HashMap};
use rand_core::OsRng;
use transcript::Transcript as TranscriptTrait;
use frost::{Curve, MultisigKeys};
use frost::{Curve, MultisigKeys, sign::StateMachine};
use crate::{Transcript, CoinError, Output, Coin};
use crate::{Transcript, CoinError, SignError, Output, Coin, Network};
pub struct WalletKeys<C: Curve> {
keys: MultisigKeys<C>,
@@ -333,4 +335,26 @@ impl<D: CoinDb, C: Coin> Wallet<D, C> {
Ok((payments, txs))
}
pub async fn attempt_send<N: Network>(
&mut self,
network: &mut N,
prepared: C::SignableTransaction,
included: &[u16]
) -> Result<(Vec<u8>, Vec<<C::Output as Output>::Id>), SignError> {
let mut attempt = self.coin.attempt_send(
prepared,
included
).await.map_err(|e| SignError::CoinError(e))?;
let commitments = network.round(
attempt.preprocess(&mut OsRng).unwrap()
).await.map_err(|e| SignError::NetworkError(e))?;
let shares = network.round(
attempt.sign(commitments, b"").map_err(|e| SignError::FrostError(e))?
).await.map_err(|e| SignError::NetworkError(e))?;
let tx = attempt.complete(shares).map_err(|e| SignError::FrostError(e))?;
self.coin.publish_transaction(&tx).await.map_err(|e| SignError::CoinError(e))
}
}