From 5dd679ef0ea316088a9eae9fe57405ff689ec249 Mon Sep 17 00:00:00 2001 From: Lucas Sunsi Abreu Date: Mon, 2 Sep 2024 14:45:02 -0300 Subject: [PATCH] avoid needless mut on calls --- src/lib.rs | 85 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c9e2e36..68f46e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -189,20 +189,22 @@ impl Interceptor for LndInterceptor { } impl Lnd { - pub async fn get_info(&mut self) -> Result { + pub async fn get_info(&self) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "GetInfo"); - self.lightning + self.clone() + .lightning .get_info(GetInfoRequest {}) .with_context(opentelemetry::Context::current_with_span(span)) .await .map(Response::into_inner) } - pub async fn add_invoice(&mut self, invoice: Invoice) -> Result { + pub async fn add_invoice(&self, invoice: Invoice) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "AddInvoice"); - self.lightning + self.clone() + .lightning .add_invoice(invoice) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -210,13 +212,14 @@ impl Lnd { } pub async fn add_hold_invoice( - &mut self, + &self, hash: Vec, value: i64, ) -> Result { let span = span!(self.tracer => "lnrpc". "Invoices" / "AddHoldInvoice"); self.invoices + .clone() .add_hold_invoice(AddHoldInvoiceRequest { hash, value, @@ -227,33 +230,33 @@ impl Lnd { .map(Response::into_inner) } - pub async fn cancel_invoice( - &mut self, - payment_hash: Vec, - ) -> Result { + pub async fn cancel_invoice(&self, payment_hash: Vec) -> Result { let span = span!(self.tracer => "lnrpc". "Invoices" / "CancelInvoice"); self.invoices + .clone() .cancel_invoice(CancelInvoiceMsg { payment_hash }) .with_context(opentelemetry::Context::current_with_span(span)) .await .map(Response::into_inner) } - pub async fn settle_invoice(&mut self, preimage: Vec) -> Result { + pub async fn settle_invoice(&self, preimage: Vec) -> Result { let span = span!(self.tracer => "lnrpc". "Invoices" / "SettleInvoice"); self.invoices + .clone() .settle_invoice(SettleInvoiceMsg { preimage }) .with_context(opentelemetry::Context::current_with_span(span)) .await .map(Response::into_inner) } - pub async fn channel_balance(&mut self) -> Result { + pub async fn channel_balance(&self) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "ChannelBalance"); self.lightning + .clone() .channel_balance(ChannelBalanceRequest {}) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -261,7 +264,7 @@ impl Lnd { } pub async fn list_payments( - &mut self, + &self, include_incomplete: bool, index_offset: u64, max_payments: u64, @@ -270,6 +273,7 @@ impl Lnd { let span = span!(self.tracer => "lnrpc". "Lightning" / "ListPayments"); self.lightning + .clone() .list_payments(ListPaymentsRequest { include_incomplete, index_offset, @@ -283,7 +287,7 @@ impl Lnd { } pub async fn list_invoices( - &mut self, + &self, pending_only: bool, index_offset: u64, num_max_invoices: u64, @@ -292,6 +296,7 @@ impl Lnd { let span = span!(self.tracer => "lnrpc". "Lightning" / "ListInvoices"); self.lightning + .clone() .list_invoices(ListInvoiceRequest { pending_only, index_offset, @@ -305,22 +310,24 @@ impl Lnd { } pub async fn send_payment_sync( - &mut self, + &self, send_request: SendRequest, ) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "SendPaymentSync"); self.lightning + .clone() .send_payment_sync(send_request) .with_context(opentelemetry::Context::current_with_span(span)) .await .map(Response::into_inner) } - pub async fn wallet_balance(&mut self) -> Result { + pub async fn wallet_balance(&self) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "WalletBalance"); self.lightning + .clone() .wallet_balance(WalletBalanceRequest::default()) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -328,12 +335,13 @@ impl Lnd { } pub async fn forwarding_history( - &mut self, + &self, req: ForwardingHistoryRequest, ) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "ForwardingHistory"); self.lightning + .clone() .forwarding_history(req) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -341,12 +349,13 @@ impl Lnd { } pub async fn list_channels( - &mut self, + &self, req: ListChannelsRequest, ) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "ListChannels"); self.lightning + .clone() .list_channels(req) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -354,35 +363,35 @@ impl Lnd { } pub async fn closed_channels( - &mut self, + &self, req: ClosedChannelsRequest, ) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "ClosedChannels"); self.lightning + .clone() .closed_channels(req) .with_context(opentelemetry::Context::current_with_span(span)) .await .map(Response::into_inner) } - pub async fn new_address( - &mut self, - req: NewAddressRequest, - ) -> Result { + pub async fn new_address(&self, req: NewAddressRequest) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "NewAddress"); self.lightning + .clone() .new_address(req) .with_context(opentelemetry::Context::current_with_span(span)) .await .map(Response::into_inner) } - pub async fn pending_channels(&mut self) -> Result { + pub async fn pending_channels(&self) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "PendingChannels"); self.lightning + .clone() .pending_channels(PendingChannelsRequest {}) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -390,12 +399,13 @@ impl Lnd { } pub async fn channel_acceptor( - &mut self, + &self, req: impl tonic::IntoStreamingRequest, ) -> Result, Status> { let span = span!(self.tracer => "lnrpc". "Lightning" / "ChannelAcceptor"); self.lightning + .clone() .channel_acceptor(req) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -403,22 +413,24 @@ impl Lnd { } pub async fn close_channel( - &mut self, + &self, req: CloseChannelRequest, ) -> Result, Status> { let span = span!(self.tracer => "lnrpc". "Lighting" / "CloseChannel"); self.lightning + .clone() .close_channel(req) .with_context(opentelemetry::Context::current_with_span(span)) .await .map(Response::into_inner) } - pub async fn send_coins(&mut self, req: SendCoinsRequest) -> Result { + pub async fn send_coins(&self, req: SendCoinsRequest) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "SendCoins"); self.lightning + .clone() .send_coins(req) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -428,12 +440,13 @@ impl Lnd { impl Lnd { pub async fn send_payment( - &mut self, + &self, req: SendPaymentRequest, ) -> Result, Status> { let span = span!(self.tracer => "lnrpc". "Router" / "SendPaymentV2"); self.router + .clone() .send_payment_v2(req) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -441,13 +454,14 @@ impl Lnd { } pub async fn track_payment( - &mut self, + &self, payment_hash: Vec, no_inflight_updates: bool, ) -> Result, Status> { let span = span!(self.tracer => "lnrpc". "Router" / "TrackPaymentV2"); self.router + .clone() .track_payment_v2(TrackPaymentRequest { no_inflight_updates, payment_hash, @@ -460,16 +474,17 @@ impl Lnd { pub trait LookupInvoice { fn lookup_invoice( - &mut self, + &self, payment_hash: Vec, ) -> impl std::future::Future> + Send; } impl LookupInvoice for Lnd { - async fn lookup_invoice(&mut self, payment_hash: Vec) -> Result { + async fn lookup_invoice(&self, payment_hash: Vec) -> Result { let span = span!(self.tracer => "lnrpc". "Invoices" / "LookupInvoiceV2"); self.invoices + .clone() .lookup_invoice_v2(LookupInvoiceMsg { lookup_modifier: LookupModifier::Default as i32, invoice_ref: Some(InvoiceRef::PaymentHash(payment_hash)), @@ -482,19 +497,20 @@ impl LookupInvoice for Lnd { pub trait SubscribeSingleInvoice { fn subscribe_single_invoice( - &mut self, + &self, r_hash: Vec, ) -> impl std::future::Future, Status>> + Send; } impl SubscribeSingleInvoice for Lnd { async fn subscribe_single_invoice( - &mut self, + &self, r_hash: Vec, ) -> Result, Status> { let span = span!(self.tracer => "lnrpc". "Invoices" / "SubscribeSingleInvoice"); self.invoices + .clone() .subscribe_single_invoice(SubscribeSingleInvoiceRequest { r_hash }) .with_context(opentelemetry::Context::current_with_span(span)) .await @@ -504,16 +520,17 @@ impl SubscribeSingleInvoice for Lnd { pub trait DecodePayReq { fn decode_pay_req( - &mut self, + &self, pay_req: String, ) -> impl std::future::Future> + Send; } impl DecodePayReq for Lnd { - async fn decode_pay_req(&mut self, pay_req: String) -> Result { + async fn decode_pay_req(&self, pay_req: String) -> Result { let span = span!(self.tracer => "lnrpc". "Lightning" / "DecodePayReq"); self.lightning + .clone() .decode_pay_req(PayReqString { pay_req }) .with_context(opentelemetry::Context::current_with_span(span)) .await