Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
feat: add new gRPC endpoints (get Profile, get Event and network Heal…
Browse files Browse the repository at this point in the history
…th) (#48)
  • Loading branch information
kehiy authored Nov 18, 2023
1 parent 53310fe commit 8204b2d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
7 changes: 7 additions & 0 deletions rpc/proto/network.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package network;
service Network {
rpc GetNetworkInfo(GetNetworkInfoRequest) returns (GetNetworkInfoResponse);
rpc GetNodeInfo(GetNodeInfoRequest) returns (GetNodeInfoResponse);
rpc NetworkHealth(NetworkHealthRequest) returns (NetworkHealthResponse);
}

message GetNetworkInfoRequest {}
Expand All @@ -23,6 +24,12 @@ message GetNodeInfoResponse {
bytes peer_id = 3;
}

message NetworkHealthRequest {}

message NetworkHealthResponse {
bool is_healthy = 1;
}

message PeerInfo {
int32 status = 1;
string moniker = 2;
Expand Down
26 changes: 26 additions & 0 deletions rpc/proto/nostr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@ package nostr;

service NostrRPC {
rpc GetAllPublicKeys(GetAllPublicKeysRequest) returns (GetAllPublicKeysResponse);
rpc GetProfile(GetProfileRequest) returns (GetProfileResponse);
rpc GetEvent(GetEventRequest) returns (GetEventResponse);
}

message GetAllPublicKeysRequest {}

message GetAllPublicKeysResponse {
repeated string public_keys = 1;
}

message GetProfileRequest {
string npub = 1; // TODO: Adding get by NIP-05 address?
}

message GetProfileResponse {
string name = 1;
string about = 2;
string avatar = 3;
string banner = 4;
repeated string nip5_address = 5;
}

message GetEventRequest {
string nevent = 1;
}

message GetEventResponse {
string author_npub = 1;
string content = 2;
string published_at = 3;
int32 kind = 4;
string sig = 5;
}
13 changes: 12 additions & 1 deletion rpc/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tonic::{Request, Response, Status};
use network::network_server::Network;
use network::{
GetNetworkInfoRequest, GetNetworkInfoResponse, GetNodeInfoRequest, GetNodeInfoResponse,
PeerInfo,
NetworkHealthRequest, NetworkHealthResponse, PeerInfo,
};

pub mod network {
Expand Down Expand Up @@ -53,4 +53,15 @@ impl Network for NetworkService {

Ok(Response::new(reply))
}

async fn network_health(
&self,
request: Request<NetworkHealthRequest>,
) -> Result<Response<NetworkHealthResponse>, Status> {
let _req = request.into_inner();

let reply = NetworkHealthResponse { is_healthy: false };

Ok(Response::new(reply))
}
}
39 changes: 38 additions & 1 deletion rpc/src/nostr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use tonic::{Request, Response, Status};

use nostr::nostr_rpc_server::NostrRpc;
use nostr::{GetAllPublicKeysRequest, GetAllPublicKeysResponse};
use nostr::{
GetAllPublicKeysRequest, GetAllPublicKeysResponse, GetEventRequest, GetEventResponse,
GetProfileRequest, GetProfileResponse,
};

pub mod nostr {
tonic::include_proto!("nostr");
Expand All @@ -24,4 +27,38 @@ impl NostrRpc for NostrRpcService {

Ok(Response::new(reply))
}

async fn get_profile(
&self,
request: Request<GetProfileRequest>,
) -> Result<Response<GetProfileResponse>, Status> {
let _req = request.into_inner();

let reply = GetProfileResponse {
about: "".to_string(),
avatar: "".to_string(),
banner: "".to_string(),
name: "".to_string(),
nip5_address: vec!["".to_string()],
};

Ok(Response::new(reply))
}

async fn get_event(
&self,
request: Request<GetEventRequest>,
) -> Result<Response<GetEventResponse>, Status> {
let _req = request.into_inner();

let reply = GetEventResponse {
author_npub: "".to_string(),
content: "".to_string(),
published_at: "".to_string(),
kind: 0,
sig: "".to_string(),
};

Ok(Response::new(reply))
}
}

0 comments on commit 8204b2d

Please sign in to comment.