use ln::msgs::DecodeError;
use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest};
-use ln::channelmanager::HTLCSource;
+use ln::channelmanager::{HTLCSource, PaymentPreimage};
use ln::chan_utils;
use ln::chan_utils::{HTLCType, LocalCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment};
use chain::chaininterface::{FeeEstimator, BroadcasterInterface, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT};
prev_local_commitment: Option<LocalCommitmentTransaction>,
current_htlc_cache: Option<HTLCTxCache>,
prev_htlc_cache: Option<HTLCTxCache>,
+ local_csv: u16,
key_storage: ChanSigner,
} else {
writer.write_all(&[0; 1])?;
}
+ self.local_csv.write(writer)?;
self.key_storage.write(writer)?;
}
_ => return Err(DecodeError::InvalidValue),
};
+ let local_csv = Readable::read(reader)?;
let key_storage = Readable::read(reader)?;
prev_local_commitment,
current_htlc_cache,
prev_htlc_cache,
+ local_csv,
key_storage,
claimable_outpoints,
pending_claim_requests,
}
impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
- pub(super) fn new(destination_script: Script, keys: ChanSigner, funding_redeemscript: Script, logger: Arc<Logger>) -> Self {
+ pub(super) fn new(destination_script: Script, keys: ChanSigner, funding_redeemscript: Script, local_csv: u16, logger: Arc<Logger>) -> Self {
let key_storage = keys;
prev_local_commitment: None,
current_htlc_cache: None,
prev_htlc_cache: None,
+ local_csv,
key_storage,
pending_claim_requests: HashMap::new(),
claimable_outpoints: HashMap::new(),
}
None
}
+
+ pub(super) fn get_fully_signed_htlc_tx(&mut self, txid: Sha256dHash, htlc_index: u32, preimage: Option<PaymentPreimage>) -> Option<Transaction> {
+ //TODO: store preimage in OnchainTxHandler
+ if let Some(ref local_commitment) = self.local_commitment {
+ if local_commitment.txid() == txid {
+ if let Some(ref htlc_cache) = self.current_htlc_cache {
+ if let Some(htlc) = htlc_cache.per_htlc.get(&htlc_index) {
+ if !htlc.0.offered && preimage.is_none() { return None; }; // If we don't have preimage for HTLC-Success, don't try to generate
+ let htlc_secret = if !htlc.0.offered { preimage } else { None }; // If we have a preimage for a HTLC-Timeout, don't use it that's likely a duplicate HTLC hash
+ let mut htlc_tx = chan_utils::build_htlc_transaction(&txid, htlc_cache.feerate_per_kw, self.local_csv, &htlc.0, &htlc_cache.local_keys.a_delayed_payment_key, &htlc_cache.local_keys.revocation_key);
+ self.key_storage.sign_htlc_transaction(&mut htlc_tx, htlc.1.as_ref().unwrap(), &htlc_secret, &htlc.0, &htlc_cache.local_keys.a_htlc_key, &htlc_cache.local_keys.b_htlc_key, &htlc_cache.local_keys.revocation_key, &htlc_cache.local_keys.per_commitment_point, &self.secp_ctx);
+ return Some(htlc_tx);
+
+ }
+ }
+ }
+ }
+ None
+ }
}