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

Remove unnecessary delegate message type #7

Merged
merged 10 commits into from
Sep 26, 2023
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
6 changes: 3 additions & 3 deletions rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ fn main() {
.arg("--rust")
.arg("-o")
.arg("src")
.arg("../../schemas/flatbuffers/common.fbs")
.arg("../../schemas/flatbuffers/client_request.fbs")
.arg("../../schemas/flatbuffers/host_response.fbs")
.arg("../schemas/flatbuffers/common.fbs")
.arg("../schemas/flatbuffers/client_request.fbs")
.arg("../schemas/flatbuffers/host_response.fbs")
.status();
if let Err(err) = status {
println!("failed compiling flatbuffers schema: {err}");
Expand Down
16 changes: 0 additions & 16 deletions rust/src/client_api/client_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use crate::host_response_generated::host_response::{
HostResponse as FbsHostResponse, HostResponseArgs, HostResponseType, Ok as FbsOk, OkArgs,
OutboundDelegateMsg as FbsOutboundDelegateMsg, OutboundDelegateMsgArgs,
OutboundDelegateMsgType, PutResponse as FbsPutResponse, PutResponseArgs,
RandomBytesRequest as FbsRandomBytesRequest, RandomBytesRequestArgs,
RequestUserInput as FbsRequestUserInput, RequestUserInputArgs,
SetSecretRequest as FbsSetSecretRequest, SetSecretRequestArgs,
UpdateNotification as FbsUpdateNotification, UpdateNotificationArgs,
Expand Down Expand Up @@ -1200,21 +1199,6 @@ impl HostResponse {
);
messages.push(msg);
}
OutboundDelegateMsg::RandomBytesRequest(size) => {
let data: u32 = *size as u32;
let request_offset = FbsRandomBytesRequest::create(
&mut builder,
&RandomBytesRequestArgs { data },
);
let msg = FbsOutboundDelegateMsg::create(
&mut builder,
&OutboundDelegateMsgArgs {
inbound_type: OutboundDelegateMsgType::RandomBytesRequest,
inbound: Some(request_offset.as_union_value()),
},
);
messages.push(msg);
}
OutboundDelegateMsg::GetSecretResponse(response) => {
let secret_key_data = builder.create_vector(response.key.key());
let secret_hash_data = builder.create_vector(response.key.hash());
Expand Down
153 changes: 5 additions & 148 deletions rust/src/client_request_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,16 @@ pub mod client_request {
since = "2.0.0",
note = "Use associated constants instead. This will no longer be generated in 2021."
)]
pub const ENUM_MAX_INBOUND_DELEGATE_MSG_TYPE: u8 = 5;
pub const ENUM_MAX_INBOUND_DELEGATE_MSG_TYPE: u8 = 4;
#[deprecated(
since = "2.0.0",
note = "Use associated constants instead. This will no longer be generated in 2021."
)]
#[allow(non_camel_case_types)]
pub const ENUM_VALUES_INBOUND_DELEGATE_MSG_TYPE: [InboundDelegateMsgType; 6] = [
pub const ENUM_VALUES_INBOUND_DELEGATE_MSG_TYPE: [InboundDelegateMsgType; 5] = [
InboundDelegateMsgType::NONE,
InboundDelegateMsgType::common_ApplicationMessage,
InboundDelegateMsgType::common_GetSecretResponse,
InboundDelegateMsgType::RandomBytes,
InboundDelegateMsgType::UserInputResponse,
InboundDelegateMsgType::common_GetSecretRequest,
];
Expand All @@ -252,17 +251,15 @@ pub mod client_request {
pub const NONE: Self = Self(0);
pub const common_ApplicationMessage: Self = Self(1);
pub const common_GetSecretResponse: Self = Self(2);
pub const RandomBytes: Self = Self(3);
pub const UserInputResponse: Self = Self(4);
pub const common_GetSecretRequest: Self = Self(5);
pub const UserInputResponse: Self = Self(3);
pub const common_GetSecretRequest: Self = Self(4);

pub const ENUM_MIN: u8 = 0;
pub const ENUM_MAX: u8 = 5;
pub const ENUM_MAX: u8 = 4;
pub const ENUM_VALUES: &'static [Self] = &[
Self::NONE,
Self::common_ApplicationMessage,
Self::common_GetSecretResponse,
Self::RandomBytes,
Self::UserInputResponse,
Self::common_GetSecretRequest,
];
Expand All @@ -272,7 +269,6 @@ pub mod client_request {
Self::NONE => Some("NONE"),
Self::common_ApplicationMessage => Some("common_ApplicationMessage"),
Self::common_GetSecretResponse => Some("common_GetSecretResponse"),
Self::RandomBytes => Some("RandomBytes"),
Self::UserInputResponse => Some("UserInputResponse"),
Self::common_GetSecretRequest => Some("common_GetSecretRequest"),
_ => None,
Expand Down Expand Up @@ -2269,120 +2265,6 @@ pub mod client_request {
ds.finish()
}
}
pub enum RandomBytesOffset {}
#[derive(Copy, Clone, PartialEq)]

pub struct RandomBytes<'a> {
pub _tab: flatbuffers::Table<'a>,
}

impl<'a> flatbuffers::Follow<'a> for RandomBytes<'a> {
type Inner = RandomBytes<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self {
_tab: flatbuffers::Table::new(buf, loc),
}
}
}

impl<'a> RandomBytes<'a> {
pub const VT_DATA: flatbuffers::VOffsetT = 4;

#[inline]
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
RandomBytes { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args RandomBytesArgs<'args>,
) -> flatbuffers::WIPOffset<RandomBytes<'bldr>> {
let mut builder = RandomBytesBuilder::new(_fbb);
if let Some(x) = args.data {
builder.add_data(x);
}
builder.finish()
}

#[inline]
pub fn data(&self) -> flatbuffers::Vector<'a, u8> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe {
self._tab
.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(
RandomBytes::VT_DATA,
None,
)
.unwrap()
}
}
}

impl flatbuffers::Verifiable for RandomBytes<'_> {
#[inline]
fn run_verifier(
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>(
"data",
Self::VT_DATA,
true,
)?
.finish();
Ok(())
}
}
pub struct RandomBytesArgs<'a> {
pub data: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, u8>>>,
}
impl<'a> Default for RandomBytesArgs<'a> {
#[inline]
fn default() -> Self {
RandomBytesArgs {
data: None, // required field
}
}
}

pub struct RandomBytesBuilder<'a: 'b, 'b> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b> RandomBytesBuilder<'a, 'b> {
#[inline]
pub fn add_data(&mut self, data: flatbuffers::WIPOffset<flatbuffers::Vector<'b, u8>>) {
self.fbb_
.push_slot_always::<flatbuffers::WIPOffset<_>>(RandomBytes::VT_DATA, data);
}
#[inline]
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> RandomBytesBuilder<'a, 'b> {
let start = _fbb.start_table();
RandomBytesBuilder {
fbb_: _fbb,
start_: start,
}
}
#[inline]
pub fn finish(self) -> flatbuffers::WIPOffset<RandomBytes<'a>> {
let o = self.fbb_.end_table(self.start_);
self.fbb_.required(o, RandomBytes::VT_DATA, "data");
flatbuffers::WIPOffset::new(o.value())
}
}

impl core::fmt::Debug for RandomBytes<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut ds = f.debug_struct("RandomBytes");
ds.field("data", &self.data());
ds.finish()
}
}
pub enum ClientResponseOffset {}
#[derive(Copy, Clone, PartialEq)]

Expand Down Expand Up @@ -2780,20 +2662,6 @@ pub mod client_request {
}
}

#[inline]
#[allow(non_snake_case)]
pub fn inbound_as_random_bytes(&self) -> Option<RandomBytes<'a>> {
if self.inbound_type() == InboundDelegateMsgType::RandomBytes {
let u = self.inbound();
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
Some(unsafe { RandomBytes::init_from_table(u) })
} else {
None
}
}

#[inline]
#[allow(non_snake_case)]
pub fn inbound_as_user_input_response(&self) -> Option<UserInputResponse<'a>> {
Expand Down Expand Up @@ -2837,7 +2705,6 @@ pub mod client_request {
match key {
InboundDelegateMsgType::common_ApplicationMessage => v.verify_union_variant::<flatbuffers::ForwardsUOffset<super::common::ApplicationMessage>>("InboundDelegateMsgType::common_ApplicationMessage", pos),
InboundDelegateMsgType::common_GetSecretResponse => v.verify_union_variant::<flatbuffers::ForwardsUOffset<super::common::GetSecretResponse>>("InboundDelegateMsgType::common_GetSecretResponse", pos),
InboundDelegateMsgType::RandomBytes => v.verify_union_variant::<flatbuffers::ForwardsUOffset<RandomBytes>>("InboundDelegateMsgType::RandomBytes", pos),
InboundDelegateMsgType::UserInputResponse => v.verify_union_variant::<flatbuffers::ForwardsUOffset<UserInputResponse>>("InboundDelegateMsgType::UserInputResponse", pos),
InboundDelegateMsgType::common_GetSecretRequest => v.verify_union_variant::<flatbuffers::ForwardsUOffset<super::common::GetSecretRequest>>("InboundDelegateMsgType::common_GetSecretRequest", pos),
_ => Ok(()),
Expand Down Expand Up @@ -2928,16 +2795,6 @@ pub mod client_request {
)
}
}
InboundDelegateMsgType::RandomBytes => {
if let Some(x) = self.inbound_as_random_bytes() {
ds.field("inbound", &x)
} else {
ds.field(
"inbound",
&"InvalidFlatbuffer: Union discriminant does not match value.",
)
}
}
InboundDelegateMsgType::UserInputResponse => {
if let Some(x) = self.inbound_as_user_input_response() {
ds.field("inbound", &x)
Expand Down
16 changes: 2 additions & 14 deletions rust/src/delegate_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,9 @@ pub trait DelegateInterface {
) -> Result<Vec<OutboundDelegateMsg>, DelegateError>;
}

#[non_exhaustive]
#[serde_as]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
// todo: add serde_as(Bytes)
pub struct DelegateContext(Vec<u8>);
pub struct DelegateContext(#[serde_as(as = "serde_with::Bytes")] Vec<u8>);

impl DelegateContext {
pub const MAX_SIZE: usize = 4096 * 10 * 10;
Expand Down Expand Up @@ -429,8 +428,6 @@ impl AsRef<[u8]> for DelegateContext {
pub enum InboundDelegateMsg<'a> {
ApplicationMessage(ApplicationMessage),
GetSecretResponse(GetSecretResponse),
// todo: remove this and replace by native freenet_stdlib contract api calls
RandomBytes(Vec<u8>),
UserResponse(#[serde(borrow)] UserInputResponse<'a>),
GetSecretRequest(GetSecretRequest),
}
Expand All @@ -440,7 +437,6 @@ impl InboundDelegateMsg<'_> {
match self {
InboundDelegateMsg::ApplicationMessage(r) => InboundDelegateMsg::ApplicationMessage(r),
InboundDelegateMsg::GetSecretResponse(r) => InboundDelegateMsg::GetSecretResponse(r),
InboundDelegateMsg::RandomBytes(b) => InboundDelegateMsg::RandomBytes(b),
InboundDelegateMsg::UserResponse(r) => InboundDelegateMsg::UserResponse(r.into_owned()),
InboundDelegateMsg::GetSecretRequest(r) => InboundDelegateMsg::GetSecretRequest(r),
}
Expand Down Expand Up @@ -508,12 +504,6 @@ impl<'a> TryFromFbs<&FbsInboundDelegateMsg<'a>> for InboundDelegateMsg<'a> {
};
Ok(InboundDelegateMsg::GetSecretResponse(get_secret))
}
InboundDelegateMsgType::RandomBytes => {
let random_bytes = msg.inbound_as_random_bytes().unwrap();
Ok(InboundDelegateMsg::RandomBytes(
random_bytes.data().bytes().to_vec(),
))
}
InboundDelegateMsgType::UserInputResponse => {
let user_response = msg.inbound_as_user_input_response().unwrap();
let user_response = UserInputResponse {
Expand Down Expand Up @@ -604,7 +594,6 @@ pub enum OutboundDelegateMsg {
// from the node
GetSecretRequest(GetSecretRequest),
SetSecretRequest(SetSecretRequest),
RandomBytesRequest(usize),
// GetContractRequest {
// mode: RelatedMode,
// contract_id: ContractInstanceId,
Expand All @@ -629,7 +618,6 @@ impl OutboundDelegateMsg {
match self {
OutboundDelegateMsg::ApplicationMessage(msg) => msg.processed,
OutboundDelegateMsg::GetSecretRequest(msg) => msg.processed,
OutboundDelegateMsg::RandomBytesRequest(_) => false,
OutboundDelegateMsg::SetSecretRequest(_) => false,
OutboundDelegateMsg::RequestUserInput(_) => true,
OutboundDelegateMsg::ContextUpdated(_) => true,
Expand Down
Loading