Skip to content

Commit 16080ce

Browse files
committed
Rename {Signed,}RawInvoice::hash to avoid naming collisions
Now that `{Signed,}RawInvoice` implement the std `Hash` trait, having a method called `hash` is ambiguous. Instead, we rename the `hash` methods `signed_hash` to make it clear that the hash is the one used for the purpose of signing the invoice.
1 parent 15a5966 commit 16080ce

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lightning-invoice/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl SignedRawInvoice {
745745
}
746746

747747
/// The hash of the `RawInvoice` that was signed.
748-
pub fn hash(&self) -> &[u8; 32] {
748+
pub fn signed_hash(&self) -> &[u8; 32] {
749749
&self.hash
750750
}
751751

@@ -853,8 +853,8 @@ impl RawInvoice {
853853
hash
854854
}
855855

856-
/// Calculate the hash of the encoded `RawInvoice`
857-
pub fn hash(&self) -> [u8; 32] {
856+
/// Calculate the hash of the encoded `RawInvoice` which should be signed
857+
pub fn signed_hash(&self) -> [u8; 32] {
858858
use bech32::ToBase32;
859859

860860
RawInvoice::hash_from_parts(
@@ -872,7 +872,7 @@ impl RawInvoice {
872872
pub fn sign<F, E>(self, sign_method: F) -> Result<SignedRawInvoice, E>
873873
where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
874874
{
875-
let raw_hash = self.hash();
875+
let raw_hash = self.signed_hash();
876876
let hash = Message::from_slice(&raw_hash[..])
877877
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
878878
let signature = sign_method(&hash)?;
@@ -1591,7 +1591,7 @@ mod test {
15911591
0xd5, 0x18, 0xe1, 0xc9
15921592
];
15931593

1594-
assert_eq!(invoice.hash(), expected_hash)
1594+
assert_eq!(invoice.signed_hash(), expected_hash)
15951595
}
15961596

15971597
#[test]

0 commit comments

Comments
 (0)