Skip to content

Commit

Permalink
feat: add rpc endpoint for getting account details
Browse files Browse the repository at this point in the history
  • Loading branch information
polydez committed Mar 29, 2024
1 parent be2be66 commit fbcfd6b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 4 deletions.
1 change: 1 addition & 0 deletions proto/proto/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ service Api {
rpc GetBlockHeaderByNumber(requests.GetBlockHeaderByNumberRequest) returns (responses.GetBlockHeaderByNumberResponse) {}
rpc SyncState(requests.SyncStateRequest) returns (responses.SyncStateResponse) {}
rpc SubmitProvenTransaction(requests.SubmitProvenTransactionRequest) returns (responses.SubmitProvenTransactionResponse) {}
rpc GetPublicAccountDetails(requests.GetPublicAccountDetailsRequest) returns (responses.GetPublicAccountDetailsResponse) {}
}
86 changes: 86 additions & 0 deletions proto/src/generated/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,33 @@ pub mod api_client {
.insert(GrpcMethod::new("rpc.Api", "SubmitProvenTransaction"));
self.inner.unary(req, path, codec).await
}
pub async fn get_public_account_details(
&mut self,
request: impl tonic::IntoRequest<
super::super::requests::GetPublicAccountDetailsRequest,
>,
) -> std::result::Result<
tonic::Response<super::super::responses::GetPublicAccountDetailsResponse>,
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/GetPublicAccountDetails",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("rpc.Api", "GetPublicAccountDetails"));
self.inner.unary(req, path, codec).await
}
}
}
/// Generated server implementations.
Expand Down Expand Up @@ -224,6 +251,15 @@ pub mod api_server {
tonic::Response<super::super::responses::SubmitProvenTransactionResponse>,
tonic::Status,
>;
async fn get_public_account_details(
&self,
request: tonic::Request<
super::super::requests::GetPublicAccountDetailsRequest,
>,
) -> std::result::Result<
tonic::Response<super::super::responses::GetPublicAccountDetailsResponse>,
tonic::Status,
>;
}
#[derive(Debug)]
pub struct ApiServer<T: Api> {
Expand Down Expand Up @@ -501,6 +537,56 @@ pub mod api_server {
};
Box::pin(fut)
}
"/rpc.Api/GetPublicAccountDetails" => {
#[allow(non_camel_case_types)]
struct GetPublicAccountDetailsSvc<T: Api>(pub Arc<T>);
impl<
T: Api,
> tonic::server::UnaryService<
super::super::requests::GetPublicAccountDetailsRequest,
> for GetPublicAccountDetailsSvc<T> {
type Response = super::super::responses::GetPublicAccountDetailsResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
super::super::requests::GetPublicAccountDetailsRequest,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Api>::get_public_account_details(&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 = GetPublicAccountDetailsSvc(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)
}
_ => {
Box::pin(async move {
Ok(
Expand Down
25 changes: 21 additions & 4 deletions rpc/src/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use anyhow::Result;
use miden_node_proto::generated::{
block_producer::api_client as block_producer_client,
requests::{
CheckNullifiersRequest, GetBlockHeaderByNumberRequest, SubmitProvenTransactionRequest,
SyncStateRequest,
CheckNullifiersRequest, GetBlockHeaderByNumberRequest, GetPublicAccountDetailsRequest,
SubmitProvenTransactionRequest, SyncStateRequest,
},
responses::{
CheckNullifiersResponse, GetBlockHeaderByNumberResponse, SubmitProvenTransactionResponse,
SyncStateResponse,
CheckNullifiersResponse, GetBlockHeaderByNumberResponse, GetPublicAccountDetailsResponse,
SubmitProvenTransactionResponse, SyncStateResponse,
},
rpc::api_server,
store::api_client as store_client,
Expand Down Expand Up @@ -132,4 +132,21 @@ impl api_server::Api for RpcApi {

self.block_producer.clone().submit_proven_transaction(request).await
}

/// Returns details for public (on-chain) account by id.
#[instrument(
target = "miden-rpc",
name = "rpc:get_public_account_details",
skip_all,
ret(level = "debug"),
err
)]
async fn get_public_account_details(
&self,
request: tonic::Request<GetPublicAccountDetailsRequest>,
) -> std::result::Result<Response<GetPublicAccountDetailsResponse>, Status> {
debug!(target: COMPONENT, request = ?request.get_ref());

self.store.clone().get_public_account_details(request).await
}
}

0 comments on commit fbcfd6b

Please sign in to comment.