Skip to content

Commit 1d60fa3

Browse files
committed
fixup: Add ClaimId::from_htlcs
1 parent 318a244 commit 1d60fa3

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

lightning/src/chain/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use bitcoin::block::{Block, Header};
1313
use bitcoin::constants::genesis_block;
1414
use bitcoin::hash_types::{BlockHash, Txid};
15+
use bitcoin::hashes::sha256::Hash as Sha256;
16+
use bitcoin::hashes::{Hash, HashEngine};
1517
use bitcoin::network::Network;
1618
use bitcoin::script::{Script, ScriptBuf};
1719
use bitcoin::secp256k1::PublicKey;
@@ -21,6 +23,7 @@ use crate::chain::transaction::{OutPoint, TransactionData};
2123
use crate::impl_writeable_tlv_based;
2224
use crate::ln::types::ChannelId;
2325
use crate::sign::ecdsa::EcdsaChannelSigner;
26+
use crate::sign::HTLCDescriptor;
2427

2528
#[allow(unused_imports)]
2629
use crate::prelude::*;
@@ -442,3 +445,14 @@ where
442445
/// This is not exported to bindings users as we just use [u8; 32] directly.
443446
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
444447
pub struct ClaimId(pub [u8; 32]);
448+
449+
impl ClaimId {
450+
pub(crate) fn from_htlcs(htlcs: &[HTLCDescriptor]) -> ClaimId {
451+
let mut engine = Sha256::engine();
452+
for htlc in htlcs {
453+
engine.input(&htlc.commitment_txid.to_byte_array());
454+
engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
455+
}
456+
ClaimId(Sha256::from_engine(engine).to_byte_array())
457+
}
458+
}

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
1515
use bitcoin::amount::Amount;
1616
use bitcoin::hash_types::{BlockHash, Txid};
17-
use bitcoin::hashes::sha256::Hash as Sha256;
18-
use bitcoin::hashes::{Hash, HashEngine};
17+
use bitcoin::hashes::Hash;
1918
use bitcoin::locktime::absolute::LockTime;
2019
use bitcoin::script::{Script, ScriptBuf};
2120
use bitcoin::secp256k1;
@@ -882,12 +881,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
882881
// claim, which will always be unique per request. Once a claim ID
883882
// is generated, it is assigned and remains unchanged, even if the
884883
// underlying set of HTLCs changes.
885-
let mut engine = Sha256::engine();
886-
for htlc in htlcs {
887-
engine.input(&htlc.commitment_txid.to_byte_array());
888-
engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
889-
}
890-
ClaimId(Sha256::from_engine(engine).to_byte_array())
884+
ClaimId::from_htlcs(htlcs)
891885
},
892886
};
893887
debug_assert!(self.pending_claim_requests.get(&claim_id).is_none());

lightning/src/events/bump_transaction/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ use crate::util::logger::Logger;
4141
use bitcoin::amount::Amount;
4242
use bitcoin::consensus::Encodable;
4343
use bitcoin::constants::WITNESS_SCALE_FACTOR;
44-
use bitcoin::hashes::sha256::Hash as Sha256;
45-
use bitcoin::hashes::{Hash, HashEngine};
4644
use bitcoin::locktime::absolute::LockTime;
4745
use bitcoin::secp256k1;
4846
use bitcoin::secp256k1::ecdsa::Signature;
@@ -941,12 +939,7 @@ where
941939
} else {
942940
// Generate a new claim_id to map a user-provided utxo to this
943941
// particular set of HTLCs via `select_confirmed_utxos`.
944-
let mut engine = Sha256::engine();
945-
for htlc in selected_htlcs {
946-
engine.input(&htlc.commitment_txid.to_byte_array());
947-
engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
948-
}
949-
ClaimId(Sha256::from_engine(engine).to_byte_array())
942+
ClaimId::from_htlcs(&selected_htlcs)
950943
};
951944

952945
log_info!(

0 commit comments

Comments
 (0)