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

Chainmail: Rewrite in Rust #826

Merged
merged 19 commits into from
Sep 18, 2024
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
23 changes: 1 addition & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ if(DEFINED WASI_SDK_PREFIX)
${CMAKE_CURRENT_BINARY_DIR}/Tokens.wasm
${CMAKE_CURRENT_BINARY_DIR}/Transact.wasm
${CMAKE_CURRENT_BINARY_DIR}/VerifySig.wasm
${CMAKE_CURRENT_BINARY_DIR}/Webmail.wasm
${CMAKE_CURRENT_BINARY_DIR}/PSubjectiveService.wasm
${CMAKE_CURRENT_BINARY_DIR}/CounterService.wasm
${CMAKE_CURRENT_BINARY_DIR}/AsyncQueryService.wasm
Expand Down Expand Up @@ -235,7 +234,6 @@ set(JS_DIRS
services/user/Supervisor/ui:Supervisor_js
services/user/Explorer/ui:Explorer_js
services/user/Tokens/ui:Tokens_js
services/user/Webmail/ui:Webmail_js
)
set(ADMIN_DIR services/user/XAdmin/ui:XAdmin_js)
set(COMMON_LIB_DIR services/user/CommonApi/common/packages/common-lib/:CommonApiCommonLib_js)
Expand Down Expand Up @@ -311,7 +309,6 @@ add_rs_component(services/system/AuthSig/plugin:AuthPlugin auth_sig.wasm wasm32-
add_rs_component(services/user/Invite/plugin:InvitesPlugin invite.wasm wasm32-wasi ${AuthPlugin_DEP})
add_rs_component(services/user/Tokens/plugin:TokensPlugin tokens.wasm wasm32-wasi )
add_rs_component(services/user/Supervisor/plugin:TestsPlugin test.wasm wasm32-wasi )
add_rs_component(services/user/Webmail/plugin:WebmailPlugin webmail_plugin.wasm wasm32-wasi)
add_rs_component(services/user/ClientData/plugin:ClientDataPlugin clientdata.wasm wasm32-wasi )

set(WASM_PSIBASE_BYPRODUCTS
Expand Down Expand Up @@ -625,23 +622,6 @@ psibase_package(
DEPENDS ${InvitesPlugin_DEP}
)

psibase_package(
OUTPUT ${SERVICE_DIR}/Webmail.psi
NAME Webmail
VERSION ${PSIBASE_VERSION}
DESCRIPTION "This app provides a webmail client for authenticated asynchronous communication between network users"
PACKAGE_DEPENDS "Accounts(^${PSIBASE_VERSION})" "HttpServer(^${PSIBASE_VERSION})" "Nft(^${PSIBASE_VERSION})" "Tokens(^${PSIBASE_VERSION})"
SERVICE webmail
WASM ${CMAKE_CURRENT_BINARY_DIR}/Webmail.wasm
SERVER webmail
DATA ${COMPONENT_BIN_DIR}/${WebmailPlugin_OUTPUT_FILE} /plugin.wasm
DATA GLOB ${CMAKE_CURRENT_SOURCE_DIR}/services/user/Webmail/ui/dist/* /
INIT
DEPENDS ${Webmail_js_DEP}
DEPENDS wasm
DEPENDS ${WebmailPlugin_DEP}
)

psibase_package(
OUTPUT ${SERVICE_DIR}/Nft.psi
NAME Nft
Expand Down Expand Up @@ -746,7 +726,7 @@ psibase_package(
VERSION ${PSIBASE_VERSION}
DESCRIPTION "All development services"
PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate ClientData CommonApi CpuLimit
Docs Webmail Events Explorer Fractal Invite Nft Packages Producers HttpServer
Docs Events Explorer Fractal Invite Nft Packages Producers HttpServer
Sites SetCode Supervisor Symbol TokenUsers Tokens Transact Homepage
)

Expand Down Expand Up @@ -819,7 +799,6 @@ install(
${SERVICE_DIR}/TokenUsers.psi
${SERVICE_DIR}/Tokens.psi
${SERVICE_DIR}/Transact.psi
${SERVICE_DIR}/Webmail.psi
DESTINATION ${CMAKE_INSTALL_DATADIR}/psibase/packages/
COMPONENT ServerData)

Expand Down
2 changes: 1 addition & 1 deletion rust/fracpack/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{

pub use indexmap;

#[derive(Debug, Serialize, Deserialize, Pack, Unpack)]
#[derive(Debug, Clone, Serialize, Deserialize, Pack, Unpack)]
#[fracpack(fracpack_mod = "crate")]
pub struct Schema(IndexMap<String, AnyType>);

Expand Down
38 changes: 37 additions & 1 deletion rust/psibase/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use fracpack::{Pack, ToSchema, Unpack};
use serde::{Deserialize, Serialize};

/// Identify database to operate on
///
/// Native functions expose a set of databases which serve
/// various purposes. This enum identifies which database to
/// use when invoking those functions.
#[repr(u32)]
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum DbId {
/// Services should store their tables here
///
Expand Down Expand Up @@ -134,3 +137,36 @@ pub enum DbId {
/// This number may grow in the future
NumDatabases,
}

impl Pack for DbId {
const FIXED_SIZE: u32 = 4;

const VARIABLE_SIZE: bool = false;

fn pack(&self, dest: &mut Vec<u8>) {
(*self as u32).pack(dest);
}
}
impl<'a> Unpack<'a> for DbId {
const FIXED_SIZE: u32 = 4;

const VARIABLE_SIZE: bool = false;

fn unpack(src: &'a [u8], pos: &mut u32) -> fracpack::Result<Self> {
let u32_form = u32::unpack(src, pos)?;
if u32_form >= DbId::NumDatabases as u32 {
return Err(fracpack::Error::BadEnumIndex);
}
Ok(unsafe { std::mem::transmute(u32_form) })
}

fn verify(src: &'a [u8], pos: &mut u32) -> fracpack::Result<()> {
u32::verify(src, pos)
}
}

impl ToSchema for DbId {
fn schema(_builder: &mut fracpack::SchemaBuilder) -> fracpack::AnyType {
todo!()
}
}
11 changes: 9 additions & 2 deletions rust/psibase/src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{AccountNumber, MethodNumber};
use fracpack::{AnyType, FunctionType, SchemaBuilder};
use fracpack::{AnyType, FunctionType, Pack, SchemaBuilder, ToSchema, Unpack};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

type EventMap = IndexMap<MethodNumber, AnyType>;

type ActionMap = IndexMap<MethodNumber, FunctionType>;

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Pack, Unpack)]
#[fracpack(fracpack_mod = "fracpack")]
pub struct Schema {
pub service: AccountNumber,
pub types: fracpack::Schema,
Expand All @@ -17,6 +18,12 @@ pub struct Schema {
pub merkle: EventMap,
}

impl ToSchema for Schema {
fn schema(_builder: &mut SchemaBuilder) -> AnyType {
todo!()
}
}

pub trait ToActionsSchema {
fn to_schema(builder: &mut SchemaBuilder) -> IndexMap<MethodNumber, FunctionType>;
}
Expand Down
19 changes: 19 additions & 0 deletions rust/psibase/src/services/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[crate::service(name = "events", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
mod service {

#[action]
fn setSchema(schema: crate::Schema) {
unimplemented!()
}

#[action]
fn addIndex(
db_id: crate::DbId,
service: crate::AccountNumber,
event: crate::MethodNumber,
column: u8,
) {
unimplemented!()
}
}
2 changes: 2 additions & 0 deletions rust/psibase/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ pub mod auth_delegate;
pub mod auth_sig;
pub mod common_api;
pub mod cpu_limit;
pub mod events;
pub mod http_server;
#[allow(non_snake_case)]
pub mod invite;
#[allow(non_snake_case)]
pub mod nft;
pub mod packages;
pub mod producers;
pub mod r_events;
pub mod setcode;
pub mod sites;
pub mod tokens;
Expand Down
10 changes: 10 additions & 0 deletions rust/psibase/src/services/r_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[crate::service(name = "r-events", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
mod service {
use crate::HttpRequest;

#[action]
fn serveSys(request: HttpRequest) -> Option<crate::http::HttpReply> {
unimplemented!()
}
}
1 change: 0 additions & 1 deletion services/user/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ add("-debug")

if(DEFINED IS_WASM)
add_subdirectory(CommonApi)
add_subdirectory(Webmail)
add_subdirectory(Events)
add_subdirectory(Explorer)
add_subdirectory(Fractal)
Expand Down
7 changes: 0 additions & 7 deletions services/user/Webmail/CMakeLists.txt

This file was deleted.

Loading
Loading