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..7b2de096 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,36 @@ public override async Task GetAvailableWallets(GetA throw new RpcException(new Status(StatusCode.Internal, e.Message)); } } + + public override async Task GetWalletBalance(GetWalletBalanceRequest request, ServerCallContext context) + { + try + { + 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 + }; + } + catch (Exception e) + { + _logger?.LogError(e, "Error getting wallet balance through gRPC"); + throw new RpcException(new Status(StatusCode.Internal, e.Message)); + } + } + public override async Task AddNode(AddNodeRequest request, ServerCallContext context) {