Skip to content
Merged
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
1 change: 1 addition & 0 deletions crates/proto/src/domain/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl TryFrom<proto::account::AccountStorageHeader> for AccountStorageHeader {
// ================================================================================================

/// Represents a request for an account proof.
#[derive(Debug)]
pub struct AccountRequest {
pub account_id: AccountId,
// If not present, the latest account proof references the latest available
Expand Down
23 changes: 13 additions & 10 deletions crates/rpc/src/server/api/get_account.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use miden_node_proto::domain::account::{AccountRequest, AccountStorageRequest, SlotData};
use miden_node_proto::domain::account::{
AccountRequest,
AccountResponse,
AccountStorageRequest,
SlotData,
};
use miden_node_proto::generated as proto;
use miden_node_store::GetAccountError;
use miden_node_utils::limiter::QueryParamStorageMapKeyTotalLimit;
Expand All @@ -10,21 +15,19 @@ use super::{COMPONENT, RpcService, check};

#[tonic::async_trait]
impl proto::server::rpc_api::GetAccount for RpcService {
type Input = proto::rpc::AccountRequest;
type Output = proto::rpc::AccountResponse;
type Input = AccountRequest;
type Output = AccountResponse;

fn decode(request: proto::rpc::AccountRequest) -> tonic::Result<Self::Input> {
Ok(request)
AccountRequest::try_from(request).map_err(Into::into)
}

fn encode(output: Self::Output) -> tonic::Result<proto::rpc::AccountResponse> {
Ok(output)
Ok(output.into())
}

async fn handle(&self, raw_request: Self::Input) -> tonic::Result<Self::Output> {
debug!(target: COMPONENT, ?raw_request);

let request = AccountRequest::try_from(raw_request.clone())?;
async fn handle(&self, request: Self::Input) -> tonic::Result<Self::Output> {
debug!(target: COMPONENT, ?request);

let span = Span::current();
span.set_attribute("account.id", request.account_id);
Expand All @@ -50,7 +53,7 @@ impl proto::server::rpc_api::GetAccount for RpcService {

let account_data =
self.store.get_account(request).await.map_err(get_account_error_to_status)?;
Ok(account_data.into())
Ok(account_data)
}
}

Expand Down
7 changes: 4 additions & 3 deletions crates/rpc/src/server/api/get_note_script_by_root.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use miden_node_proto::decode::read_root;
use miden_node_proto::generated as proto;
use miden_protocol::note::NoteScript;
use tonic::Status;
use tracing::debug;

Expand All @@ -8,14 +9,14 @@ use super::{COMPONENT, RpcService, database_error_to_status};
#[tonic::async_trait]
impl proto::server::rpc_api::GetNoteScriptByRoot for RpcService {
type Input = proto::note::NoteScriptRoot;
type Output = proto::rpc::MaybeNoteScript;
type Output = Option<NoteScript>;

fn decode(request: proto::note::NoteScriptRoot) -> tonic::Result<Self::Input> {
Ok(request)
}

fn encode(output: Self::Output) -> tonic::Result<proto::rpc::MaybeNoteScript> {
Ok(output)
Ok(proto::rpc::MaybeNoteScript { script: output.map(Into::into) })
}

async fn handle(&self, request: Self::Input) -> tonic::Result<Self::Output> {
Expand All @@ -28,6 +29,6 @@ impl proto::server::rpc_api::GetNoteScriptByRoot for RpcService {
.await
.map_err(|err| database_error_to_status(&err))?;

Ok(proto::rpc::MaybeNoteScript { script: script.map(Into::into) })
Ok(script)
}
}
9 changes: 5 additions & 4 deletions crates/rpc/src/server/api/get_notes_by_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use miden_node_proto::decode::convert_digests_to_words;
use miden_node_proto::generated as proto;
use miden_node_proto::generated::note::CommittedNote;
use miden_node_store::NoteRecord;
use miden_node_utils::limiter::QueryParamNoteIdLimit;
use miden_protocol::Word;
Expand All @@ -13,14 +14,14 @@ use super::{COMPONENT, RpcService, check, database_error_to_status};
#[tonic::async_trait]
impl proto::server::rpc_api::GetNotesById for RpcService {
type Input = proto::note::NoteIdList;
type Output = proto::note::CommittedNoteList;
type Output = Vec<CommittedNote>;

fn decode(request: proto::note::NoteIdList) -> tonic::Result<Self::Input> {
Ok(request)
}

fn encode(output: Self::Output) -> tonic::Result<proto::note::CommittedNoteList> {
Ok(output)
fn encode(notes: Self::Output) -> tonic::Result<proto::note::CommittedNoteList> {
Ok(proto::note::CommittedNoteList { notes })
}

async fn handle(&self, request: Self::Input) -> tonic::Result<Self::Output> {
Expand All @@ -39,7 +40,7 @@ impl proto::server::rpc_api::GetNotesById for RpcService {
.map(note_record_to_proto)
.collect();

Ok(proto::note::CommittedNoteList { notes })
Ok(notes)
}
}

Expand Down
Loading