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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
pub use self::{schema::Schema, transactions::BtcAnchoringInterface};
pub use crate::proto::{AddFunds, SignInput};
use bitcoin::blockdata::script::Script;
use btc_transaction_utils::{multisig::RedeemScript, p2wsh};
use exonum::helpers::Height;
use crate::{btc::Address, config::Config};
pub mod data_layout;
pub mod errors;
pub mod schema;
pub mod transactions;
#[derive(Debug, Clone)]
pub enum BtcAnchoringState {
Regular {
actual_configuration: Config,
},
Transition {
actual_configuration: Config,
following_configuration: Config,
},
}
impl BtcAnchoringState {
pub fn redeem_script(&self) -> RedeemScript {
match self {
BtcAnchoringState::Regular {
actual_configuration,
} => actual_configuration.redeem_script(),
BtcAnchoringState::Transition {
following_configuration,
..
} => following_configuration.redeem_script(),
}
}
pub fn script_pubkey(&self) -> Script {
self.redeem_script().as_ref().to_v0_p2wsh()
}
pub fn output_address(&self) -> Address {
p2wsh::address(&self.redeem_script(), self.actual_config().network).into()
}
pub fn is_regular(&self) -> bool {
if let BtcAnchoringState::Regular { .. } = self {
true
} else {
false
}
}
pub fn is_transition(&self) -> bool {
if let BtcAnchoringState::Transition { .. } = self {
true
} else {
false
}
}
pub fn actual_config(&self) -> &Config {
match self {
BtcAnchoringState::Regular {
ref actual_configuration,
} => actual_configuration,
BtcAnchoringState::Transition {
ref actual_configuration,
..
} => actual_configuration,
}
}
pub fn following_config(&self) -> Option<&Config> {
match self {
BtcAnchoringState::Regular { .. } => None,
BtcAnchoringState::Transition {
ref following_configuration,
..
} => Some(following_configuration),
}
}
pub fn following_anchoring_height(&self, latest_anchored_height: Option<Height>) -> Height {
latest_anchored_height.map_or_else(Height::zero, |height| match self {
BtcAnchoringState::Regular {
ref actual_configuration,
} => actual_configuration.following_anchoring_height(height),
BtcAnchoringState::Transition { .. } => height,
})
}
}