From 315bc25bf5a2438a769439cd043350e2e66ec922 Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 20 Nov 2024 16:50:30 +0100 Subject: [PATCH] feat: GetWalletBalance call --- src/Proto/nodeguard.proto | 17 +++++++++++++++++ src/Rpc/NodeGuardService.cs | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/Proto/nodeguard.proto b/src/Proto/nodeguard.proto index 59fe8629..afc5f691 100644 --- a/src/Proto/nodeguard.proto +++ b/src/Proto/nodeguard.proto @@ -34,6 +34,12 @@ service NodeGuardService { Gets a list of available wallets */ rpc GetAvailableWallets(GetAvailableWalletsRequest) returns (GetAvailableWalletsResponse); + + /* + Get balance from a specific wallet + */ + rpc GetWalletBalance(GetWalletBalanceRequest) returns (GetWalletBalanceResponse); + /* Opens a channel to a given node */ @@ -168,6 +174,17 @@ message GetAvailableWalletsResponse { repeated Wallet wallets = 1; } +message GetWalletBalanceRequest { + int32 wallet_id = 1; +} + +message GetWalletBalanceResponse { + // Confirmed balance in satoshis + int64 confirmed_balance = 1; + // Unconfirmed balance in satoshis + int64 unconfirmed_balance = 2; +} + message AddNodeRequest{ string pub_key = 1; string name = 2; diff --git a/src/Rpc/NodeGuardService.cs b/src/Rpc/NodeGuardService.cs index 1a3b9433..ae209394 100644 --- a/src/Rpc/NodeGuardService.cs +++ b/src/Rpc/NodeGuardService.cs @@ -28,6 +28,8 @@ Task GetNewWalletAddress(GetNewWalletAddressRequest Task GetAvailableWallets(GetAvailableWalletsRequest request, ServerCallContext context); + + Task GetWalletBalance(GetWalletBalanceRequest request, ServerCallContext context); Task GetNodes(GetNodesRequest request, ServerCallContext context); @@ -377,6 +379,28 @@ public override async Task GetAvailableWallets(GetA throw new RpcException(new Status(StatusCode.Internal, e.Message)); } } + + public override async Task GetWalletBalance(GetWalletBalanceRequest request, ServerCallContext context) + { + var wallet = await _walletRepository.GetById(request.WalletId); + if (wallet == null) + { + throw new RpcException(new Status(StatusCode.NotFound, "Wallet not found")); + } + + var balance = await _lightningService.GetWalletBalance(wallet); + if (balance == null) + { + throw new RpcException(new Status(StatusCode.Internal, "Error getting wallet balance")); + } + + return new GetWalletBalanceResponse + { + ConfirmedBalance = ((Money)balance.Confirmed).Satoshi, + UnconfirmedBalance = ((Money)balance.Unconfirmed).Satoshi + }; + } + public override async Task AddNode(AddNodeRequest request, ServerCallContext context) {