From 8b3516208a6465ae8a5f1a987a5d1fd2585527a7 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 10 Sep 2022 20:31:12 +0000 Subject: [PATCH] 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. --- lightning-invoice/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 4fc58271..defe958a 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -745,7 +745,7 @@ impl SignedRawInvoice { } /// The hash of the `RawInvoice` that was signed. - pub fn hash(&self) -> &[u8; 32] { + pub fn signable_hash(&self) -> &[u8; 32] { &self.hash } @@ -853,8 +853,8 @@ impl RawInvoice { hash } - /// Calculate the hash of the encoded `RawInvoice` - pub fn hash(&self) -> [u8; 32] { + /// Calculate the hash of the encoded `RawInvoice` which should be signed. + pub fn signable_hash(&self) -> [u8; 32] { use bech32::ToBase32; RawInvoice::hash_from_parts( @@ -872,7 +872,7 @@ impl RawInvoice { pub fn sign(self, sign_method: F) -> Result where F: FnOnce(&Message) -> Result { - let raw_hash = self.hash(); + let raw_hash = self.signable_hash(); let hash = Message::from_slice(&raw_hash[..]) .expect("Hash is 32 bytes long, same as MESSAGE_SIZE"); let signature = sign_method(&hash)?; @@ -1591,7 +1591,7 @@ mod test { 0xd5, 0x18, 0xe1, 0xc9 ]; - assert_eq!(invoice.hash(), expected_hash) + assert_eq!(invoice.signable_hash(), expected_hash) } #[test] -- 2.30.2