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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use bitcoin::hashes::sha256;
use bitcoin::util::psbt::PartiallySignedTransaction;
pub use sapio_base::Clause;
use std::fmt;
use std::sync::Arc;
#[derive(Debug)]
pub enum EmulatorError {
NetworkIssue(std::io::Error),
BIP32Error(bitcoin::util::bip32::Error),
}
impl fmt::Display for EmulatorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl std::error::Error for EmulatorError {}
impl From<std::io::Error> for EmulatorError {
fn from(e: std::io::Error) -> EmulatorError {
EmulatorError::NetworkIssue(e)
}
}
impl From<bitcoin::util::bip32::Error> for EmulatorError {
fn from(e: bitcoin::util::bip32::Error) -> EmulatorError {
EmulatorError::BIP32Error(e)
}
}
pub trait CTVEmulator: Sync + Send {
fn get_signer_for(&self, h: sha256::Hash) -> Result<Clause, EmulatorError>;
fn sign(
&self,
b: PartiallySignedTransaction,
) -> Result<PartiallySignedTransaction, EmulatorError>;
}
pub type NullEmulator = Arc<dyn CTVEmulator>;
pub struct CTVAvailable;
impl CTVEmulator for CTVAvailable {
fn get_signer_for(&self, h: sha256::Hash) -> Result<Clause, EmulatorError> {
Ok(Clause::TxTemplate(h))
}
fn sign(
&self,
b: PartiallySignedTransaction,
) -> Result<PartiallySignedTransaction, EmulatorError> {
Ok(b)
}
}