mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Route networking through Wallet, not Coin
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user