Skip to content

Commit

Permalink
Api : deferred call endpoint versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
modship committed Dec 11, 2024
1 parent cb30010 commit 820ed1e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
30 changes: 30 additions & 0 deletions massa-api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,16 @@ impl MassaRpcServer for API<Public> {
&self,
req: Vec<DeferredCallsQuoteRequest>,
) -> RpcResult<Vec<DeferredCallsQuoteResponse>> {
let current_network_version = self
.0
.keypair_factory
.mip_store
.get_network_version_current();

if current_network_version < 1 {
return Err(ApiError::NotFound.into());
}

if req.len() as u64 > self.0.api_settings.max_arguments {
return Err(ApiError::BadRequest("too many arguments".into()).into());
}
Expand Down Expand Up @@ -1205,6 +1215,16 @@ impl MassaRpcServer for API<Public> {
&self,
arg: Vec<String>,
) -> RpcResult<Vec<DeferredCallResponse>> {
let current_network_version = self
.0
.keypair_factory
.mip_store
.get_network_version_current();

if current_network_version < 1 {
return Err(ApiError::NotFound.into());
}

if arg.len() as u64 > self.0.api_settings.max_arguments {
return Err(ApiError::BadRequest("too many arguments".into()).into());
}
Expand Down Expand Up @@ -1245,6 +1265,16 @@ impl MassaRpcServer for API<Public> {
&self,
slots: Vec<Slot>,
) -> RpcResult<Vec<DeferredCallsSlotResponse>> {
let current_network_version = self
.0
.keypair_factory
.mip_store
.get_network_version_current();

if current_network_version < 1 {
return Err(ApiError::NotFound.into());
}

if slots.len() as u64 > self.0.api_settings.max_arguments {
return Err(ApiError::BadRequest("too many arguments".into()).into());
}
Expand Down
19 changes: 19 additions & 0 deletions massa-execution-exports/src/mapping_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use massa_proto_rs::massa::model::v1 as grpc_model;
/// Convert a `grpc_api::ScExecutionEventsRequest` to a `ScExecutionEventsRequest`
pub fn to_querystate_filter(
query: grpc_api::ExecutionQueryRequestItem,
network_version: u32,
) -> Result<ExecutionQueryRequestItem, ModelsError> {
if let Some(item) = query.request_item {
match item {
Expand Down Expand Up @@ -135,6 +136,12 @@ pub fn to_querystate_filter(
Ok(ExecutionQueryRequestItem::Events(event_filter))
}
exec::RequestItem::DeferredCallQuote(value) => {
if network_version < 1 {
return Err(ModelsError::InvalidVersionError(
"deferred call quote is not supported in this network version".to_string(),
));
}

Ok(ExecutionQueryRequestItem::DeferredCallQuote {
target_slot: value
.target_slot
Expand All @@ -147,10 +154,22 @@ pub fn to_querystate_filter(
})
}
exec::RequestItem::DeferredCallInfo(info) => {
if network_version < 1 {
return Err(ModelsError::InvalidVersionError(
"deferred call quote is not supported in this network version".to_string(),
));
}

let id = DeferredCallId::from_str(&info.call_id)?;
Ok(ExecutionQueryRequestItem::DeferredCallInfo(id))
}
exec::RequestItem::DeferredCallsBySlot(value) => {
if network_version < 1 {
return Err(ModelsError::InvalidVersionError(
"deferred call quote is not supported in this network version".to_string(),
));
}

Ok(ExecutionQueryRequestItem::DeferredCallsBySlot(
value
.slot
Expand Down
4 changes: 3 additions & 1 deletion massa-grpc/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,13 @@ pub(crate) fn query_state(
grpc: &MassaPublicGrpc,
request: tonic::Request<grpc_api::QueryStateRequest>,
) -> Result<grpc_api::QueryStateResponse, GrpcError> {
let current_network_version = grpc.keypair_factory.mip_store.get_network_version_current();

let queries = request
.into_inner()
.queries
.into_iter()
.map(to_querystate_filter)
.map(|q| to_querystate_filter(q, current_network_version))
.collect::<Result<Vec<_>, _>>()?;

if queries.is_empty() {
Expand Down

0 comments on commit 820ed1e

Please sign in to comment.