@@ -1121,14 +1121,19 @@ pub(crate) struct ShutdownResult {
1121
1121
1122
1122
#[derive(Debug, Copy, Clone)]
1123
1123
enum HolderCommitmentPoint {
1124
- Uninitialized { transaction_number: u64 },
1125
1124
PendingNext { transaction_number: u64, current: PublicKey },
1126
1125
Available { transaction_number: u64, current: PublicKey, next: PublicKey },
1127
1126
}
1128
1127
1129
- impl HolderCommitmentPoint where {
1130
- pub fn new() -> Self {
1131
- HolderCommitmentPoint::Uninitialized { transaction_number: INITIAL_COMMITMENT_NUMBER }
1128
+ impl HolderCommitmentPoint {
1129
+ pub fn new<SP: Deref>(signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>) -> Self
1130
+ where SP::Target: SignerProvider
1131
+ {
1132
+ HolderCommitmentPoint::Available {
1133
+ transaction_number: INITIAL_COMMITMENT_NUMBER,
1134
+ current: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx),
1135
+ next: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx),
1136
+ }
1132
1137
}
1133
1138
1134
1139
pub fn is_available(&self) -> bool {
@@ -1137,23 +1142,20 @@ impl HolderCommitmentPoint where {
1137
1142
1138
1143
pub fn transaction_number(&self) -> u64 {
1139
1144
match self {
1140
- HolderCommitmentPoint::Uninitialized { transaction_number } => *transaction_number,
1141
1145
HolderCommitmentPoint::PendingNext { transaction_number, .. } => *transaction_number,
1142
1146
HolderCommitmentPoint::Available { transaction_number, .. } => *transaction_number,
1143
1147
}
1144
1148
}
1145
1149
1146
- pub fn current_point(&self) -> Option< PublicKey> {
1150
+ pub fn current_point(&self) -> PublicKey {
1147
1151
match self {
1148
- HolderCommitmentPoint::Uninitialized { .. } => None,
1149
- HolderCommitmentPoint::PendingNext { current, .. } => Some(*current),
1150
- HolderCommitmentPoint::Available { current, .. } => Some(*current),
1152
+ HolderCommitmentPoint::PendingNext { current, .. } => *current,
1153
+ HolderCommitmentPoint::Available { current, .. } => *current,
1151
1154
}
1152
1155
}
1153
1156
1154
1157
pub fn next_point(&self) -> Option<PublicKey> {
1155
1158
match self {
1156
- HolderCommitmentPoint::Uninitialized { .. } => None,
1157
1159
HolderCommitmentPoint::PendingNext { .. } => None,
1158
1160
HolderCommitmentPoint::Available { next, .. } => Some(*next),
1159
1161
}
@@ -1162,13 +1164,6 @@ impl HolderCommitmentPoint where {
1162
1164
pub fn advance<SP: Deref, L: Deref>(&mut self, signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L)
1163
1165
where SP::Target: SignerProvider, L::Target: Logger
1164
1166
{
1165
- if let HolderCommitmentPoint::Uninitialized { transaction_number } = self {
1166
- let current = signer.as_ref().get_per_commitment_point(*transaction_number, secp_ctx); // TODO
1167
- log_trace!(logger, "Retrieved current per-commitment point {}", transaction_number);
1168
- *self = HolderCommitmentPoint::PendingNext { transaction_number: *transaction_number, current };
1169
- // TODO: handle error case when get_per_commitment_point becomes async
1170
- }
1171
-
1172
1167
if let HolderCommitmentPoint::Available { transaction_number, next, .. } = self {
1173
1168
*self = HolderCommitmentPoint::PendingNext {
1174
1169
transaction_number: *transaction_number - 1,
@@ -1177,10 +1172,9 @@ impl HolderCommitmentPoint where {
1177
1172
}
1178
1173
1179
1174
if let HolderCommitmentPoint::PendingNext { transaction_number, current } = self {
1180
- let next = signer.as_ref().get_per_commitment_point(*transaction_number - 1, secp_ctx); // TODO
1175
+ let next = signer.as_ref().get_per_commitment_point(*transaction_number - 1, secp_ctx);
1181
1176
log_trace!(logger, "Retrieved next per-commitment point {}", *transaction_number - 1);
1182
1177
*self = HolderCommitmentPoint::Available { transaction_number: *transaction_number, current: *current, next };
1183
- // TODO: handle error case when get_per_commitment_point becomes async
1184
1178
}
1185
1179
}
1186
1180
}
0 commit comments