Skip to content

Commit

Permalink
fixup! feat: Add reject dlc channel offer handling
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed Feb 21, 2024
1 parent 300cbf1 commit 6c00d11
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion dlc-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,13 @@ where
/// message to be sent as well as the public key of the offering node.
pub fn reject_channel(&self, channel_id: &ChannelId) -> Result<(Reject, PublicKey), Error> {
let offered_channel = get_channel_in_state!(self, channel_id, Offered, None as Option<PublicKey>)?;

if offered_channel.is_offer_party {
return Err(Error::InvalidState(
"Cannot reject channel initiated by us.".to_string(),
));
}

let offered_contract = get_contract_in_state!(self, &offered_channel.offered_contract_id, Offered, None as Option<PublicKey>)?;

let counterparty = offered_channel.counter_party;
Expand Down Expand Up @@ -2030,10 +2037,20 @@ where
self.store.upsert_channel(Channel::Cancelled(offered_channel), Some(Contract::Rejected(offered_contract)))?;
},
Channel::Signed(mut signed_channel) => {

let contract = match signed_channel.state {
SignedChannelState::RenewOffered { offered_contract_id, .. } => {
let offered_contract = get_contract_in_state!(self, &offered_contract_id, Offered, None::<PublicKey>)?;
Some(Contract::Rejected(offered_contract))

}
_ => None
};

crate::channel_updater::on_reject(&mut signed_channel)?;

self.store
.upsert_channel(Channel::Signed(signed_channel), None)?;
.upsert_channel(Channel::Signed(signed_channel), contract)?;
},
channel => {
return Err(Error::InvalidState(
Expand Down

0 comments on commit 6c00d11

Please sign in to comment.