Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetReceivedByAddress endpoint to gRPC server #1967

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,24 @@ func (s *walletServer) NextAddress(ctx context.Context, req *pb.NextAddressReque
}, nil
}

func (s *walletServer) GetReceivedByAddress(ctx context.Context, req *pb.GetReceivedByAddressRequest) (
*pb.GetReceivedByAddressResponse, error) {
w := s.wallet
addr, err := decodeAddress(req.Address, w.ChainParams())
if err != nil {
return nil, err
}
total, err := w.TotalReceivedForAddr(ctx, addr, 1)
if err != nil {
if errors.Is(err, errors.NotExist) {
return nil, status.Errorf(codes.NotFound, "address not found in wallet")
}
return nil, translateError(err)
}

return &pb.GetReceivedByAddressResponse{Amount: int64(total)}, nil
}

func (s *walletServer) ImportPrivateKey(ctx context.Context, req *pb.ImportPrivateKeyRequest) (
*pb.ImportPrivateKeyResponse, error) {

Expand Down
11 changes: 10 additions & 1 deletion rpc/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ service WalletService {
rpc Rescan (RescanRequest) returns (stream RescanResponse);
rpc NextAccount (NextAccountRequest) returns (NextAccountResponse);
rpc NextAddress (NextAddressRequest) returns (NextAddressResponse);
rpc GetReceivedByAddress (GetReceivedByAddressRequest) returns (GetReceivedByAddressResponse);
rpc ImportPrivateKey (ImportPrivateKeyRequest) returns (ImportPrivateKeyResponse);
rpc ImportScript(ImportScriptRequest) returns (ImportScriptResponse);
rpc FundTransaction (FundTransactionRequest) returns (FundTransactionResponse);
Expand Down Expand Up @@ -1291,4 +1292,12 @@ message ProcessUnmanagedTicketsRequest {
uint32 change_account = 4;
}

message ProcessUnmanagedTicketsResponse {}
message ProcessUnmanagedTicketsResponse {}

message GetReceivedByAddressRequest {
string address = 1;
}

message GetReceivedByAddressResponse {
int64 amount = 1;
}
Loading