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

Implement get_notes_by_id endpoint #298

Merged
merged 14 commits into from
Apr 8, 2024
217 changes: 109 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion proto/proto/note.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ message NoteCreated {
digest.Digest note_id = 3;
account.AccountId sender = 4;
fixed64 tag = 5;
}
}
5 changes: 5 additions & 0 deletions proto/proto/requests.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ message SubmitProvenTransactionRequest {
bytes transaction = 1;
}

message GetNotesByIdRequest {
// List of NoteId's to be queried from the database
repeated digest.Digest note_ids = 1;
}

message ListNullifiersRequest {}

message ListAccountsRequest {}
Expand Down
5 changes: 5 additions & 0 deletions proto/proto/responses.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ message GetTransactionInputsResponse {

message SubmitProvenTransactionResponse {}

message GetNotesByIdResponse {
// Lists Note's returned by the database
repeated note.Note notes = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems these are missing the details (i.e. the note's script/inputs/etc.):

message Note {
fixed32 block_num = 1;
uint32 note_index = 2;
digest.Digest note_id = 3;
account.AccountId sender = 4;
fixed64 tag = 5;
merkle.MerklePath merkle_path = 7;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this message is missing a details field.

This message represents getting a list of notes. Each note will have their own details field indeed. But the GetNoteById message should not return details but only a list of notes.

If you want to see the Note message with a details field, then see this PR when I make the modification to the db: #300

}

message ListNullifiersResponse {
// Lists all nullifiers of the current chain
repeated smt.SmtLeafEntry nullifiers = 1;
Expand Down
1 change: 1 addition & 0 deletions proto/proto/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "responses.proto";
service Api {
rpc CheckNullifiers(requests.CheckNullifiersRequest) returns (responses.CheckNullifiersResponse) {}
rpc GetBlockHeaderByNumber(requests.GetBlockHeaderByNumberRequest) returns (responses.GetBlockHeaderByNumberResponse) {}
rpc GetNotesById(requests.GetNotesByIdRequest) returns (responses.GetNotesByIdResponse) {}
rpc SyncState(requests.SyncStateRequest) returns (responses.SyncStateResponse) {}
rpc SubmitProvenTransaction(requests.SubmitProvenTransactionRequest) returns (responses.SubmitProvenTransactionResponse) {}
rpc GetAccountDetails(requests.GetAccountDetailsRequest) returns (responses.GetAccountDetailsResponse) {}
Expand Down
1 change: 1 addition & 0 deletions proto/proto/store.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ service Api {
rpc CheckNullifiers(requests.CheckNullifiersRequest) returns (responses.CheckNullifiersResponse) {}
rpc GetBlockHeaderByNumber(requests.GetBlockHeaderByNumberRequest) returns (responses.GetBlockHeaderByNumberResponse) {}
rpc GetBlockInputs(requests.GetBlockInputsRequest) returns (responses.GetBlockInputsResponse) {}
rpc GetNotesById(requests.GetNotesByIdRequest) returns (responses.GetNotesByIdResponse) {}
rpc GetTransactionInputs(requests.GetTransactionInputsRequest) returns (responses.GetTransactionInputsResponse) {}
rpc SyncState(requests.SyncStateRequest) returns (responses.SyncStateResponse) {}
rpc ListNullifiers(requests.ListNullifiersRequest) returns (responses.ListNullifiersResponse) {}
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/account.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/block_header.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/block_producer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// Generated client implementations.
pub mod api_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/digest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// A hash digest, the result of a hash function.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/merkle.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/mmr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/note.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
9 changes: 9 additions & 0 deletions proto/src/generated/requests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -103,6 +104,14 @@ pub struct SubmitProvenTransactionRequest {
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetNotesByIdRequest {
/// List of NoteId's to be queried from the database
#[prost(message, repeated, tag = "1")]
pub note_ids: ::prost::alloc::vec::Vec<super::digest::Digest>,
}
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListNullifiersRequest {}
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
9 changes: 9 additions & 0 deletions proto/src/generated/responses.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -126,6 +127,14 @@ pub struct SubmitProvenTransactionResponse {}
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetNotesByIdResponse {
/// Lists Note's returned by the database
#[prost(message, repeated, tag = "1")]
pub notes: ::prost::alloc::vec::Vec<super::note::Note>,
}
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListNullifiersResponse {
/// Lists all nullifiers of the current chain
#[prost(message, repeated, tag = "1")]
Expand Down
79 changes: 79 additions & 0 deletions proto/src/generated/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// Generated client implementations.
pub mod api_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
Expand Down Expand Up @@ -134,6 +135,28 @@ pub mod api_client {
.insert(GrpcMethod::new("rpc.Api", "GetBlockHeaderByNumber"));
self.inner.unary(req, path, codec).await
}
pub async fn get_notes_by_id(
&mut self,
request: impl tonic::IntoRequest<super::super::requests::GetNotesByIdRequest>,
) -> std::result::Result<
tonic::Response<super::super::responses::GetNotesByIdResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/rpc.Api/GetNotesById");
let mut req = request.into_request();
req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetNotesById"));
self.inner.unary(req, path, codec).await
}
pub async fn sync_state(
&mut self,
request: impl tonic::IntoRequest<super::super::requests::SyncStateRequest>,
Expand Down Expand Up @@ -234,6 +257,13 @@ pub mod api_server {
tonic::Response<super::super::responses::GetBlockHeaderByNumberResponse>,
tonic::Status,
>;
async fn get_notes_by_id(
&self,
request: tonic::Request<super::super::requests::GetNotesByIdRequest>,
) -> std::result::Result<
tonic::Response<super::super::responses::GetNotesByIdResponse>,
tonic::Status,
>;
async fn sync_state(
&self,
request: tonic::Request<super::super::requests::SyncStateRequest>,
Expand Down Expand Up @@ -436,6 +466,55 @@ pub mod api_server {
};
Box::pin(fut)
}
"/rpc.Api/GetNotesById" => {
#[allow(non_camel_case_types)]
struct GetNotesByIdSvc<T: Api>(pub Arc<T>);
impl<
T: Api,
> tonic::server::UnaryService<
super::super::requests::GetNotesByIdRequest,
> for GetNotesByIdSvc<T> {
type Response = super::super::responses::GetNotesByIdResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
super::super::requests::GetNotesByIdRequest,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Api>::get_notes_by_id(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = GetNotesByIdSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/rpc.Api/SyncState" => {
#[allow(non_camel_case_types)]
struct SyncStateSvc<T: Api>(pub Arc<T>);
Expand Down
1 change: 1 addition & 0 deletions proto/src/generated/smt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// An entry in a leaf.
#[derive(Eq, PartialOrd, Ord, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
79 changes: 79 additions & 0 deletions proto/src/generated/store.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// Generated client implementations.
pub mod api_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
Expand Down Expand Up @@ -182,6 +183,28 @@ pub mod api_client {
req.extensions_mut().insert(GrpcMethod::new("store.Api", "GetBlockInputs"));
self.inner.unary(req, path, codec).await
}
pub async fn get_notes_by_id(
&mut self,
request: impl tonic::IntoRequest<super::super::requests::GetNotesByIdRequest>,
) -> std::result::Result<
tonic::Response<super::super::responses::GetNotesByIdResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/store.Api/GetNotesById");
let mut req = request.into_request();
req.extensions_mut().insert(GrpcMethod::new("store.Api", "GetNotesById"));
self.inner.unary(req, path, codec).await
}
pub async fn get_transaction_inputs(
&mut self,
request: impl tonic::IntoRequest<
Expand Down Expand Up @@ -365,6 +388,13 @@ pub mod api_server {
tonic::Response<super::super::responses::GetBlockInputsResponse>,
tonic::Status,
>;
async fn get_notes_by_id(
&self,
request: tonic::Request<super::super::requests::GetNotesByIdRequest>,
) -> std::result::Result<
tonic::Response<super::super::responses::GetNotesByIdResponse>,
tonic::Status,
>;
async fn get_transaction_inputs(
&self,
request: tonic::Request<super::super::requests::GetTransactionInputsRequest>,
Expand Down Expand Up @@ -684,6 +714,55 @@ pub mod api_server {
};
Box::pin(fut)
}
"/store.Api/GetNotesById" => {
#[allow(non_camel_case_types)]
struct GetNotesByIdSvc<T: Api>(pub Arc<T>);
impl<
T: Api,
> tonic::server::UnaryService<
super::super::requests::GetNotesByIdRequest,
> for GetNotesByIdSvc<T> {
type Response = super::super::responses::GetNotesByIdResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
super::super::requests::GetNotesByIdRequest,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Api>::get_notes_by_id(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = GetNotesByIdSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/store.Api/GetTransactionInputs" => {
#[allow(non_camel_case_types)]
struct GetTransactionInputsSvc<T: Api>(pub Arc<T>);
Expand Down
Loading
Loading