diff --git a/qr_code_crypto/src/lib.rs b/qr_code_crypto/src/lib.rs index bb89276..5de21c4 100644 --- a/qr_code_crypto/src/lib.rs +++ b/qr_code_crypto/src/lib.rs @@ -1,3 +1,5 @@ +use rust_decimal::prelude::*; + pub trait CryptoInvoice { fn new(address: &str) -> Self; fn set_query_part(self, name: &str, value: &str) -> Self; @@ -43,3 +45,9 @@ impl CryptoInvoice for MoneroInvoice { format!("monero:{}{}", self.address, self.query) } } + +impl MoneroInvoice { + pub fn add_amount(self, amount: Decimal) -> Self { + self.set_query_part("tx_amount", &amount.to_string()) + } +} diff --git a/qr_code_crypto/src/main.rs b/qr_code_crypto/src/main.rs index c9132fd..0ca4c5f 100644 --- a/qr_code_crypto/src/main.rs +++ b/qr_code_crypto/src/main.rs @@ -16,6 +16,7 @@ fn create_and_print_qr_invoice(invoice: impl CryptoInvoice) { fn main() { let monero_donation_adress = "888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H".to_string(); - let monero_invoice = MoneroInvoice::new(&monero_donation_adress); + let monero_invoice = + MoneroInvoice::new(&monero_donation_adress).add_amount(Decimal::new(200, 2)); create_and_print_qr_invoice(monero_invoice); }