diff --git a/CMakeLists.txt b/CMakeLists.txt index a1b7694bb..ef02c53ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,6 +244,7 @@ set(JS_DIRS services/user/Supervisor/ui:Supervisor_js services/user/Explorer/ui:Explorer_js services/user/Tokens/ui:Tokens_js + services/user/Chainmail/ui:Chainmail_js ) set(ADMIN_DIR services/user/XAdmin/ui:XAdmin_js) set(COMMON_LIB_DIR services/user/CommonApi/common/packages/common-lib/:CommonApiCommonLib_js) @@ -417,6 +418,12 @@ psibase_package( DEPENDS ${ClientDataPlugin_DEP} ) +cargo_psibase_package( + OUTPUT ${SERVICE_DIR}/Chainmail.psi + PATH services/user/Chainmail + DEPENDS ${Chainmail_js_DEP} +) + psibase_package( OUTPUT ${SERVICE_DIR}/AuthSig.psi NAME AuthSig @@ -738,7 +745,7 @@ psibase_package( NAME DevDefault VERSION ${PSIBASE_VERSION} DESCRIPTION "All development services" - PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate ClientData CommonApi CpuLimit + PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate Chainmail ClientData CommonApi CpuLimit Docs Events Explorer Fractal Invite Nft Packages Producers HttpServer Sites SetCode Supervisor Symbol TokenUsers Tokens Transact Homepage ) @@ -748,7 +755,7 @@ psibase_package( NAME ProdDefault VERSION ${PSIBASE_VERSION} DESCRIPTION "All production services" - PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate ClientData CommonApi CpuLimit + PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate Chainmail ClientData CommonApi CpuLimit Docs Events Explorer Fractal Invite Nft Packages Producers HttpServer Sites SetCode Supervisor Symbol Tokens Transact Homepage ) @@ -777,7 +784,7 @@ function(write_package_index target dir) endfunction() write_package_index(package-index ${SERVICE_DIR} - Accounts AuthAny AuthSig ClientData CommonApi CpuLimit DevDefault ProdDefault + Accounts AuthAny AuthSig Chainmail ClientData CommonApi CpuLimit DevDefault ProdDefault Docs Events Explorer Fractal Invite Nft Nop Minimal Packages Producers HttpServer Sites SetCode Supervisor Symbol TokenUsers Tokens Transact Homepage) @@ -787,6 +794,7 @@ install( ${SERVICE_DIR}/AuthAny.psi ${SERVICE_DIR}/AuthDelegate.psi ${SERVICE_DIR}/AuthSig.psi + ${SERVICE_DIR}/Chainmail.psi ${SERVICE_DIR}/ClientData.psi ${SERVICE_DIR}/CommonApi.psi ${SERVICE_DIR}/DevDefault.psi diff --git a/doc/psidk/src/development/services/rust-service/package.md b/doc/psidk/src/development/services/rust-service/package.md index b85d78ac5..ec08eeb43 100644 --- a/doc/psidk/src/development/services/rust-service/package.md +++ b/doc/psidk/src/development/services/rust-service/package.md @@ -21,6 +21,7 @@ Example: [package] name = "example" version = "0.1.0" +description = "An example package" [package.metadata.psibase] # Builds example.psi diff --git a/libraries/psibase/sdk/pack_service.cmake b/libraries/psibase/sdk/pack_service.cmake index 8c0f0d19e..0c634a12f 100644 --- a/libraries/psibase/sdk/pack_service.cmake +++ b/libraries/psibase/sdk/pack_service.cmake @@ -306,3 +306,42 @@ function(psibase_package) ) add_custom_target(${_NAME} ALL DEPENDS ${_OUTPUT}) endfunction() + +# Description: - Use this function when you want to add additional details to a package that is +# built/managed by cargo-psibase, as opposed to packages built entirely using CMake. +# OUTPUT - [Required] The package file. +# PATH - [Required] The path to the cargo workspace (e.g. `services/user/Branding`). +# DEPENDS ... - Targets that this target depends on +function(cargo_psibase_package) + cmake_parse_arguments(ARG "" "PATH;OUTPUT;DEPENDS" "" ${ARGN}) + + if(NOT ARG_PATH OR NOT ARG_OUTPUT) + message(FATAL_ERROR "Both PATH and OUTPUT must be specified for cargo_psibase_package") + endif() + + # Set variables + get_filename_component(PACKAGE_NAME ${ARG_OUTPUT} NAME) + get_filename_component(TARGET_NAME ${ARG_OUTPUT} NAME_WE) + set(PACKAGE_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_PATH}/target/wasm32-wasi/release/packages/${PACKAGE_NAME}) + + # Build the package if needed + ExternalProject_Add(${TARGET_NAME}_ext + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_PATH} + BUILD_BYPRODUCTS ${PACKAGE_OUTPUT} + CONFIGURE_COMMAND "" + BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/rust/release/cargo-psibase package + --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_PATH}/Cargo.toml + INSTALL_COMMAND "" + BUILD_ALWAYS 1 + DEPENDS ${ARG_DEPENDS} cargo-psibase + ) + + add_custom_command( + OUTPUT ${ARG_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PACKAGE_OUTPUT} ${ARG_OUTPUT} + DEPENDS ${PACKAGE_OUTPUT} + DEPENDS ${TARGET_NAME}_ext + VERBATIM + ) + add_custom_target(${TARGET_NAME} ALL DEPENDS ${ARG_OUTPUT} cargo-psibase) +endfunction() \ No newline at end of file diff --git a/libraries/psio/include/psio/check.hpp b/libraries/psio/include/psio/check.hpp index 0d3a4b229..7e029a6df 100644 --- a/libraries/psio/include/psio/check.hpp +++ b/libraries/psio/include/psio/check.hpp @@ -17,7 +17,7 @@ namespace psio template [[noreturn]] void abort_error(const T& msg) { -#ifdef __cpp_exceptions +#ifndef COMPILING_WASM throw std::runtime_error((std::string)error_to_str(msg)); #else psibase::abortMessage(error_to_str(msg)); diff --git a/libraries/psio/include/psio/view.hpp b/libraries/psio/include/psio/view.hpp index 877022bde..4c5961633 100644 --- a/libraries/psio/include/psio/view.hpp +++ b/libraries/psio/include/psio/view.hpp @@ -221,7 +221,7 @@ namespace psio (void)unpack_numeric(&offset, this->data, pos, 4); if (offset == 1) { -#ifdef __cpp_exceptions +#ifndef COMPILING_WASM throw std::bad_optional_access{}; #else abort_error("bad optional access"); @@ -340,7 +340,7 @@ namespace psio } else { -#ifdef __cpp_exceptions +#ifndef COMPILING_WASM throw std::bad_variant_access{}; #else abort_error("bad variant access"); @@ -358,7 +358,7 @@ namespace psio } else { -#ifdef __cpp_exceptions +#ifndef COMPILING_WASM throw std::bad_variant_access{}; #else abort_error("bad variant access"); @@ -556,7 +556,7 @@ namespace psio } else { -#ifdef __cpp_exceptions +#ifndef COMPILING_WASM throw std::out_of_range("view our of range"); #else abort_error("view our of range"); @@ -625,7 +625,7 @@ namespace psio } else { -#ifdef __cpp_exceptions +#ifndef COMPILING_WASM throw std::out_of_range("view out of range"); #else abort_error("view out of range"); diff --git a/programs/psinode/main.cpp b/programs/psinode/main.cpp index 0d99e7d49..e481f0313 100644 --- a/programs/psinode/main.cpp +++ b/programs/psinode/main.cpp @@ -1439,8 +1439,9 @@ void to_config(const PsinodeConfig& config, ConfigFile& file) if (!config.tls.trustfiles.empty()) { file.set( - "", "tls-trustfile", config.tls.trustfiles, [](std::string_view text) - { return std::string(text); }, "A file containing trusted certificate authorities"); + "", "tls-trustfile", config.tls.trustfiles, + [](std::string_view text) { return std::string(text); }, + "A file containing trusted certificate authorities"); } #endif if (!config.services.empty()) @@ -1451,8 +1452,9 @@ void to_config(const PsinodeConfig& config, ConfigFile& file) services.push_back(to_string(service)); } file.set( - "", "service", services, [](std::string_view text) - { return service_from_string(text).host; }, "Native service root directory"); + "", "service", services, + [](std::string_view text) { return service_from_string(text).host; }, + "Native service root directory"); } if (!std::holds_alternative(config.admin)) { @@ -1480,6 +1482,7 @@ void to_config(const PsinodeConfig& config, ConfigFile& file) // private keys. file.keep("", "key"); file.keep("", "leeway"); + file.keep("", "database-cache-size"); // to_config(config.loggers, file); } diff --git a/rust/cargo-psibase/src/package.rs b/rust/cargo-psibase/src/package.rs index 0887614ac..7ed168583 100644 --- a/rust/cargo-psibase/src/package.rs +++ b/rust/cargo-psibase/src/package.rs @@ -326,13 +326,14 @@ pub async fn build_package( } }; - let meta = Meta { + let mut meta = Meta { name: package_name.to_string(), version: package_version.to_string(), description: package_description.unwrap_or_else(|| package_name.to_string()), depends, accounts, }; + meta.depends.sort_by(|a, b| a.name.cmp(&b.name)); let mut service_wasms = Vec::new(); for (service, info, id) in services { diff --git a/rust/psibase/src/services/events.rs b/rust/psibase/src/services/events.rs index d19fcb6bd..f84a45bd1 100644 --- a/rust/psibase/src/services/events.rs +++ b/rust/psibase/src/services/events.rs @@ -1,19 +1,15 @@ #[crate::service(name = "events", dispatch = false, psibase_mod = "crate")] #[allow(non_snake_case, unused_variables)] mod service { + use crate::{AccountNumber, DbId, MethodNumber, Schema}; #[action] - fn setSchema(schema: crate::Schema) { + fn setSchema(schema: Schema) { unimplemented!() } #[action] - fn addIndex( - db_id: crate::DbId, - service: crate::AccountNumber, - event: crate::MethodNumber, - column: u8, - ) { + fn addIndex(db_id: DbId, service: AccountNumber, event: MethodNumber, column: u8) { unimplemented!() } } diff --git a/rust/test_package/Cargo.toml b/rust/test_package/Cargo.toml index 65d1e5a8f..ab438fac4 100644 --- a/rust/test_package/Cargo.toml +++ b/rust/test_package/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "test_package" +description = "Test for package building" version.workspace = true rust-version.workspace = true repository.workspace = true @@ -9,7 +10,6 @@ publish = false [package.metadata.psibase] package-name = "TestPackage" -description = "Test for package building" services = ["tpack"] [lib] diff --git a/services/user/Branding/ui/src/App.tsx b/services/user/Branding/ui/src/App.tsx index 9135d3a6c..56ec90b21 100644 --- a/services/user/Branding/ui/src/App.tsx +++ b/services/user/Branding/ui/src/App.tsx @@ -19,8 +19,7 @@ export const App = () => { const init = async () => { await supervisor.onLoaded(); - supervisor.preLoadPlugins([{ service: "branding" }]); - setTimeout(getNetworkName, 1500); + await getNetworkName(); }; useEffect(() => { diff --git a/services/user/Chainmail/Cargo.lock b/services/user/Chainmail/Cargo.lock index 5ec65dd5b..c3fefaf5d 100644 --- a/services/user/Chainmail/Cargo.lock +++ b/services/user/Chainmail/Cargo.lock @@ -364,7 +364,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chainmail" -version = "0.1.0" +version = "0.12.0" dependencies = [ "async-graphql", "chainmail_package", @@ -374,7 +374,7 @@ dependencies = [ [[package]] name = "chainmail_package" -version = "0.0.0" +version = "0.12.0" dependencies = [ "chainmail", "plugin", @@ -1438,7 +1438,7 @@ dependencies = [ [[package]] name = "plugin" -version = "0.1.0" +version = "0.12.0" dependencies = [ "chainmail", "chainmail_package", diff --git a/services/user/Chainmail/Cargo.toml b/services/user/Chainmail/Cargo.toml index fd3624b35..f6ec5bfd3 100644 --- a/services/user/Chainmail/Cargo.toml +++ b/services/user/Chainmail/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["service", "plugin"] [workspace.package] -version = "0.1.0" +version = "0.12.0" rust-version = "1.64" edition = "2021" repository = "https://github.com/gofractally/psibase" @@ -12,6 +12,17 @@ publish = false [package] name = "chainmail_package" +description = "Message-sending application" +version.workspace = true +rust-version.workspace = true +edition.workspace = true +repository.workspace = true +homepage.workspace = true +publish.workspace = true + +[package.metadata.psibase] +package-name = "Chainmail" +services = ["chainmail"] [profile.release] codegen-units = 1 @@ -20,14 +31,9 @@ debug = false strip = true lto = true -[package.metadata.psibase] -package-name = "Chainmail" -description = "Basic email app" -services = ["chainmail"] - [lib] crate-type = ["rlib"] [dependencies] -chainmail = { path = "service" } -plugin = { path = "plugin" } +chainmail = { path = "service", version = "0.12.0" } +plugin = { path = "plugin", version = "0.12.0" } diff --git a/services/user/Chainmail/plugin/Cargo.toml b/services/user/Chainmail/plugin/Cargo.toml index 1cba67759..4875410a0 100644 --- a/services/user/Chainmail/plugin/Cargo.toml +++ b/services/user/Chainmail/plugin/Cargo.toml @@ -26,4 +26,4 @@ world = "impl" "transact:plugin" = { path = "../../../system/Transact/plugin/wit/world.wit" } [dev-dependencies] -chainmail_package = { path = ".." } +chainmail_package = { path = "..", version = "0.12.0" } diff --git a/services/user/Chainmail/service/Cargo.toml b/services/user/Chainmail/service/Cargo.toml index 1f7a77320..54f375925 100644 --- a/services/user/Chainmail/service/Cargo.toml +++ b/services/user/Chainmail/service/Cargo.toml @@ -10,6 +10,18 @@ publish = false [package.metadata.psibase] server = "chainmail" plugin = "plugin" +data = [{ src = "../ui/dist/", dst = "/" }] +postinstall = [ + { sender = "chainmail", service = "chainmail", method = "init", rawData = "0000" }, +] + +[package.metadata.psibase.dependencies] +Accounts = "0.12.0" +CommonApi = "0.12.0" +SetCode = "0.12.0" +HttpServer = "0.12.0" +Supervisor = "0.12.0" +Events = "0.12.0" [dependencies] psibase = { path = "../../../../rust/psibase/" } @@ -17,4 +29,4 @@ async-graphql = "7.0.7" serde = { version = "1.0.209", features = ["derive"] } [dev-dependencies] -chainmail_package = { path = ".." } +chainmail_package = { path = "..", version = "0.12.0" } diff --git a/services/user/Chainmail/service/src/lib.rs b/services/user/Chainmail/service/src/lib.rs index 282421253..e795e4b09 100644 --- a/services/user/Chainmail/service/src/lib.rs +++ b/services/user/Chainmail/service/src/lib.rs @@ -99,14 +99,36 @@ fn serve_rest_api(request: &HttpRequest) -> Option { #[psibase::service] mod service { - use psibase::services::accounts::Wrapper as AccountsSvc; - use psibase::{ - anyhow, check, get_sender, get_service, serve_simple_ui, AccountNumber, HexBytes, - HttpReply, HttpRequest, Table, - }; + + use psibase::*; + use serde::{Deserialize, Serialize}; + use services::accounts::Wrapper as AccountsSvc; + use services::events::Wrapper as EventsSvc; use crate::serve_rest_api; + #[table(name = "InitTable", index = 1)] + #[derive(Serialize, Deserialize, ToSchema, Fracpack)] + struct InitRow {} + impl InitRow { + #[primary_key] + fn pk(&self) {} + } + + #[action] + fn init() { + let table = InitTable::new(); + check( + table.get_index_pk().get(&()).is_none(), + "Service already initialized", + ); + table.put(&InitRow {}).unwrap(); + + EventsSvc::call().setSchema(create_schema::()); + EventsSvc::call().addIndex(DbId::HistoryEvent, SERVICE, MethodNumber::from("sent"), 0); + EventsSvc::call().addIndex(DbId::HistoryEvent, SERVICE, MethodNumber::from("sent"), 1); + } + #[action] fn send(receiver: AccountNumber, subject: String, body: String) { check(