projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
`rustfmt`: `lightning-transaction-sync/tests/integration_tests.rs`
[rust-lightning]
/
lightning-invoice
/
src
/
lib.rs
diff --git
a/lightning-invoice/src/lib.rs
b/lightning-invoice/src/lib.rs
index 920d44b1561dbf12f8afdc1e3e5105eb8a5aefef..e427bf3ccb99965a4ba50d8609c3dad186cf3658 100644
(file)
--- a/
lightning-invoice/src/lib.rs
+++ b/
lightning-invoice/src/lib.rs
@@
-42,8
+42,8
@@
extern crate serde;
use std::time::SystemTime;
use bech32::u5;
use std::time::SystemTime;
use bech32::u5;
-use bitcoin::{Address, Network, PubkeyHash, ScriptHash};
-use bitcoin::address::
{Payload, WitnessProgram, WitnessVersion}
;
+use bitcoin::{Address, Network, PubkeyHash, ScriptHash
, WitnessProgram, WitnessVersion
};
+use bitcoin::address::
Payload
;
use bitcoin::hashes::{Hash, sha256};
use lightning::ln::features::Bolt11InvoiceFeatures;
use lightning::util::invoice::construct_invoice_preimage;
use bitcoin::hashes::{Hash, sha256};
use lightning::ln::features::Bolt11InvoiceFeatures;
use lightning::util::invoice::construct_invoice_preimage;
@@
-577,7
+577,13
@@
impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
/// Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
pub fn amount_milli_satoshis(mut self, amount_msat: u64) -> Self {
/// Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
pub fn amount_milli_satoshis(mut self, amount_msat: u64) -> Self {
- let amount = amount_msat * 10; // Invoices are denominated in "pico BTC"
+ let amount = match amount_msat.checked_mul(10) { // Invoices are denominated in "pico BTC"
+ Some(amt) => amt,
+ None => {
+ self.error = Some(CreationError::InvalidAmount);
+ return self
+ }
+ };
let biggest_possible_si_prefix = SiPrefix::values_desc()
.iter()
.find(|prefix| amount % prefix.multiplier() == 0)
let biggest_possible_si_prefix = SiPrefix::values_desc()
.iter()
.find(|prefix| amount % prefix.multiplier() == 0)
@@
-872,8
+878,7
@@
impl SignedRawBolt11Invoice {
/// Recovers the public key used for signing the invoice from the recoverable signature.
pub fn recover_payee_pub_key(&self) -> Result<PayeePubKey, secp256k1::Error> {
/// Recovers the public key used for signing the invoice from the recoverable signature.
pub fn recover_payee_pub_key(&self) -> Result<PayeePubKey, secp256k1::Error> {
- let hash = Message::from_slice(&self.hash[..])
- .expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
+ let hash = Message::from_digest(self.hash);
Ok(PayeePubKey(Secp256k1::new().recover_ecdsa(
&hash,
Ok(PayeePubKey(Secp256k1::new().recover_ecdsa(
&hash,
@@
-898,8
+903,7
@@
impl SignedRawBolt11Invoice {
let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
.expect("One is always present");
let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
.expect("One is always present");
- let hash = Message::from_slice(&self.hash[..])
- .expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
+ let hash = Message::from_digest(self.hash);
let secp_context = Secp256k1::new();
let verification_result = secp_context.verify_ecdsa(
let secp_context = Secp256k1::new();
let verification_result = secp_context.verify_ecdsa(
@@
-993,8
+997,7
@@
impl RawBolt11Invoice {
where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
{
let raw_hash = self.signable_hash();
where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
{
let raw_hash = self.signable_hash();
- let hash = Message::from_slice(&raw_hash[..])
- .expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
+ let hash = Message::from_digest(raw_hash);
let signature = sign_method(&hash)?;
Ok(SignedRawBolt11Invoice {
let signature = sign_method(&hash)?;
Ok(SignedRawBolt11Invoice {