Rename `{Signed,}RawInvoice::hash` to avoid naming collisions
authorMatt Corallo <git@bluematt.me>
Sat, 10 Sep 2022 20:31:12 +0000 (20:31 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 12 Sep 2022 16:26:58 +0000 (16:26 +0000)
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

index 4fc58271ed722f17d3b0392a7612915cbcc45a97..defe958a1c05406cf8eb6cdfe409c9958c26458b 100644 (file)
@@ -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<F, E>(self, sign_method: F) -> Result<SignedRawInvoice, E>
                where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
        {
-               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]