1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::*;
pub struct FederatedEmulatorConnection {
emulators: Vec<Arc<dyn CTVEmulator>>,
threshold: u8,
}
impl FederatedEmulatorConnection {
pub fn new(emulators: Vec<Arc<dyn CTVEmulator>>, threshold: u8) -> Self {
FederatedEmulatorConnection {
emulators,
threshold,
}
}
}
impl CTVEmulator for FederatedEmulatorConnection {
fn get_signer_for(&self, h: Sha256) -> Result<Clause, EmulatorError> {
let v = self
.emulators
.iter()
.map(|e| e.get_signer_for(h))
.collect::<Result<Vec<Clause>, EmulatorError>>()?;
Ok(Clause::Threshold(self.threshold as usize, v))
}
fn sign(
&self,
mut b: PartiallySignedTransaction,
) -> Result<PartiallySignedTransaction, EmulatorError> {
for emulator in self.emulators.iter() {
b = emulator.sign(b)?;
}
Ok(b)
}
}