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
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "freenet-stdlib"
version = "0.1.28"
version = "0.1.29"
edition = "2021"
rust-version = "1.71.1"
publish = true
Expand Down
69 changes: 57 additions & 12 deletions rust/src/client_api/client_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ use crate::generated::common::{
ApplicationMessage as FbsApplicationMessage, ApplicationMessageArgs, ContractCode,
ContractCodeArgs, ContractContainer as FbsContractContainer, ContractContainerArgs,
ContractInstanceId as FbsContractInstanceId, ContractInstanceIdArgs,
ContractKey as FbsContractKey, ContractKeyArgs,
ContractType, DeltaUpdate, DeltaUpdateArgs, GetSecretRequest as FbsGetSecretRequest,
GetSecretRequestArgs, GetSecretResponse as FbsGetSecretResponse, GetSecretResponseArgs,
RelatedDeltaUpdate, RelatedDeltaUpdateArgs, RelatedStateAndDeltaUpdate,
RelatedStateAndDeltaUpdateArgs, RelatedStateUpdate, RelatedStateUpdateArgs,
SecretsId as FbsSecretsId, SecretsIdArgs, StateAndDeltaUpdate, StateAndDeltaUpdateArgs,
StateUpdate, StateUpdateArgs, UpdateData as FbsUpdateData, UpdateDataArgs, UpdateDataType,
WasmContractV1, WasmContractV1Args,
ContractKey as FbsContractKey, ContractKeyArgs, ContractType, DeltaUpdate, DeltaUpdateArgs,
GetSecretRequest as FbsGetSecretRequest, GetSecretRequestArgs,
GetSecretResponse as FbsGetSecretResponse, GetSecretResponseArgs, RelatedDeltaUpdate,
RelatedDeltaUpdateArgs, RelatedStateAndDeltaUpdate, RelatedStateAndDeltaUpdateArgs,
RelatedStateUpdate, RelatedStateUpdateArgs, SecretsId as FbsSecretsId, SecretsIdArgs,
StateAndDeltaUpdate, StateAndDeltaUpdateArgs, StateUpdate, StateUpdateArgs,
UpdateData as FbsUpdateData, UpdateDataArgs, UpdateDataType, WasmContractV1,
WasmContractV1Args,
};
use crate::generated::host_response::{
finish_host_response_buffer, ClientResponse as FbsClientResponse, ClientResponseArgs,
ContextUpdated as FbsContextUpdated, ContextUpdatedArgs,
ContractResponse as FbsContractResponse, ContractResponseArgs, ContractResponseType,
DelegateKey as FbsDelegateKey, DelegateKeyArgs, DelegateResponse as FbsDelegateResponse,
DelegateResponseArgs, GetResponse as FbsGetResponse, GetResponseArgs,
HostResponse as FbsHostResponse, HostResponseArgs, HostResponseType, Ok as FbsOk, OkArgs,
OutboundDelegateMsg as FbsOutboundDelegateMsg, OutboundDelegateMsgArgs,
OutboundDelegateMsgType, PutResponse as FbsPutResponse, PutResponseArgs,
RequestUserInput as FbsRequestUserInput, RequestUserInputArgs,
HostResponse as FbsHostResponse, HostResponseArgs, HostResponseType, NotFound as FbsNotFound,
NotFoundArgs, Ok as FbsOk, OkArgs, OutboundDelegateMsg as FbsOutboundDelegateMsg,
OutboundDelegateMsgArgs, OutboundDelegateMsgType, PutResponse as FbsPutResponse,
PutResponseArgs, RequestUserInput as FbsRequestUserInput, RequestUserInputArgs,
SetSecretRequest as FbsSetSecretRequest, SetSecretRequestArgs,
UpdateNotification as FbsUpdateNotification, UpdateNotificationArgs,
UpdateResponse as FbsUpdateResponse, UpdateResponseArgs,
Expand Down Expand Up @@ -1349,6 +1349,41 @@ impl HostResponse {
Ok(builder.finished_data().to_vec())
}
ContractResponse::SubscribeResponse { .. } => todo!(),
ContractResponse::NotFound { instance_id } => {
let instance_data = builder.create_vector(instance_id.as_bytes());
let instance_offset = FbsContractInstanceId::create(
&mut builder,
&ContractInstanceIdArgs {
data: Some(instance_data),
},
);

let not_found_offset = FbsNotFound::create(
&mut builder,
&NotFoundArgs {
instance_id: Some(instance_offset),
},
);

let contract_response_offset = FbsContractResponse::create(
&mut builder,
&ContractResponseArgs {
contract_response_type: ContractResponseType::NotFound,
contract_response: Some(not_found_offset.as_union_value()),
},
);

let response_offset = FbsHostResponse::create(
&mut builder,
&HostResponseArgs {
response: Some(contract_response_offset.as_union_value()),
response_type: HostResponseType::ContractResponse,
},
);

finish_host_response_buffer(&mut builder, response_offset);
Ok(builder.finished_data().to_vec())
}
},
HostResponse::DelegateResponse { key, values } => {
let key_data = builder.create_vector(key.bytes());
Expand Down Expand Up @@ -1588,6 +1623,9 @@ impl Display for HostResponse {
ContractResponse::SubscribeResponse { key, .. } => {
f.write_fmt(format_args!("subscribe response for `{key}`"))
}
ContractResponse::NotFound { instance_id } => {
f.write_fmt(format_args!("not found for `{instance_id}`"))
}
},
HostResponse::DelegateResponse { .. } => write!(f, "delegate responses"),
HostResponse::Ok => write!(f, "ok response"),
Expand Down Expand Up @@ -1624,6 +1662,13 @@ pub enum ContractResponse<T = WrappedState> {
key: ContractKey,
subscribed: bool,
},
/// Contract was not found after exhaustive search.
/// This is an explicit response that distinguishes "contract doesn't exist"
/// from other failure modes like timeouts or network errors.
NotFound {
/// The instance ID that was searched for.
instance_id: ContractInstanceId,
},
}

impl<T> From<ContractResponse<T>> for HostResponse<T> {
Expand Down
1 change: 0 additions & 1 deletion rust/src/contract_interface/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ impl std::hash::Hash for ContractKey {
}
}


impl From<ContractKey> for ContractInstanceId {
fn from(key: ContractKey) -> Self {
key.instance
Expand Down
8 changes: 4 additions & 4 deletions rust/src/generated/client_request_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4707,7 +4707,7 @@ pub mod client_request {
/// `root_as_client_request_unchecked`.
pub fn root_as_client_request(
buf: &[u8],
) -> Result<ClientRequest<'_>, flatbuffers::InvalidFlatbuffer> {
) -> Result<ClientRequest, flatbuffers::InvalidFlatbuffer> {
flatbuffers::root::<ClientRequest>(buf)
}
#[inline]
Expand All @@ -4719,7 +4719,7 @@ pub mod client_request {
/// `size_prefixed_root_as_client_request_unchecked`.
pub fn size_prefixed_root_as_client_request(
buf: &[u8],
) -> Result<ClientRequest<'_>, flatbuffers::InvalidFlatbuffer> {
) -> Result<ClientRequest, flatbuffers::InvalidFlatbuffer> {
flatbuffers::size_prefixed_root::<ClientRequest>(buf)
}
#[inline]
Expand Down Expand Up @@ -4752,14 +4752,14 @@ pub mod client_request {
/// Assumes, without verification, that a buffer of bytes contains a ClientRequest and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid `ClientRequest`.
pub unsafe fn root_as_client_request_unchecked(buf: &[u8]) -> ClientRequest<'_> {
pub unsafe fn root_as_client_request_unchecked(buf: &[u8]) -> ClientRequest {
flatbuffers::root_unchecked::<ClientRequest>(buf)
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a size prefixed ClientRequest and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid size prefixed `ClientRequest`.
pub unsafe fn size_prefixed_root_as_client_request_unchecked(buf: &[u8]) -> ClientRequest<'_> {
pub unsafe fn size_prefixed_root_as_client_request_unchecked(buf: &[u8]) -> ClientRequest {
flatbuffers::size_prefixed_root_unchecked::<ClientRequest>(buf)
}
#[inline]
Expand Down
Loading
Loading