From 6ec246678b2727e1cbe6bcc5f586e8c33a11f918 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Fri, 10 Nov 2023 13:13:35 +0700 Subject: [PATCH 01/14] rename --- crates/flow-server/src/api/auth_proxy.rs | 2 +- crates/flow-server/src/api/claim_token.rs | 2 +- crates/flow-server/src/api/clone_flow.rs | 2 +- crates/flow-server/src/api/create_apikey.rs | 2 +- crates/flow-server/src/api/db_push_logs.rs | 2 +- crates/flow-server/src/api/db_rpc.rs | 2 +- crates/flow-server/src/api/delete_apikey.rs | 2 +- crates/flow-server/src/api/kvstore/create_store.rs | 2 +- crates/flow-server/src/api/kvstore/delete_item.rs | 2 +- crates/flow-server/src/api/kvstore/delete_store.rs | 2 +- crates/flow-server/src/api/kvstore/read_item.rs | 2 +- crates/flow-server/src/api/kvstore/write_item.rs | 2 +- crates/flow-server/src/api/start_flow.rs | 2 +- crates/flow-server/src/api/stop_flow.rs | 2 +- crates/flow-server/src/api/submit_signature.rs | 2 +- crates/flow-server/src/api/ws_auth_proxy.rs | 2 +- crates/flow-server/src/lib.rs | 2 +- crates/flow-server/src/wss/mod.rs | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/flow-server/src/api/auth_proxy.rs b/crates/flow-server/src/api/auth_proxy.rs index b1f38b8c..4b5d32a2 100644 --- a/crates/flow-server/src/api/auth_proxy.rs +++ b/crates/flow-server/src/api/auth_proxy.rs @@ -11,7 +11,7 @@ pub struct Output { pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/auth") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(auth)) } diff --git a/crates/flow-server/src/api/claim_token.rs b/crates/flow-server/src/api/claim_token.rs index 3d67cac4..eaf64a3b 100644 --- a/crates/flow-server/src/api/claim_token.rs +++ b/crates/flow-server/src/api/claim_token.rs @@ -14,7 +14,7 @@ pub struct Output { pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/claim_token") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .app_data(web::Data::new(config.endpoints())) .route(web::post().to(claim_token)) diff --git a/crates/flow-server/src/api/clone_flow.rs b/crates/flow-server/src/api/clone_flow.rs index 145172de..cbe4c433 100644 --- a/crates/flow-server/src/api/clone_flow.rs +++ b/crates/flow-server/src/api/clone_flow.rs @@ -11,7 +11,7 @@ pub struct Output { pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/clone/{id}") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(clone_flow)) } diff --git a/crates/flow-server/src/api/create_apikey.rs b/crates/flow-server/src/api/create_apikey.rs index bcd369d9..550e5505 100644 --- a/crates/flow-server/src/api/create_apikey.rs +++ b/crates/flow-server/src/api/create_apikey.rs @@ -18,7 +18,7 @@ pub struct Output { pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/create") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(create_key)) } diff --git a/crates/flow-server/src/api/db_push_logs.rs b/crates/flow-server/src/api/db_push_logs.rs index c2540f17..745d14c5 100644 --- a/crates/flow-server/src/api/db_push_logs.rs +++ b/crates/flow-server/src/api/db_push_logs.rs @@ -4,7 +4,7 @@ use db::FlowRunLogsRow; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/db_push_logs") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(db_push_logs)) } diff --git a/crates/flow-server/src/api/db_rpc.rs b/crates/flow-server/src/api/db_rpc.rs index 56f9d5f1..4e71cc3c 100644 --- a/crates/flow-server/src/api/db_rpc.rs +++ b/crates/flow-server/src/api/db_rpc.rs @@ -3,7 +3,7 @@ use serde_json::value::RawValue; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/db_rpc") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(db_rpc)) } diff --git a/crates/flow-server/src/api/delete_apikey.rs b/crates/flow-server/src/api/delete_apikey.rs index 2d45fe66..8087b506 100644 --- a/crates/flow-server/src/api/delete_apikey.rs +++ b/crates/flow-server/src/api/delete_apikey.rs @@ -10,7 +10,7 @@ pub struct Output {} pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/delete") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(delete_key)) } diff --git a/crates/flow-server/src/api/kvstore/create_store.rs b/crates/flow-server/src/api/kvstore/create_store.rs index 97205364..a939874b 100644 --- a/crates/flow-server/src/api/kvstore/create_store.rs +++ b/crates/flow-server/src/api/kvstore/create_store.rs @@ -5,7 +5,7 @@ use regex::Regex; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/create_store") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(create_store)) } diff --git a/crates/flow-server/src/api/kvstore/delete_item.rs b/crates/flow-server/src/api/kvstore/delete_item.rs index 20062500..405bbeae 100644 --- a/crates/flow-server/src/api/kvstore/delete_item.rs +++ b/crates/flow-server/src/api/kvstore/delete_item.rs @@ -3,7 +3,7 @@ use value::Value; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/delete_item") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(write_item)) } diff --git a/crates/flow-server/src/api/kvstore/delete_store.rs b/crates/flow-server/src/api/kvstore/delete_store.rs index 75467119..6e42bb5e 100644 --- a/crates/flow-server/src/api/kvstore/delete_store.rs +++ b/crates/flow-server/src/api/kvstore/delete_store.rs @@ -2,7 +2,7 @@ use super::super::prelude::*; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/delete_store") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(delete_store)) } diff --git a/crates/flow-server/src/api/kvstore/read_item.rs b/crates/flow-server/src/api/kvstore/read_item.rs index cfa13fee..5c847a1a 100644 --- a/crates/flow-server/src/api/kvstore/read_item.rs +++ b/crates/flow-server/src/api/kvstore/read_item.rs @@ -3,7 +3,7 @@ use value::Value; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/read_item") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(read_item)) } diff --git a/crates/flow-server/src/api/kvstore/write_item.rs b/crates/flow-server/src/api/kvstore/write_item.rs index c6b35237..b31d42ed 100644 --- a/crates/flow-server/src/api/kvstore/write_item.rs +++ b/crates/flow-server/src/api/kvstore/write_item.rs @@ -3,7 +3,7 @@ use value::Value; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/write_item") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(write_item)) } diff --git a/crates/flow-server/src/api/start_flow.rs b/crates/flow-server/src/api/start_flow.rs index a9384555..8e9c2ad3 100644 --- a/crates/flow-server/src/api/start_flow.rs +++ b/crates/flow-server/src/api/start_flow.rs @@ -22,7 +22,7 @@ pub struct Output { pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/start/{id}") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(start_flow)) } diff --git a/crates/flow-server/src/api/stop_flow.rs b/crates/flow-server/src/api/stop_flow.rs index b0f1d4c8..8143f687 100644 --- a/crates/flow-server/src/api/stop_flow.rs +++ b/crates/flow-server/src/api/stop_flow.rs @@ -17,7 +17,7 @@ pub struct Output { pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/stop/{id}") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(stop_flow)) } diff --git a/crates/flow-server/src/api/submit_signature.rs b/crates/flow-server/src/api/submit_signature.rs index decf293c..089eb7e7 100644 --- a/crates/flow-server/src/api/submit_signature.rs +++ b/crates/flow-server/src/api/submit_signature.rs @@ -19,7 +19,7 @@ pub struct Output { pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { web::resource("/submit") - .wrap(config.apikey_auth(db)) + .wrap(config.all_auth(db)) .wrap(config.cors()) .route(web::post().to(submit_signature)) } diff --git a/crates/flow-server/src/api/ws_auth_proxy.rs b/crates/flow-server/src/api/ws_auth_proxy.rs index 8401bc48..c0aea353 100644 --- a/crates/flow-server/src/api/ws_auth_proxy.rs +++ b/crates/flow-server/src/api/ws_auth_proxy.rs @@ -14,7 +14,7 @@ pub struct Output { } pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { - let auth = web::Data::new(config.apikey_auth(db)); + let auth = web::Data::new(config.all_auth(db)); web::resource("/ws_auth") .app_data(auth) .wrap(config.cors()) diff --git a/crates/flow-server/src/lib.rs b/crates/flow-server/src/lib.rs index 38050c63..d40754cb 100644 --- a/crates/flow-server/src/lib.rs +++ b/crates/flow-server/src/lib.rs @@ -212,7 +212,7 @@ impl Config { /// Build a middleware to validate `Authorization` header /// with Supabase's JWT secret and API key. - pub fn apikey_auth(&self, pool: DbPool) -> auth::ApiAuth { + pub fn all_auth(&self, pool: DbPool) -> auth::ApiAuth { match (self.supabase.jwt_key.as_ref(), pool) { (Some(key), DbPool::Real(pool)) => { auth::ApiAuth::real(key.as_bytes(), self.supabase.anon_key.clone(), pool) diff --git a/crates/flow-server/src/wss/mod.rs b/crates/flow-server/src/wss/mod.rs index 51322ccd..4cef2461 100644 --- a/crates/flow-server/src/wss/mod.rs +++ b/crates/flow-server/src/wss/mod.rs @@ -22,7 +22,7 @@ use serde_json::json; use std::sync::Arc; pub fn service(config: &Config, db: DbPool) -> impl HttpServiceFactory { - let auth = web::Data::new(config.apikey_auth(db)); + let auth = web::Data::new(config.all_auth(db)); web::resource("") .app_data(auth) .wrap(config.cors()) From 84bdc5c7bf570271091a73956d417d610c7e32f8 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Fri, 10 Nov 2023 13:49:58 +0700 Subject: [PATCH 02/14] . --- .../pdg-common/src/nft_metadata/generate.rs | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/crates/pdg-common/src/nft_metadata/generate.rs b/crates/pdg-common/src/nft_metadata/generate.rs index abcb6fa7..644bbb4b 100644 --- a/crates/pdg-common/src/nft_metadata/generate.rs +++ b/crates/pdg-common/src/nft_metadata/generate.rs @@ -231,6 +231,7 @@ mod tests { dbg!(get_new_pose(poses)); // adjust pose + #[allow(dead_code)] fn adjust_pose(poses: HashSet, selected_pose: Pose) -> Option { // check poses is not empty if poses.is_empty() | !poses.contains(&selected_pose) { @@ -315,29 +316,30 @@ mod tests { // // add new fx + #[allow(dead_code)] fn add_new_effect_to_base(mut base: RenderParams, new_effect: &str) -> RenderParams { //find the new_effect in the RenderParams enum match new_effect { - stringify!(Hologram) => base.fx0 = Fx0::Hologram, - stringify!(Xray) => base.fx0 = Fx0::Xray, - stringify!(SoapBubble) => base.fx0 = Fx0::SoapBubble, - stringify!(Pixel) => base.fx0 = Fx0::Pixel, - stringify!(Melted) => base.fx1 = Fx1::Melted, - stringify!(Disintegration) => base.fx1 = Fx1::Disintegration, - stringify!(Butterflies) => base.fx2 = Fx2::Butterflies, - stringify!(Underwater) => base.fx2 = Fx2::Underwater, - stringify!(Fireflyies) => base.fx2 = Fx2::Fireflyies, - stringify!(Fall) => base.fx2 = Fx2::Fall, - stringify!(Ladybag) => base.fx2 = Fx2::Ladybag, - stringify!(Spring) => base.fx2 = Fx2::Spring, - stringify!(Frozen) => base.fx4 = Fx4::Frozen, - stringify!(Rain) => base.fx4 = Fx4::Rain, - stringify!(Fungi) => base.fx5 = Fx5::Fungi, - stringify!(GrowFlower) => base.fx5 = Fx5::GrowFlower, - stringify!(Gold) => base.fx6 = Fx6::Gold, - stringify!(Silver) => base.fx6 = Fx6::Silver, - stringify!(LineartMinimalistic) => base.fx1a = Fx1a::LineartMinimalistic, - stringify!(LineartHeavy) => base.fx1a = Fx1a::LineartHeavy, + "Hologram" => base.fx0 = Fx0::Hologram, + "Xray" => base.fx0 = Fx0::Xray, + "SoapBubble" => base.fx0 = Fx0::SoapBubble, + "Pixel" => base.fx0 = Fx0::Pixel, + "Melted" => base.fx1 = Fx1::Melted, + "Disintegration" => base.fx1 = Fx1::Disintegration, + "Butterflies" => base.fx2 = Fx2::Butterflies, + "Underwater" => base.fx2 = Fx2::Underwater, + "Fireflyies" => base.fx2 = Fx2::Fireflyies, + "Fall" => base.fx2 = Fx2::Fall, + "Ladybag" => base.fx2 = Fx2::Ladybag, + "Spring" => base.fx2 = Fx2::Spring, + "Frozen" => base.fx4 = Fx4::Frozen, + "Rain" => base.fx4 = Fx4::Rain, + "Fungi" => base.fx5 = Fx5::Fungi, + "GrowFlower" => base.fx5 = Fx5::GrowFlower, + "Gold" => base.fx6 = Fx6::Gold, + "Silver" => base.fx6 = Fx6::Silver, + "LineartMinimalistic" => base.fx1a = Fx1a::LineartMinimalistic, + "LineartHeavy" => base.fx1a = Fx1a::LineartHeavy, _ => {} } From 078a976fc16935e1ab86ad158145073efd1eee87 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Fri, 10 Nov 2023 13:56:52 +0700 Subject: [PATCH 03/14] Rename --- Cargo.lock | 46 +++++++++---------- Cargo.toml | 2 +- crates/cmds-solana/Cargo.toml | 2 +- lib/flow-lib/Cargo.toml | 2 +- lib/{value => flow-value}/Cargo.toml | 2 +- lib/{value => flow-value}/src/crud.rs | 0 lib/{value => flow-value}/src/crud/path.rs | 0 lib/{value => flow-value}/src/de.rs | 0 .../src/de/const_bytes.rs | 0 lib/{value => flow-value}/src/de/de_enum.rs | 0 lib/{value => flow-value}/src/de/de_struct.rs | 0 lib/{value => flow-value}/src/de/text_repr.rs | 0 lib/{value => flow-value}/src/decimal.rs | 0 .../src/json_repr/iter_ser.rs | 0 lib/{value => flow-value}/src/keypair.rs | 0 lib/{value => flow-value}/src/lib.rs | 0 lib/{value => flow-value}/src/macros.rs | 0 lib/{value => flow-value}/src/pubkey.rs | 0 lib/{value => flow-value}/src/ser.rs | 0 lib/{value => flow-value}/src/ser/iter_ser.rs | 0 lib/{value => flow-value}/src/ser/map_key.rs | 0 lib/{value => flow-value}/src/ser/maps.rs | 0 lib/{value => flow-value}/src/ser/seq.rs | 0 .../src/ser/tagged_bytes.rs | 0 .../src/ser/text_repr.rs | 0 lib/{value => flow-value}/src/signature.rs | 0 lib/{value => flow-value}/src/tests/ser.json | 0 lib/{value => flow-value}/src/value_type.rs | 0 28 files changed, 27 insertions(+), 27 deletions(-) rename lib/{value => flow-value}/Cargo.toml (97%) rename lib/{value => flow-value}/src/crud.rs (100%) rename lib/{value => flow-value}/src/crud/path.rs (100%) rename lib/{value => flow-value}/src/de.rs (100%) rename lib/{value => flow-value}/src/de/const_bytes.rs (100%) rename lib/{value => flow-value}/src/de/de_enum.rs (100%) rename lib/{value => flow-value}/src/de/de_struct.rs (100%) rename lib/{value => flow-value}/src/de/text_repr.rs (100%) rename lib/{value => flow-value}/src/decimal.rs (100%) rename lib/{value => flow-value}/src/json_repr/iter_ser.rs (100%) rename lib/{value => flow-value}/src/keypair.rs (100%) rename lib/{value => flow-value}/src/lib.rs (100%) rename lib/{value => flow-value}/src/macros.rs (100%) rename lib/{value => flow-value}/src/pubkey.rs (100%) rename lib/{value => flow-value}/src/ser.rs (100%) rename lib/{value => flow-value}/src/ser/iter_ser.rs (100%) rename lib/{value => flow-value}/src/ser/map_key.rs (100%) rename lib/{value => flow-value}/src/ser/maps.rs (100%) rename lib/{value => flow-value}/src/ser/seq.rs (100%) rename lib/{value => flow-value}/src/ser/tagged_bytes.rs (100%) rename lib/{value => flow-value}/src/ser/text_repr.rs (100%) rename lib/{value => flow-value}/src/signature.rs (100%) rename lib/{value => flow-value}/src/tests/ser.json (100%) rename lib/{value => flow-value}/src/value_type.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 2a59c383..6160fa93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1617,6 +1617,7 @@ dependencies = [ "ed25519-dalek", "fasteval", "flow-lib", + "flow-value", "futures", "hex", "hyper", @@ -1653,7 +1654,6 @@ dependencies = [ "tracing", "tracing-log", "url", - "value", "wormhole-sdk", ] @@ -2179,6 +2179,7 @@ dependencies = [ "either", "flow", "flow-lib", + "flow-value", "futures-util", "hashbrown 0.13.2", "kv", @@ -2200,7 +2201,6 @@ dependencies = [ "tracing-subscriber", "url", "uuid 1.5.0", - "value", "x509-parser", ] @@ -2674,6 +2674,7 @@ dependencies = [ "cmds-std", "derive_more", "flow-lib", + "flow-value", "futures", "hashbrown 0.13.2", "indexmap 2.1.0", @@ -2695,7 +2696,6 @@ dependencies = [ "tracing-subscriber", "utils", "uuid 1.5.0", - "value", ] [[package]] @@ -2706,6 +2706,7 @@ dependencies = [ "anyhow", "async-trait", "bytes", + "flow-value", "futures", "inventory", "once_cell", @@ -2721,7 +2722,6 @@ dependencies = [ "tower", "tracing", "uuid 1.5.0", - "value", ] [[package]] @@ -2748,6 +2748,7 @@ dependencies = [ "either", "flow", "flow-lib", + "flow-value", "futures-channel", "futures-util", "hashbrown 0.13.2", @@ -2772,7 +2773,24 @@ dependencies = [ "tracing-subscriber", "utils", "uuid 1.5.0", - "value", +] + +[[package]] +name = "flow-value" +version = "0.0.1" +dependencies = [ + "base64 0.13.1", + "bs58 0.4.0", + "bytes", + "indexmap 2.1.0", + "itoa", + "rust_decimal", + "rust_decimal_macros", + "ryu", + "serde", + "serde_json", + "solana-sdk", + "thiserror", ] [[package]] @@ -7874,24 +7892,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "value" -version = "0.0.1" -dependencies = [ - "base64 0.13.1", - "bs58 0.4.0", - "bytes", - "indexmap 2.1.0", - "itoa", - "rust_decimal", - "rust_decimal_macros", - "ryu", - "serde", - "serde_json", - "solana-sdk", - "thiserror", -] - [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index ca8bcb1f..0e4c8853 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ cmds-pdg = { path = "crates/cmds-pdg", version = "0.0.0" } cmds-solana = { path = "crates/cmds-solana", version = "0.0.0" } # lib/ -value = { path = "lib/value", version = "0.0.1" } +value = { path = "lib/flow-value", version = "0.0.1", package = "flow-value" } flow-lib = { path = "lib/flow-lib", version = "0.0.1" } space-lib = { path = "lib/space-lib", version = "0.5.0" } space-macro = { path = "lib/space-macro", version = "0.2.1" } diff --git a/crates/cmds-solana/Cargo.toml b/crates/cmds-solana/Cargo.toml index 7f3cba68..c1f0112a 100644 --- a/crates/cmds-solana/Cargo.toml +++ b/crates/cmds-solana/Cargo.toml @@ -118,4 +118,4 @@ rev = "b209022b85d8e6cbf4e37b059bfe3ce7fa11c6e1" [dev-dependencies] rust_decimal_macros = "1.26" -inventory = "0.3" \ No newline at end of file +inventory = "0.3" diff --git a/lib/flow-lib/Cargo.toml b/lib/flow-lib/Cargo.toml index 73b4968f..17a4185d 100644 --- a/lib/flow-lib/Cargo.toml +++ b/lib/flow-lib/Cargo.toml @@ -26,4 +26,4 @@ reqwest = { version = "*", default-features = false } # solana libs solana-sdk = "1" -solana-client = "1" \ No newline at end of file +solana-client = "1" diff --git a/lib/value/Cargo.toml b/lib/flow-value/Cargo.toml similarity index 97% rename from lib/value/Cargo.toml rename to lib/flow-value/Cargo.toml index 13824193..061dccda 100644 --- a/lib/value/Cargo.toml +++ b/lib/flow-value/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "value" +name = "flow-value" version = "0.0.1" edition = "2021" diff --git a/lib/value/src/crud.rs b/lib/flow-value/src/crud.rs similarity index 100% rename from lib/value/src/crud.rs rename to lib/flow-value/src/crud.rs diff --git a/lib/value/src/crud/path.rs b/lib/flow-value/src/crud/path.rs similarity index 100% rename from lib/value/src/crud/path.rs rename to lib/flow-value/src/crud/path.rs diff --git a/lib/value/src/de.rs b/lib/flow-value/src/de.rs similarity index 100% rename from lib/value/src/de.rs rename to lib/flow-value/src/de.rs diff --git a/lib/value/src/de/const_bytes.rs b/lib/flow-value/src/de/const_bytes.rs similarity index 100% rename from lib/value/src/de/const_bytes.rs rename to lib/flow-value/src/de/const_bytes.rs diff --git a/lib/value/src/de/de_enum.rs b/lib/flow-value/src/de/de_enum.rs similarity index 100% rename from lib/value/src/de/de_enum.rs rename to lib/flow-value/src/de/de_enum.rs diff --git a/lib/value/src/de/de_struct.rs b/lib/flow-value/src/de/de_struct.rs similarity index 100% rename from lib/value/src/de/de_struct.rs rename to lib/flow-value/src/de/de_struct.rs diff --git a/lib/value/src/de/text_repr.rs b/lib/flow-value/src/de/text_repr.rs similarity index 100% rename from lib/value/src/de/text_repr.rs rename to lib/flow-value/src/de/text_repr.rs diff --git a/lib/value/src/decimal.rs b/lib/flow-value/src/decimal.rs similarity index 100% rename from lib/value/src/decimal.rs rename to lib/flow-value/src/decimal.rs diff --git a/lib/value/src/json_repr/iter_ser.rs b/lib/flow-value/src/json_repr/iter_ser.rs similarity index 100% rename from lib/value/src/json_repr/iter_ser.rs rename to lib/flow-value/src/json_repr/iter_ser.rs diff --git a/lib/value/src/keypair.rs b/lib/flow-value/src/keypair.rs similarity index 100% rename from lib/value/src/keypair.rs rename to lib/flow-value/src/keypair.rs diff --git a/lib/value/src/lib.rs b/lib/flow-value/src/lib.rs similarity index 100% rename from lib/value/src/lib.rs rename to lib/flow-value/src/lib.rs diff --git a/lib/value/src/macros.rs b/lib/flow-value/src/macros.rs similarity index 100% rename from lib/value/src/macros.rs rename to lib/flow-value/src/macros.rs diff --git a/lib/value/src/pubkey.rs b/lib/flow-value/src/pubkey.rs similarity index 100% rename from lib/value/src/pubkey.rs rename to lib/flow-value/src/pubkey.rs diff --git a/lib/value/src/ser.rs b/lib/flow-value/src/ser.rs similarity index 100% rename from lib/value/src/ser.rs rename to lib/flow-value/src/ser.rs diff --git a/lib/value/src/ser/iter_ser.rs b/lib/flow-value/src/ser/iter_ser.rs similarity index 100% rename from lib/value/src/ser/iter_ser.rs rename to lib/flow-value/src/ser/iter_ser.rs diff --git a/lib/value/src/ser/map_key.rs b/lib/flow-value/src/ser/map_key.rs similarity index 100% rename from lib/value/src/ser/map_key.rs rename to lib/flow-value/src/ser/map_key.rs diff --git a/lib/value/src/ser/maps.rs b/lib/flow-value/src/ser/maps.rs similarity index 100% rename from lib/value/src/ser/maps.rs rename to lib/flow-value/src/ser/maps.rs diff --git a/lib/value/src/ser/seq.rs b/lib/flow-value/src/ser/seq.rs similarity index 100% rename from lib/value/src/ser/seq.rs rename to lib/flow-value/src/ser/seq.rs diff --git a/lib/value/src/ser/tagged_bytes.rs b/lib/flow-value/src/ser/tagged_bytes.rs similarity index 100% rename from lib/value/src/ser/tagged_bytes.rs rename to lib/flow-value/src/ser/tagged_bytes.rs diff --git a/lib/value/src/ser/text_repr.rs b/lib/flow-value/src/ser/text_repr.rs similarity index 100% rename from lib/value/src/ser/text_repr.rs rename to lib/flow-value/src/ser/text_repr.rs diff --git a/lib/value/src/signature.rs b/lib/flow-value/src/signature.rs similarity index 100% rename from lib/value/src/signature.rs rename to lib/flow-value/src/signature.rs diff --git a/lib/value/src/tests/ser.json b/lib/flow-value/src/tests/ser.json similarity index 100% rename from lib/value/src/tests/ser.json rename to lib/flow-value/src/tests/ser.json diff --git a/lib/value/src/value_type.rs b/lib/flow-value/src/value_type.rs similarity index 100% rename from lib/value/src/value_type.rs rename to lib/flow-value/src/value_type.rs From adde5481667d774566d2f4221e50b98d9a2725c5 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Fri, 10 Nov 2023 14:03:32 +0700 Subject: [PATCH 04/14] . --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- lib/flow-lib/Cargo.toml | 2 +- lib/flow-value/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6160fa93..2facc787 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2700,7 +2700,7 @@ dependencies = [ [[package]] name = "flow-lib" -version = "0.0.1" +version = "0.1.0" dependencies = [ "actix", "anyhow", @@ -2777,7 +2777,7 @@ dependencies = [ [[package]] name = "flow-value" -version = "0.0.1" +version = "0.1.0" dependencies = [ "base64 0.13.1", "bs58 0.4.0", diff --git a/Cargo.toml b/Cargo.toml index 0e4c8853..7f843930 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,8 @@ cmds-pdg = { path = "crates/cmds-pdg", version = "0.0.0" } cmds-solana = { path = "crates/cmds-solana", version = "0.0.0" } # lib/ -value = { path = "lib/flow-value", version = "0.0.1", package = "flow-value" } -flow-lib = { path = "lib/flow-lib", version = "0.0.1" } +value = { path = "lib/flow-value", version = "0.1.0", package = "flow-value" } +flow-lib = { path = "lib/flow-lib", version = "0.1.0" } space-lib = { path = "lib/space-lib", version = "0.5.0" } space-macro = { path = "lib/space-macro", version = "0.2.1" } diff --git a/lib/flow-lib/Cargo.toml b/lib/flow-lib/Cargo.toml index 17a4185d..feacdbe9 100644 --- a/lib/flow-lib/Cargo.toml +++ b/lib/flow-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flow-lib" -version = "0.0.1" +version = "0.1.0" edition = "2021" [dependencies] diff --git a/lib/flow-value/Cargo.toml b/lib/flow-value/Cargo.toml index 061dccda..b5fb6095 100644 --- a/lib/flow-value/Cargo.toml +++ b/lib/flow-value/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flow-value" -version = "0.0.1" +version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 63607f8a051740c810b994adda517017100e77cd Mon Sep 17 00:00:00 2001 From: Duy Do Date: Sat, 11 Nov 2023 11:03:01 +0700 Subject: [PATCH 05/14] . --- crates/flow-server/src/db_worker/mod.rs | 1 + crates/flow-server/src/db_worker/signer.rs | 40 ++++++++++ crates/utils/src/address_book.rs | 87 ++++++++++++---------- 3 files changed, 88 insertions(+), 40 deletions(-) create mode 100644 crates/flow-server/src/db_worker/signer.rs diff --git a/crates/flow-server/src/db_worker/mod.rs b/crates/flow-server/src/db_worker/mod.rs index ad5cb8c0..da4770b3 100644 --- a/crates/flow-server/src/db_worker/mod.rs +++ b/crates/flow-server/src/db_worker/mod.rs @@ -14,6 +14,7 @@ pub mod flow_run_worker; pub mod messages; pub mod token_worker; pub mod user_worker; +pub mod signer; pub use flow_run_worker::FlowRunWorker; pub use user_worker::UserWorker; diff --git a/crates/flow-server/src/db_worker/signer.rs b/crates/flow-server/src/db_worker/signer.rs new file mode 100644 index 00000000..7b13a234 --- /dev/null +++ b/crates/flow-server/src/db_worker/signer.rs @@ -0,0 +1,40 @@ +use actix::{Actor, ResponseFuture}; +use flow_lib::context::signer; +use futures_util::FutureExt; +use hashbrown::HashMap; +use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; +use std::future::ready; + +pub enum SignerType { + Keypair(Keypair), + UserWallet { + // Forward to UserWorker + sender: actix::Recipient, + }, +} + +pub struct SignerWorker { + signers: HashMap, +} + +impl Actor for SignerWorker { + type Context = actix::Context; +} + +impl actix::Handler for SignerWorker { + type Result = ResponseFuture<::Result>; + + fn handle(&mut self, msg: signer::SignatureRequest, _: &mut Self::Context) -> Self::Result { + match self.signers.get(&msg.pubkey) { + None => ready(Err(signer::Error::Pubkey)).boxed(), + Some(SignerType::Keypair(keypair)) => ready(Ok(signer::SignatureResponse { + signature: keypair.sign_message(&msg.message), + })) + .boxed(), + Some(SignerType::UserWallet { sender }) => { + let fut = sender.send(msg); + async move { fut.await? }.boxed() + } + } + } +} diff --git a/crates/utils/src/address_book.rs b/crates/utils/src/address_book.rs index ed09625b..14b9ed40 100644 --- a/crates/utils/src/address_book.rs +++ b/crates/utils/src/address_book.rs @@ -206,58 +206,65 @@ impl AnyID { } } -struct StringActor0 { - id: String, -} +/* +#[cfg(test)] +mod tests { + use super::*; -impl Actor for StringActor0 { - type Context = actix::Context; -} + struct StringActor0 { + id: String, + } -impl ManagableActor for StringActor0 { - type ID = String; - fn id(&self) -> String { - self.id.clone() + impl Actor for StringActor0 { + type Context = actix::Context; } -} -struct StringActor1 { - id: String, -} + impl ManagableActor for StringActor0 { + type ID = String; + fn id(&self) -> String { + self.id.clone() + } + } -impl Actor for StringActor1 { - type Context = actix::Context; -} + struct StringActor1 { + id: String, + } -impl ManagableActor for StringActor1 { - type ID = String; - fn id(&self) -> String { - self.id.clone() + impl Actor for StringActor1 { + type Context = actix::Context; } -} -struct I32Actor0 { - id: i32, -} + impl ManagableActor for StringActor1 { + type ID = String; + fn id(&self) -> String { + self.id.clone() + } + } -impl Actor for I32Actor0 { - type Context = actix::Context; -} + struct I32Actor0 { + id: i32, + } -impl ManagableActor for I32Actor0 { - type ID = i32; - fn id(&self) -> i32 { - self.id + impl Actor for I32Actor0 { + type Context = actix::Context; } -} -struct UnitActor0 {} + impl ManagableActor for I32Actor0 { + type ID = i32; + fn id(&self) -> i32 { + self.id + } + } -impl Actor for UnitActor0 { - type Context = actix::Context; -} + struct UnitActor0 {} -impl ManagableActor for UnitActor0 { - type ID = (); - fn id(&self) -> Self::ID {} + impl Actor for UnitActor0 { + type Context = actix::Context; + } + + impl ManagableActor for UnitActor0 { + type ID = (); + fn id(&self) -> Self::ID {} + } } +*/ From 4a7ed6e375efe66c080f04b4871b7191aaae111a Mon Sep 17 00:00:00 2001 From: Duy Do Date: Sat, 11 Nov 2023 11:44:12 +0700 Subject: [PATCH 06/14] Update licence text --- LICENSE | 7 ------- README.md | 9 ++++++++- lib/flow-lib/Cargo.toml | 4 ++++ lib/flow-value/Cargo.toml | 4 ++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/LICENSE b/LICENSE index 0e583f09..0ad25db4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,10 +1,3 @@ -Open source license: AGPLv3 - -For commercial projects and to keep your source code proprietary, -please get a license at www.spaceoperator.com - -////////////////////////////////////////////////////////////////////// - GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 diff --git a/README.md b/README.md index 4ced4e6f..cdb17ce8 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,11 @@ RUST_LOG=info cargo run -p flow-server -- guest.toml ``` This server can be used to run flows belonging to you. Toggle "Remote 🌐" button in flow editor to switch to `localhost` server. -Please note that some browsers such as Brave will block requests to `localhost` by default, disable protection if you encounter network errors. \ No newline at end of file +Please note that some browsers such as Brave will block requests to `localhost` by default, disable protection if you encounter network errors. + +## License + +Open source license: AGPLv3 + +For commercial projects and to keep your source code proprietary, +please get a license at [www.spaceoperator.com](www.spaceoperator.com). diff --git a/lib/flow-lib/Cargo.toml b/lib/flow-lib/Cargo.toml index feacdbe9..66709af3 100644 --- a/lib/flow-lib/Cargo.toml +++ b/lib/flow-lib/Cargo.toml @@ -2,6 +2,10 @@ name = "flow-lib" version = "0.1.0" edition = "2021" +license = "AGPL-3.0-only" +homepage = "https://www.spaceoperator.com" +repository = "https://github.com/space-operator/flow-backend" +keywords = ["flow", "solana"] [dependencies] value = { workspace = true } diff --git a/lib/flow-value/Cargo.toml b/lib/flow-value/Cargo.toml index b5fb6095..32d81a2a 100644 --- a/lib/flow-value/Cargo.toml +++ b/lib/flow-value/Cargo.toml @@ -2,6 +2,10 @@ name = "flow-value" version = "0.1.0" edition = "2021" +license = "AGPL-3.0-only" +homepage = "https://www.spaceoperator.com" +repository = "https://github.com/space-operator/flow-backend" +keywords = ["flow", "solana"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] From 8982aaae25ae6cf333d38a3de11963c9e81b1e06 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Mon, 13 Nov 2023 14:02:42 +0700 Subject: [PATCH 07/14] wallet --- crates/cmds-solana/src/wallet.rs | 62 ++++---------------------------- 1 file changed, 7 insertions(+), 55 deletions(-) diff --git a/crates/cmds-solana/src/wallet.rs b/crates/cmds-solana/src/wallet.rs index 0af4943c..ac9aabc9 100644 --- a/crates/cmds-solana/src/wallet.rs +++ b/crates/cmds-solana/src/wallet.rs @@ -8,12 +8,8 @@ pub struct Wallet { } #[derive(Deserialize)] -#[serde(tag = "wallet_type")] -enum FormData { - #[serde(rename = "HARDCODED")] - HardCoded { wallet_data: String }, - #[serde(rename = "ADAPTER")] - Adapter { wallet_data: String }, +struct FormData { + public_key: String, } #[derive(ThisError, Debug)] @@ -33,29 +29,11 @@ fn adapter_wallet(pubkey: Pubkey) -> Output { impl FormData { fn into_output(self) -> Result { - match self { - FormData::Adapter { wallet_data } => { - let pubkey = wallet_data - .parse::() - .map_err(|_| WalletError::InvalidBase58)?; - Ok(adapter_wallet(pubkey)) - } - FormData::HardCoded { wallet_data } => { - let mut buf = [0u8; 64]; - let size = bs58::decode(wallet_data.trim()) - .into(&mut buf) - .map_err(|_| WalletError::InvalidBase58)?; - if size != buf.len() { - return Err(WalletError::InvalidBase58); - } - let keypair = Keypair::from_bytes(&buf).expect("correct size, never fail"); - - Ok(Output { - pubkey: keypair.pubkey(), - keypair, - }) - } - } + let pubkey = self + .public_key + .parse::() + .map_err(|_| WalletError::InvalidBase58)?; + Ok(adapter_wallet(pubkey)) } } @@ -134,8 +112,6 @@ mod tests { targets: Vec::new(), targets_form: TargetsForm { form_data: json!({ - // there is also "wallet_id", but it is not used - "wallet_type": "ADAPTER", "wallet_data": PUBKEY_STR, }), extra: Extra::default(), @@ -144,28 +120,4 @@ mod tests { }; assert_eq!(Wallet::new(&nd).form.unwrap().pubkey, PUBKEY); } - - #[test] - fn hardcoded() { - const KEYPAIR: &str = "oLXLpXdGn6RjMHz3fvcPdGNUDQxXu91t7YAFbtRew3TFVPHAU1UrZJpgiHDLKDtrWZRQg6trQFFp6zEX2TQ1S3k"; - - let nd = NodeData { - r#type: flow_lib::CommandType::Native, - node_id: WALLET.into(), - sources: Vec::new(), - targets: Vec::new(), - targets_form: TargetsForm { - form_data: json!({ - // there is also "wallet_id", but it is not used - "wallet_type": "HARDCODED", - "wallet_data": KEYPAIR, - }), - extra: Extra::default(), - wasm_bytes: None, - }, - }; - let wallet = Wallet::new(&nd).form.unwrap(); - assert_eq!(wallet.keypair.to_base58_string(), KEYPAIR); - assert_eq!(wallet.keypair.pubkey(), wallet.pubkey); - } } From 3fc7c8352f7e1c3b9578c48ea1ffd207fa2fc2e8 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Mon, 13 Nov 2023 18:49:18 +0700 Subject: [PATCH 08/14] . --- Cargo.lock | 4 + crates/db/Cargo.toml | 1 + crates/db/src/connection.rs | 8 +- crates/db/src/connection/conn_impl.rs | 32 ++++++++ crates/db/src/connection/proxied_user_conn.rs | 8 ++ crates/db/src/error.rs | 32 +++++++- crates/db/src/lib.rs | 12 +++ crates/flow-server/src/api/init_auth.rs | 3 +- crates/flow-server/src/api/mod.rs | 43 ---------- .../flow-server/src/api/submit_signature.rs | 5 +- crates/flow-server/src/db_worker/signer.rs | 4 +- .../flow-server/src/db_worker/user_worker.rs | 50 +++++++++++- crates/flow-server/src/middleware/auth.rs | 2 +- crates/utils/Cargo.toml | 3 + crates/utils/src/lib.rs | 61 ++++++++++++++ crates/utils/src/serde_bs58.rs | 80 +++++++++++++++++++ lib/flow-lib/src/context.rs | 4 +- 17 files changed, 293 insertions(+), 59 deletions(-) create mode 100644 crates/utils/src/serde_bs58.rs diff --git a/Cargo.lock b/Cargo.lock index 2facc787..39bc4aaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2200,6 +2200,7 @@ dependencies = [ "tracing", "tracing-subscriber", "url", + "utils", "uuid 1.5.0", "x509-parser", ] @@ -7861,8 +7862,11 @@ name = "utils" version = "0.0.0" dependencies = [ "actix", + "bs58 0.4.0", "futures-util", "hashbrown 0.13.2", + "serde", + "thiserror", "tower", ] diff --git a/crates/db/Cargo.toml b/crates/db/Cargo.toml index e26d7b94..ef4f1bab 100644 --- a/crates/db/Cargo.toml +++ b/crates/db/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" flow = { workspace = true } flow-lib = { workspace = true } value = { workspace = true } +utils = { workspace = true } serde = "1" serde_json = { version = "1", features = ["raw_value"] } diff --git a/crates/db/src/connection.rs b/crates/db/src/connection.rs index c043b5c0..5c7ef4f3 100644 --- a/crates/db/src/connection.rs +++ b/crates/db/src/connection.rs @@ -1,4 +1,4 @@ -use crate::{Error, WasmStorage}; +use crate::{Error, Wallet, WasmStorage}; use async_trait::async_trait; use chrono::{DateTime, Utc}; use deadpool_postgres::Object as Connection; @@ -29,6 +29,8 @@ pub struct UserConnection { pub trait UserConnectionTrait: Any + 'static { async fn clone_flow(&mut self, flow_id: FlowId) -> crate::Result>; + async fn get_wallets(&self) -> crate::Result>; + async fn new_flow_run( &self, config: &ClientConfig, @@ -118,6 +120,10 @@ pub trait UserConnectionTrait: Any + 'static { #[async_trait] impl UserConnectionTrait for UserConnection { + async fn get_wallets(&self) -> crate::Result> { + self.get_wallets().await + } + async fn clone_flow(&mut self, flow_id: FlowId) -> crate::Result> { self.clone_flow(flow_id).await } diff --git a/crates/db/src/connection/conn_impl.rs b/crates/db/src/connection/conn_impl.rs index d6edc544..973f43cd 100644 --- a/crates/db/src/connection/conn_impl.rs +++ b/crates/db/src/connection/conn_impl.rs @@ -1,4 +1,5 @@ use flow_lib::config::client::NodeDataSkipWasm; +use utils::bs58_decode; use super::*; @@ -11,6 +12,37 @@ impl UserConnection { } } + pub async fn get_wallets(&self) -> crate::Result> { + let stmt = self + .conn + .prepare_cached("SELECT public_key, keypair FROM wallets WHERE user_id = $1") + .await + .map_err(Error::exec("prepare get_wallets"))?; + self.conn + .query(&stmt, &[&self.user_id]) + .await + .map_err(Error::exec("get wallets"))? + .into_iter() + .map(|r| { + let pubkey_str = r + .try_get::<_, String>(0) + .map_err(Error::data("wallets.public_key"))?; + let pubkey = + bs58_decode(&pubkey_str).map_err(Error::parsing("wallets.public_key"))?; + + let keypair_str = r + .try_get::<_, Option>(1) + .map_err(Error::data("wallets.keypair"))?; + let keypair = keypair_str + .map(|s| utils::bs58_decode(&s)) + .transpose() + .map_err(Error::parsing("wallets.keypair"))?; + + Ok(Wallet { pubkey, keypair }) + }) + .collect() + } + pub async fn clone_flow(&mut self, flow_id: FlowId) -> crate::Result> { let tx = self .conn diff --git a/crates/db/src/connection/proxied_user_conn.rs b/crates/db/src/connection/proxied_user_conn.rs index 7cdd555b..8c32dfec 100644 --- a/crates/db/src/connection/proxied_user_conn.rs +++ b/crates/db/src/connection/proxied_user_conn.rs @@ -85,6 +85,10 @@ impl ProxiedUserConn { #[async_trait::async_trait] impl UserConnectionTrait for ProxiedUserConn { + async fn get_wallets(&self) -> crate::Result> { + self.send::<[(); 0], _>("get_wallets", &[]).await + } + async fn clone_flow(&mut self, flow_id: FlowId) -> crate::Result> { self.send("clone_flow", &(flow_id,)).await } @@ -230,6 +234,10 @@ impl UserConnection { pub async fn process_rpc(&mut self, req_json: &str) -> Result, BoxError> { let req: RpcRequest<'_, &'_ RawValue> = serde_json::from_str(req_json)?; match req.method { + "get_wallets" => { + let res = self.get_wallets().await?; + Ok(serde_json::value::to_raw_value(&res)?) + } "clone_flow" => { let (flow_id,) = serde_json::from_str(req.params.get())?; let res = self.clone_flow(flow_id).await?; diff --git a/crates/db/src/error.rs b/crates/db/src/error.rs index a4a0fe5b..8cc02c95 100644 --- a/crates/db/src/error.rs +++ b/crates/db/src/error.rs @@ -33,6 +33,13 @@ pub enum Error { context: &'static str, location: &'static Location<'static>, }, + #[error("parsing error: {error}, context {context:?}, at {location}")] + Parsing { + #[source] + error: anyhow::Error, + context: &'static str, + location: &'static Location<'static>, + }, #[error("{kind} not found: {id}, at {location}")] ResourceNotFound { kind: &'static str, @@ -123,6 +130,15 @@ impl> Error { location, }, Error::ProxyError(e) => Error::ProxyError(e), + Error::Parsing { + error, + context, + location, + } => Error::Parsing { + error, + context, + location, + }, } } @@ -162,7 +178,7 @@ impl> Error { } } - /// Error when parsing data from the database, usually for JSON deserialize error. + /// Error when parsing JSON data from the database. #[track_caller] pub fn json(context: &'static str) -> impl FnOnce(serde_json::Error) -> Self { let location = std::panic::Location::caller(); @@ -174,6 +190,20 @@ impl> Error { } } + /// Error when parsing data from the database. + #[track_caller] + pub fn parsing( + context: &'static str, + ) -> impl FnOnce(E1) -> Self { + let location = std::panic::Location::caller(); + + move |error: E1| Error::Parsing { + context, + location, + error: error.into(), + } + } + #[track_caller] pub fn not_found(kind: &'static str, id: I) -> Self { let location = std::panic::Location::caller(); diff --git a/crates/db/src/lib.rs b/crates/db/src/lib.rs index 93a035f9..dd8da82d 100644 --- a/crates/db/src/lib.rs +++ b/crates/db/src/lib.rs @@ -29,3 +29,15 @@ pub struct FlowRunLogsRow { pub content: String, pub module: Option, } + +#[derive(Serialize, Deserialize)] +pub struct Wallet { + #[serde(with = "utils::serde_bs58")] + pub pubkey: [u8; 32], + #[serde( + default, + with = "utils::serde_bs58::opt", + skip_serializing_if = "Option::is_none" + )] + pub keypair: Option<[u8; 64]>, +} diff --git a/crates/flow-server/src/api/init_auth.rs b/crates/flow-server/src/api/init_auth.rs index afac7b40..e2eb6eb8 100644 --- a/crates/flow-server/src/api/init_auth.rs +++ b/crates/flow-server/src/api/init_auth.rs @@ -1,10 +1,9 @@ -use super::bs58_decode; use super::prelude::*; use crate::user::SignatureAuth; #[derive(Deserialize)] pub struct Params { - #[serde(deserialize_with = "bs58_decode")] + #[serde(with = "utils::serde_bs58")] pub pubkey: [u8; 32], } diff --git a/crates/flow-server/src/api/mod.rs b/crates/flow-server/src/api/mod.rs index 2dcf37de..a9b4025c 100644 --- a/crates/flow-server/src/api/mod.rs +++ b/crates/flow-server/src/api/mod.rs @@ -46,46 +46,3 @@ pub mod prelude { } } } - -pub mod serde_bs58 { - pub use super::bs58_decode as deserialize; - pub use super::bs58_encode as serialize; -} - -pub fn bs58_encode(t: &[u8; N], s: S) -> Result -where - S: serde::Serializer, -{ - s.serialize_str(&bs58::encode(t).into_string()) -} - -pub fn bs58_decode<'de, const S: usize, D>(d: D) -> Result<[u8; S], D::Error> -where - D: serde::Deserializer<'de>, -{ - struct Visitor; - - impl<'de, const N: usize> serde::de::Visitor<'de> for Visitor { - type Value = [u8; N]; - - fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.write_str("base58 public key") - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, - { - let mut pk = [0u8; N]; - let size = bs58::decode(v) - .into(&mut pk) - .map_err(|_| serde::de::Error::custom("invalid base58"))?; - if size != N { - return Err(serde::de::Error::custom("invalid base58")); - } - Ok(pk) - } - } - - d.deserialize_str(Visitor::) -} diff --git a/crates/flow-server/src/api/submit_signature.rs b/crates/flow-server/src/api/submit_signature.rs index 089eb7e7..e068443a 100644 --- a/crates/flow-server/src/api/submit_signature.rs +++ b/crates/flow-server/src/api/submit_signature.rs @@ -1,14 +1,13 @@ +use super::prelude::*; use crate::db_worker::{ user_worker::{SubmitError, SubmitSignature}, FindActor, UserWorker, }; -use super::prelude::*; - #[derive(Deserialize)] pub struct Params { id: i64, - #[serde(deserialize_with = "super::bs58_decode")] + #[serde(with = "utils::serde_bs58")] signature: [u8; 64], } diff --git a/crates/flow-server/src/db_worker/signer.rs b/crates/flow-server/src/db_worker/signer.rs index 7b13a234..c8df7827 100644 --- a/crates/flow-server/src/db_worker/signer.rs +++ b/crates/flow-server/src/db_worker/signer.rs @@ -14,7 +14,7 @@ pub enum SignerType { } pub struct SignerWorker { - signers: HashMap, + pub signers: HashMap, } impl Actor for SignerWorker { @@ -26,7 +26,7 @@ impl actix::Handler for SignerWorker { fn handle(&mut self, msg: signer::SignatureRequest, _: &mut Self::Context) -> Self::Result { match self.signers.get(&msg.pubkey) { - None => ready(Err(signer::Error::Pubkey)).boxed(), + None => ready(Err(signer::Error::Pubkey(msg.pubkey.to_string()))).boxed(), Some(SignerType::Keypair(keypair)) => ready(Ok(signer::SignatureResponse { signature: keypair.sign_message(&msg.message), })) diff --git a/crates/flow-server/src/db_worker/user_worker.rs b/crates/flow-server/src/db_worker/user_worker.rs index debb16f4..7a9f1b6d 100644 --- a/crates/flow-server/src/db_worker/user_worker.rs +++ b/crates/flow-server/src/db_worker/user_worker.rs @@ -1,6 +1,8 @@ use super::{ - flow_run_worker::FlowRunWorker, messages::SubscribeError, Counter, DBWorker, GetTokenWorker, - StartActor, + flow_run_worker::FlowRunWorker, + messages::SubscribeError, + signer::{SignerType, SignerWorker}, + Counter, DBWorker, GetTokenWorker, StartActor, }; use crate::error::ErrorBody; use actix::{ @@ -20,7 +22,11 @@ use flow_lib::{ use futures_channel::oneshot; use futures_util::future::BoxFuture; use hashbrown::HashMap; -use solana_sdk::signature::Signature; +use solana_sdk::{ + pubkey::Pubkey, + signature::{Keypair, Signature}, + signer::Signer, +}; use std::future::ready; use thiserror::Error as ThisError; use utils::address_book::ManagableActor; @@ -401,6 +407,8 @@ pub enum StartError { Jwt(#[from] get_jwt::Error), #[error(transparent)] Mailbox(#[from] actix::MailboxError), + #[error(transparent)] + Db(#[from] db::Error), } impl ResponseError for StartError { @@ -436,6 +444,7 @@ impl ResponseError for StartError { | get_jwt::Error::Other(_) => StatusCode::INTERNAL_SERVER_ERROR, }, StartError::Mailbox(_) => StatusCode::INTERNAL_SERVER_ERROR, + StartError::Db(_) => StatusCode::INTERNAL_SERVER_ERROR, } } @@ -456,6 +465,7 @@ impl actix::Handler for UserWorker { let addr = ctx.address(); let endpoints = self.endpoints.clone(); let root = self.root.clone(); + let db = self.db.clone(); Box::pin(async move { if msg.user.id != user_id { return Err(StartError::Unauthorized); @@ -471,10 +481,42 @@ impl actix::Handler for UserWorker { }) .await??; + let conn = db.get_user_conn(user_id).await?; + let wallets = conn.get_wallets().await?; + let mut signers = HashMap::new(); + for w in wallets { + let pk = Pubkey::new_from_array(w.pubkey); + if !pk.is_on_curve() { + tracing::warn!("invalid wallet"); + continue; + } + let s = match w.keypair { + None => SignerType::UserWallet { + sender: addr.clone().recipient(), + }, + Some(keypair) => { + let keypair = Keypair::from_bytes(&keypair).ok().and_then(|k| { + let pubkey: ed25519_dalek::PublicKey = k.secret().into(); + (k.pubkey().to_bytes() == pubkey.to_bytes()) + .then_some(SignerType::Keypair(k)) + }); + match keypair { + None => { + tracing::warn!("invalid wallet"); + continue; + } + Some(signer) => signer, + } + } + }; + signers.insert(pk, s); + } + let signer = SignerWorker { signers }.start(); + let r = FlowRegistry::from_actix( msg.user, msg.flow_id, - addr.clone().recipient(), + signer.recipient(), addr.clone().recipient(), addr.clone().recipient(), addr.clone().recipient(), diff --git a/crates/flow-server/src/middleware/auth.rs b/crates/flow-server/src/middleware/auth.rs index 16d8a0d7..b0a11e09 100644 --- a/crates/flow-server/src/middleware/auth.rs +++ b/crates/flow-server/src/middleware/auth.rs @@ -72,7 +72,7 @@ pub struct Token { #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub struct JWTPayload { pub user_id: Uuid, - #[serde(with = "crate::api::serde_bs58")] + #[serde(with = "utils::serde_bs58")] pub pubkey: [u8; 32], } diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 23ffaeb5..9179105c 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -10,3 +10,6 @@ tower = { version = "0.4", features = ["buffer", "util"] } actix = "0.13" hashbrown = "0.13" futures-util = { version = "0.3", features = ["sink"] } +serde = "1" +bs58 = "0.4" +thiserror = "1" diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 129dcf5b..302fb939 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -1,2 +1,63 @@ +use thiserror::Error as ThisError; + pub mod actix_service; pub mod address_book; +pub mod serde_bs58; + +pub struct B58(pub [u8; N]); + +#[derive(ThisError, Debug)] +pub enum Bs58Error { + #[error(transparent)] + Decode(#[from] bs58::decode::Error), + #[error("invalid length, expected: {}, got: {}", expected, got)] + Size { expected: usize, got: usize }, +} + +impl std::str::FromStr for B58 { + type Err = Bs58Error; + + fn from_str(s: &str) -> Result { + let mut buf = [0u8; N]; + let size = bs58::decode(s).into(&mut buf)?; + if size != N { + return Err(Bs58Error::Size { + expected: N, + got: size, + }); + } + Ok(Self(buf)) + } +} + +pub fn bs58_decode(s: &str) -> Result<[u8; N], Bs58Error> { + Ok(s.parse::>()?.0) +} + +pub struct OptionVisitor(pub(crate) V); + +impl<'de, V> serde::de::Visitor<'de> for OptionVisitor +where + V: serde::de::Visitor<'de>, +{ + type Value = Option; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("optional ")?; + self.0.expecting(formatter) + } + + fn visit_none(self) -> Result + where + E: serde::de::Error, + { + Ok(None) + } + + fn visit_some(self, d: D) -> Result + where + D: serde::Deserializer<'de>, + { + d.deserialize_any(self.0).map(Some) + } +} diff --git a/crates/utils/src/serde_bs58.rs b/crates/utils/src/serde_bs58.rs new file mode 100644 index 00000000..c19bbf53 --- /dev/null +++ b/crates/utils/src/serde_bs58.rs @@ -0,0 +1,80 @@ +pub fn serialize(t: &[u8; N], s: S) -> Result +where + S: serde::Serializer, +{ + s.serialize_str(&bs58::encode(t).into_string()) +} + +pub struct Visitor; + +impl<'de, const N: usize> serde::de::Visitor<'de> for Visitor { + type Value = [u8; N]; + + fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.write_str("base58 public key") + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + let mut pk = [0u8; N]; + let size = bs58::decode(v) + .into(&mut pk) + .map_err(|_| serde::de::Error::custom("invalid base58"))?; + if size != N { + return Err(serde::de::Error::custom("invalid base58")); + } + Ok(pk) + } +} + +pub fn deserialize<'de, const S: usize, D>(d: D) -> Result<[u8; S], D::Error> +where + D: serde::Deserializer<'de>, +{ + struct Visitor; + + impl<'de, const N: usize> serde::de::Visitor<'de> for Visitor { + type Value = [u8; N]; + + fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.write_str("base58 public key") + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + let mut pk = [0u8; N]; + let size = bs58::decode(v) + .into(&mut pk) + .map_err(|_| serde::de::Error::custom("invalid base58"))?; + if size != N { + return Err(serde::de::Error::custom("invalid base58")); + } + Ok(pk) + } + } + + d.deserialize_str(Visitor::) +} + +pub mod opt { + pub fn serialize(sig: &Option<[u8; N]>, s: S) -> Result + where + S: serde::Serializer, + { + match sig { + Some(sig) => super::serialize(sig, s), + None => s.serialize_none(), + } + } + + pub fn deserialize<'de, const N: usize, D>(d: D) -> Result, D::Error> + where + D: serde::Deserializer<'de>, + { + d.deserialize_option(crate::OptionVisitor(super::Visitor)) + } +} diff --git a/lib/flow-lib/src/context.rs b/lib/flow-lib/src/context.rs index 2c263ce2..80b49f2f 100644 --- a/lib/flow-lib/src/context.rs +++ b/lib/flow-lib/src/context.rs @@ -92,8 +92,8 @@ pub mod signer { #[derive(ThisError, Debug)] pub enum Error { - #[error("can't sign for this pubkey")] - Pubkey, + #[error("can't sign for pubkey: {}", .0)] + Pubkey(String), #[error("can't sign for this user")] User, #[error("timeout")] From b42efd23b0685e2fdb1ecd0b36f2238abdee2b18 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Mon, 13 Nov 2023 19:16:54 +0700 Subject: [PATCH 09/14] . --- crates/flow-server/src/db_worker/signer.rs | 55 +++++++++++++++++-- .../flow-server/src/db_worker/user_worker.rs | 45 ++------------- 2 files changed, 55 insertions(+), 45 deletions(-) diff --git a/crates/flow-server/src/db_worker/signer.rs b/crates/flow-server/src/db_worker/signer.rs index c8df7827..8299c9f6 100644 --- a/crates/flow-server/src/db_worker/signer.rs +++ b/crates/flow-server/src/db_worker/signer.rs @@ -1,5 +1,9 @@ use actix::{Actor, ResponseFuture}; -use flow_lib::context::signer; +use db::{pool::DbPool, Error as DbError}; +use flow_lib::{ + context::signer::{self, SignatureRequest}, + UserId, +}; use futures_util::FutureExt; use hashbrown::HashMap; use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; @@ -9,7 +13,7 @@ pub enum SignerType { Keypair(Keypair), UserWallet { // Forward to UserWorker - sender: actix::Recipient, + sender: actix::Recipient, }, } @@ -21,10 +25,10 @@ impl Actor for SignerWorker { type Context = actix::Context; } -impl actix::Handler for SignerWorker { - type Result = ResponseFuture<::Result>; +impl actix::Handler for SignerWorker { + type Result = ResponseFuture<::Result>; - fn handle(&mut self, msg: signer::SignatureRequest, _: &mut Self::Context) -> Self::Result { + fn handle(&mut self, msg: SignatureRequest, _: &mut Self::Context) -> Self::Result { match self.signers.get(&msg.pubkey) { None => ready(Err(signer::Error::Pubkey(msg.pubkey.to_string()))).boxed(), Some(SignerType::Keypair(keypair)) => ready(Ok(signer::SignatureResponse { @@ -38,3 +42,44 @@ impl actix::Handler for SignerWorker { } } } + +impl SignerWorker { + pub async fn fetch_and_start<'a, I>(db: DbPool, users: I) -> Result, DbError> + where + I: IntoIterator)>, + { + let mut signers = HashMap::new(); + for (user, sender) in users { + let conn = db.get_user_conn(*user).await?; + let wallets = conn.get_wallets().await?; + for w in wallets { + let pk = Pubkey::new_from_array(w.pubkey); + if !pk.is_on_curve() { + tracing::warn!("invalid wallet"); + continue; + } + let s = match w.keypair { + None => SignerType::UserWallet { + sender: sender.clone(), + }, + Some(keypair) => { + let keypair = Keypair::from_bytes(&keypair).ok().and_then(|k| { + let pubkey: ed25519_dalek::PublicKey = k.secret().into(); + (k.pubkey().to_bytes() == pubkey.to_bytes()) + .then_some(SignerType::Keypair(k)) + }); + match keypair { + None => { + tracing::warn!("invalid wallet"); + continue; + } + Some(signer) => signer, + } + } + }; + signers.insert(pk, s); + } + } + Ok(Self { signers }.start()) + } +} diff --git a/crates/flow-server/src/db_worker/user_worker.rs b/crates/flow-server/src/db_worker/user_worker.rs index 7a9f1b6d..7f37f147 100644 --- a/crates/flow-server/src/db_worker/user_worker.rs +++ b/crates/flow-server/src/db_worker/user_worker.rs @@ -1,8 +1,6 @@ use super::{ - flow_run_worker::FlowRunWorker, - messages::SubscribeError, - signer::{SignerType, SignerWorker}, - Counter, DBWorker, GetTokenWorker, StartActor, + flow_run_worker::FlowRunWorker, messages::SubscribeError, signer::SignerWorker, Counter, + DBWorker, GetTokenWorker, StartActor, }; use crate::error::ErrorBody; use actix::{ @@ -22,11 +20,7 @@ use flow_lib::{ use futures_channel::oneshot; use futures_util::future::BoxFuture; use hashbrown::HashMap; -use solana_sdk::{ - pubkey::Pubkey, - signature::{Keypair, Signature}, - signer::Signer, -}; +use solana_sdk::signature::Signature; use std::future::ready; use thiserror::Error as ThisError; use utils::address_book::ManagableActor; @@ -481,37 +475,8 @@ impl actix::Handler for UserWorker { }) .await??; - let conn = db.get_user_conn(user_id).await?; - let wallets = conn.get_wallets().await?; - let mut signers = HashMap::new(); - for w in wallets { - let pk = Pubkey::new_from_array(w.pubkey); - if !pk.is_on_curve() { - tracing::warn!("invalid wallet"); - continue; - } - let s = match w.keypair { - None => SignerType::UserWallet { - sender: addr.clone().recipient(), - }, - Some(keypair) => { - let keypair = Keypair::from_bytes(&keypair).ok().and_then(|k| { - let pubkey: ed25519_dalek::PublicKey = k.secret().into(); - (k.pubkey().to_bytes() == pubkey.to_bytes()) - .then_some(SignerType::Keypair(k)) - }); - match keypair { - None => { - tracing::warn!("invalid wallet"); - continue; - } - Some(signer) => signer, - } - } - }; - signers.insert(pk, s); - } - let signer = SignerWorker { signers }.start(); + let signer = + SignerWorker::fetch_and_start(db, &[(user_id, addr.clone().recipient())]).await?; let r = FlowRegistry::from_actix( msg.user, From d337ea73d46a6c303ab459ca99d3ccedaea9598b Mon Sep 17 00:00:00 2001 From: Duy Do Date: Mon, 13 Nov 2023 19:35:16 +0700 Subject: [PATCH 10/14] . --- crates/flow-server/src/db_worker/signer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/flow-server/src/db_worker/signer.rs b/crates/flow-server/src/db_worker/signer.rs index 8299c9f6..d3a87b90 100644 --- a/crates/flow-server/src/db_worker/signer.rs +++ b/crates/flow-server/src/db_worker/signer.rs @@ -55,7 +55,7 @@ impl SignerWorker { for w in wallets { let pk = Pubkey::new_from_array(w.pubkey); if !pk.is_on_curve() { - tracing::warn!("invalid wallet"); + tracing::warn!("invalid wallet: pubkey is not on curve"); continue; } let s = match w.keypair { @@ -70,7 +70,7 @@ impl SignerWorker { }); match keypair { None => { - tracing::warn!("invalid wallet"); + tracing::warn!("invalid keypair: mismatch"); continue; } Some(signer) => signer, From 357b9b071004dc0353e8c58811ce24cb2f82e82b Mon Sep 17 00:00:00 2001 From: Duy Do Date: Tue, 14 Nov 2023 12:05:16 +0700 Subject: [PATCH 11/14] . --- crates/cmds-solana/src/wallet.rs | 2 +- crates/flow/test_files/nft.json | 3 +-- test_files/nft.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/cmds-solana/src/wallet.rs b/crates/cmds-solana/src/wallet.rs index ac9aabc9..e59c8db3 100644 --- a/crates/cmds-solana/src/wallet.rs +++ b/crates/cmds-solana/src/wallet.rs @@ -112,7 +112,7 @@ mod tests { targets: Vec::new(), targets_form: TargetsForm { form_data: json!({ - "wallet_data": PUBKEY_STR, + "public_key": PUBKEY_STR, }), extra: Extra::default(), wasm_bytes: None, diff --git a/crates/flow/test_files/nft.json b/crates/flow/test_files/nft.json index 5aa5cc6e..f7e3fbc9 100644 --- a/crates/flow/test_files/nft.json +++ b/crates/flow/test_files/nft.json @@ -92,8 +92,7 @@ "json_schema": {}, "ui_schema": {}, "form_data": { - "wallet_id": 65, - "wallet_data": "HJbqSuV94woJfyxFNnJyfQdACvvJYaNWsW1x6wmJ8kiq", + "public_key": "HJbqSuV94woJfyxFNnJyfQdACvvJYaNWsW1x6wmJ8kiq", "wallet_type": "ADAPTER" }, "extra": { diff --git a/test_files/nft.json b/test_files/nft.json index 5aa5cc6e..b955323e 100644 --- a/test_files/nft.json +++ b/test_files/nft.json @@ -93,7 +93,7 @@ "ui_schema": {}, "form_data": { "wallet_id": 65, - "wallet_data": "HJbqSuV94woJfyxFNnJyfQdACvvJYaNWsW1x6wmJ8kiq", + "public_key": "HJbqSuV94woJfyxFNnJyfQdACvvJYaNWsW1x6wmJ8kiq", "wallet_type": "ADAPTER" }, "extra": { From 58bfe533f93ae742a820ce826669ed49e86c66aa Mon Sep 17 00:00:00 2001 From: Duy Do Date: Tue, 14 Nov 2023 12:23:50 +0700 Subject: [PATCH 12/14] Revert "Update licence text" This reverts commit 4a7ed6e375efe66c080f04b4871b7191aaae111a. --- LICENSE | 7 +++++++ README.md | 9 +-------- lib/flow-lib/Cargo.toml | 4 ---- lib/flow-value/Cargo.toml | 4 ---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/LICENSE b/LICENSE index 0ad25db4..0e583f09 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,10 @@ +Open source license: AGPLv3 + +For commercial projects and to keep your source code proprietary, +please get a license at www.spaceoperator.com + +////////////////////////////////////////////////////////////////////// + GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 diff --git a/README.md b/README.md index cdb17ce8..4ced4e6f 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,4 @@ RUST_LOG=info cargo run -p flow-server -- guest.toml ``` This server can be used to run flows belonging to you. Toggle "Remote 🌐" button in flow editor to switch to `localhost` server. -Please note that some browsers such as Brave will block requests to `localhost` by default, disable protection if you encounter network errors. - -## License - -Open source license: AGPLv3 - -For commercial projects and to keep your source code proprietary, -please get a license at [www.spaceoperator.com](www.spaceoperator.com). +Please note that some browsers such as Brave will block requests to `localhost` by default, disable protection if you encounter network errors. \ No newline at end of file diff --git a/lib/flow-lib/Cargo.toml b/lib/flow-lib/Cargo.toml index 66709af3..feacdbe9 100644 --- a/lib/flow-lib/Cargo.toml +++ b/lib/flow-lib/Cargo.toml @@ -2,10 +2,6 @@ name = "flow-lib" version = "0.1.0" edition = "2021" -license = "AGPL-3.0-only" -homepage = "https://www.spaceoperator.com" -repository = "https://github.com/space-operator/flow-backend" -keywords = ["flow", "solana"] [dependencies] value = { workspace = true } diff --git a/lib/flow-value/Cargo.toml b/lib/flow-value/Cargo.toml index 32d81a2a..b5fb6095 100644 --- a/lib/flow-value/Cargo.toml +++ b/lib/flow-value/Cargo.toml @@ -2,10 +2,6 @@ name = "flow-value" version = "0.1.0" edition = "2021" -license = "AGPL-3.0-only" -homepage = "https://www.spaceoperator.com" -repository = "https://github.com/space-operator/flow-backend" -keywords = ["flow", "solana"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] From 6b51ae5f53e083bdc31b5f6976a093852de0ade6 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Tue, 14 Nov 2023 12:37:15 +0700 Subject: [PATCH 13/14] Fix docs --- lib/flow-value/src/lib.rs | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/flow-value/src/lib.rs b/lib/flow-value/src/lib.rs index 6ab3daec..b0b0fe65 100644 --- a/lib/flow-value/src/lib.rs +++ b/lib/flow-value/src/lib.rs @@ -4,8 +4,8 @@ //! Common operations: //! - Converting [`Value`] to Rust types. //! - Converting Rust types to [`Value`]. -//! - Receiving [`value::Map`][Map] as node's input. -//! - Returning [`value::Map`][Map] as node's output. +//! - Receiving [`flow_value::Map`][Map] as node's input. +//! - Returning [`flow_value::Map`][Map] as node's output. //! - Converting [`Value`] to/from JSON to use in HTTP APIs and database. //! - Getting and updating nested values with JSON Pointer syntax. @@ -43,17 +43,17 @@ pub mod signature; /// ``` /// use solana_sdk::pubkey::Pubkey; /// use solana_sdk::pubkey; -/// use value::Value; +/// use flow_value::Value; /// /// #[derive(serde::Deserialize)] /// pub struct User { /// pubkey: Pubkey, /// } /// -/// let value = Value::Map(value::map! { +/// let value = Value::Map(flow_value::map! { /// "pubkey" => pubkey!("My11111111111111111111111111111111111111111"), /// }); -/// value::from_value::(value).unwrap(); +/// flow_value::from_value::(value).unwrap(); /// ``` pub fn from_value(value: Value) -> Result where @@ -69,17 +69,17 @@ where /// ``` /// use solana_sdk::pubkey::Pubkey; /// use solana_sdk::pubkey; -/// use value::Value; +/// use flow_value::Value; /// /// #[derive(serde::Deserialize)] /// pub struct User { /// pubkey: Pubkey, /// } /// -/// let map = value::map! { +/// let map = flow_value::map! { /// "pubkey" => pubkey!("My11111111111111111111111111111111111111111"), /// }; -/// value::from_map::(map).unwrap(); +/// flow_value::from_map::(map).unwrap(); /// ``` pub fn from_map(map: Map) -> Result where @@ -94,9 +94,9 @@ where /// /// ``` /// use solana_sdk::signature::Signature; -/// use value::Value; +/// use flow_value::Value; /// -/// let val = value::to_value(&Signature::new_unique()).unwrap(); +/// let val = flow_value::to_value(&Signature::new_unique()).unwrap(); /// assert!(matches!(val, Value::B64(_))); /// ``` pub fn to_value(t: &T) -> Result @@ -111,10 +111,10 @@ where /// # Example /// /// ``` -/// use value::Value; +/// use flow_value::Value; /// -/// let map = value::to_map(&serde_json::json!({"A": "B"})).unwrap(); -/// assert_eq!(map, value::map! { "A" => "B" }); +/// let map = flow_value::to_map(&serde_json::json!({"A": "B"})).unwrap(); +/// assert_eq!(map, flow_value::map! { "A" => "B" }); /// ``` pub fn to_map(t: &T) -> Result where @@ -153,30 +153,30 @@ pub type Map = self::HashMap; /// /// # Node Input /// -/// Node receives a [`value::Map`][Map] as its input. It is possible to use the map directly, but +/// Node receives a [`flow_value::Map`][Map] as its input. It is possible to use the map directly, but /// it is often preferred to convert it to structs or enums of your choice. /// /// [`Value`] implements [`Deserializer`][serde::Deserializer], therefore it can be converted to /// any types supported by Serde. We provide 2 helpers: /// -/// - [`value::from_value`][from_value] - [`Value`] to any `T: Deserialize`. -/// - [`value::from_map`][from_map] - [`Map`] to any `T: Deserialize`. +/// - [`flow_value::from_value`][from_value] - [`Value`] to any `T: Deserialize`. +/// - [`flow_value::from_map`][from_map] - [`Map`] to any `T: Deserialize`. /// /// # Node Output /// -/// Node returns a [`value::Map`][Map] as its output. +/// Node returns a [`flow_value::Map`][Map] as its output. /// -/// Building the output directly with [`value::map!`][macro@map] and -/// [`value::array!`][macro@array] macros: +/// Building the output directly with [`flow_value::map!`][macro@map] and +/// [`flow_value::array!`][macro@array] macros: /// ``` -/// let value = value::map! { +/// let value = flow_value::map! { /// "customer_name" => "John", -/// "items" => value::array![1, 2, 3], +/// "items" => flow_value::array![1, 2, 3], /// }; /// ``` /// /// [`Value`] also implements [`Serializer`][serde::Serializer], you can use -/// [`value::to_map`][to_map] to convert any type `T: Serialize` into [`value::Map`][Map]. +/// [`flow_value::to_map`][to_map] to convert any type `T: Serialize` into [`value::Map`][Map]. /// /// ``` /// #[derive(serde::Serialize)] @@ -185,7 +185,7 @@ pub type Map = self::HashMap; /// items: Vec, /// } /// -/// value::to_map(&Order { +/// flow_value::to_map(&Order { /// customer_name: "John".to_owned(), /// items: [1, 2, 3].into(), /// }) @@ -222,7 +222,7 @@ pub type Map = self::HashMap; /// /// Use [`serde_json`] to encode and decode [`Value`] as JSON: /// ``` -/// use value::Value; +/// use flow_value::Value; /// /// let value = Value::U64(10); /// From 0252104cff010b899b710e3255bd00907039efa6 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Tue, 14 Nov 2023 15:12:29 +0700 Subject: [PATCH 14/14] re-export --- crates/db/src/pool.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/db/src/pool.rs b/crates/db/src/pool.rs index ddbbb6ba..0d0656a9 100644 --- a/crates/db/src/pool.rs +++ b/crates/db/src/pool.rs @@ -6,15 +6,15 @@ use crate::{ }, Error, LocalStorage, WasmStorage, }; -use deadpool_postgres::{ - ClientWrapper, Hook, HookError, Metrics, Object as Connection, Pool, SslMode, -}; +use deadpool_postgres::{ClientWrapper, Hook, HookError, Metrics, Pool, SslMode}; use flow_lib::{context::get_jwt, UserId}; use futures_util::FutureExt; use hashbrown::HashMap; use ring::signature::{UnparsedPublicKey, RSA_PSS_2048_8192_SHA256}; use std::{sync::Arc, time::Duration}; +pub use deadpool_postgres::Object as Connection; + #[derive(Clone)] pub enum DbPool { Real(RealDbPool),