Skip to content

Commit

Permalink
feat: GetWalletBalance call
Browse files Browse the repository at this point in the history
  • Loading branch information
markettes committed Nov 20, 2024
1 parent 84af88b commit 315bc25
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Proto/nodeguard.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions src/Rpc/NodeGuardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Task<GetNewWalletAddressResponse> GetNewWalletAddress(GetNewWalletAddressRequest

Task<GetAvailableWalletsResponse>
GetAvailableWallets(GetAvailableWalletsRequest request, ServerCallContext context);

Task<GetWalletBalanceResponse> GetWalletBalance(GetWalletBalanceRequest request, ServerCallContext context);

Task<GetNodesResponse> GetNodes(GetNodesRequest request, ServerCallContext context);

Expand Down Expand Up @@ -377,6 +379,28 @@ public override async Task<GetAvailableWalletsResponse> GetAvailableWallets(GetA
throw new RpcException(new Status(StatusCode.Internal, e.Message));
}
}

public override async Task<GetWalletBalanceResponse> 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<AddNodeResponse> AddNode(AddNodeRequest request, ServerCallContext context)
{
Expand Down

0 comments on commit 315bc25

Please sign in to comment.