aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-08-10 12:09:22 +0200
committerrtkay123 <dev@kanjala.com>2025-08-10 12:09:27 +0200
commitaf407fe5c3e1d5b8b315db029805fa7290c83fae (patch)
treec6cde42d7e05453b0be99fa5c3f181fc843ab76a
parentd50185df5a5870498b6c7e6b51e0368d051743ca (diff)
downloadwarden-af407fe5c3e1d5b8b315db029805fa7290c83fae.tar.bz2
warden-af407fe5c3e1d5b8b315db029805fa7290c83fae.zip
feat(pseudonyms): proto definitions
-rw-r--r--Cargo.lock19
-rw-r--r--crates/pseudonyms/Cargo.toml11
-rw-r--r--crates/pseudonyms/src/main.rs3
-rw-r--r--crates/warden/Cargo.toml2
-rw-r--r--lib/warden-core/Cargo.toml4
-rw-r--r--lib/warden-core/build.rs82
-rw-r--r--lib/warden-core/src/google/parser.rs1
-rw-r--r--lib/warden-core/src/google/parser/dt.rs161
-rw-r--r--lib/warden-core/src/iso20022.rs4
-rw-r--r--lib/warden-core/src/lib.rs16
-rw-r--r--lib/warden-core/src/pseudonyms.rs15
-rw-r--r--proto/pseudonyms/account.proto15
-rw-r--r--proto/pseudonyms/account_holder.proto11
-rw-r--r--proto/pseudonyms/entity.proto10
-rw-r--r--proto/pseudonyms/transaction_relationship.proto34
15 files changed, 267 insertions, 121 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3a95300..d0bead9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2293,6 +2293,17 @@ dependencies = [
]
[[package]]
+name = "tonic-prost"
+version = "0.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9c511b9a96d40cb12b7d5d00464446acf3b9105fd3ce25437cfe41c92b1c87d"
+dependencies = [
+ "bytes",
+ "prost 0.14.1",
+ "tonic 0.14.0",
+]
+
+[[package]]
name = "tonic-prost-build"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2710,12 +2721,20 @@ dependencies = [
"serde_json",
"time",
"tonic 0.14.0",
+ "tonic-prost",
"tonic-prost-build",
"tonic-types",
"utoipa",
]
[[package]]
+name = "warden-pseudonyms"
+version = "0.1.0"
+dependencies = [
+ "warden-core",
+]
+
+[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/crates/pseudonyms/Cargo.toml b/crates/pseudonyms/Cargo.toml
new file mode 100644
index 0000000..4ddf179
--- /dev/null
+++ b/crates/pseudonyms/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "warden-pseudonyms"
+version = "0.1.0"
+edition = "2024"
+license.workspace = true
+homepage.workspace = true
+documentation.workspace = true
+description.workspace = true
+
+[dependencies]
+warden-core = { workspace = true, features = ["pseudonyms", "serde-time"] }
diff --git a/crates/pseudonyms/src/main.rs b/crates/pseudonyms/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/crates/pseudonyms/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/crates/warden/Cargo.toml b/crates/warden/Cargo.toml
index d66c15e..b10ed45 100644
--- a/crates/warden/Cargo.toml
+++ b/crates/warden/Cargo.toml
@@ -30,7 +30,7 @@ utoipa-rapidoc = { workspace = true, optional = true }
utoipa-redoc = { workspace = true, optional = true }
utoipa-scalar = { workspace = true, optional = true }
utoipa-swagger-ui = { workspace = true, optional = true }
-warden-core = { workspace = true, features = ["iso20022", "serde", "openapi"] }
+warden-core = { workspace = true, features = ["message", "pseudonyms", "serde", "openapi"] }
[features]
default = []
diff --git a/lib/warden-core/Cargo.toml b/lib/warden-core/Cargo.toml
index bdf0af0..759e018 100644
--- a/lib/warden-core/Cargo.toml
+++ b/lib/warden-core/Cargo.toml
@@ -17,12 +17,14 @@ serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
time = { workspace = true, optional = true }
tonic = { workspace = true, optional = true }
+tonic-prost = { version = "0.14.1", optional = true }
tonic-types = { version = "0.14.0", optional = true }
utoipa = { workspace = true, optional = true }
[features]
default = []
-iso20022 = ["dep:prost", "dep:tonic", "dep:tonic-types"]
+message = ["dep:prost", "dep:tonic", "dep:tonic-types", "dep:tonic-prost"]
+pseudonyms = ["dep:prost", "dep:tonic", "dep:tonic-types", "dep:tonic-prost"]
serde = ["dep:serde", "serde/derive", "dep:serde_json"]
serde-time = [
"time",
diff --git a/lib/warden-core/build.rs b/lib/warden-core/build.rs
index 46793ed..57e20e0 100644
--- a/lib/warden-core/build.rs
+++ b/lib/warden-core/build.rs
@@ -1,29 +1,48 @@
-#[cfg(feature = "iso20022")]
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
enum Entity {
- #[cfg(feature = "iso20022")]
+ #[cfg(feature = "message")]
ISO2022,
+ #[cfg(feature = "pseudonyms")]
+ Pseudonyms,
}
-#[cfg(feature = "iso20022")]
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
impl Entity {
fn protos(&self) -> Vec<&'static str> {
- let mut res: Vec<&'static str> = vec![];
+ let mut res: Vec<&'static str> = vec![
+ // "proto/googleapis/google/type/date.proto",
+ // "proto/googleapis/google/type/money.proto",
+ // "proto/googleapis/google/type/latlng.proto",
+ ];
- #[cfg(feature = "iso20022")]
+ #[cfg(feature = "message")]
fn iso20022_protos() -> Vec<&'static str> {
vec![
- "proto/iso20022/pacs_008_001_12.proto",
- "proto/iso20022/pacs_002_001_12.proto",
- "proto/googleapis/google/type/money.proto",
+ // "proto/iso20022/pacs_008_001_12.proto",
+ // "proto/iso20022/pacs_002_001_12.proto",
"proto/warden_message.proto",
]
}
+ #[cfg(feature = "pseudonyms")]
+ fn pseudonyms_protos() -> Vec<&'static str> {
+ vec![
+ "proto/pseudonyms/account.proto",
+ "proto/pseudonyms/entity.proto",
+ "proto/pseudonyms/account_holder.proto",
+ "proto/pseudonyms/transaction_relationship.proto",
+ ]
+ }
+
match self {
- #[cfg(feature = "iso20022")]
+ #[cfg(feature = "message")]
Entity::ISO2022 => {
res.extend(iso20022_protos());
}
+ #[cfg(feature = "pseudonyms")]
+ Entity::Pseudonyms => {
+ res.extend(pseudonyms_protos());
+ }
}
res
}
@@ -32,25 +51,26 @@ impl Entity {
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=../../proto");
- #[cfg(feature = "iso20022")]
- build_proto("iso20022", Entity::ISO2022)?;
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
+ let mut protos: Vec<&'static str> = vec![];
+
+ #[cfg(feature = "message")]
+ protos.extend(Entity::ISO2022.protos());
+
+ #[cfg(feature = "pseudonyms")]
+ protos.extend(Entity::Pseudonyms.protos());
+
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
+ build_proto(&protos)?;
Ok(())
}
-#[cfg(feature = "iso20022")]
-fn build_proto(package: &str, entity: Entity) -> Result<(), Box<dyn std::error::Error>> {
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
+fn build_proto(protos: &[&str]) -> Result<(), Box<dyn std::error::Error>> {
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
- let config = tonic_prost_build::configure()
- .server_mod_attribute(
- package,
- format!("#[cfg(feature = \"rpc-server-{package}\")] #[cfg_attr(docsrs, doc(cfg(feature = \"rpc-server-{package}\")))]"),
- )
- .client_mod_attribute(
- package,
- format!("#[cfg(feature = \"rpc-client-{package}\")] #[cfg_attr(docsrs, doc(cfg(feature = \"rpc-client-{package}\")))]"),
- );
+ let config = tonic_prost_build::configure();
#[cfg(feature = "serde")]
let config = add_serde(config);
@@ -59,26 +79,18 @@ fn build_proto(package: &str, entity: Entity) -> Result<(), Box<dyn std::error::
let config = add_openapi(config);
config
- .file_descriptor_set_path(out_dir.join(format!("{package}_descriptor.bin")))
- .server_mod_attribute(
- package,
- format!("#[cfg(feature = \"rpc-server-{package}\")] #[cfg_attr(docsrs, doc(cfg(feature = \"rpc-server-{package}\")))]"),
- )
- .client_mod_attribute(
- package,
- format!("#[cfg(feature = \"rpc-client-{package}\")] #[cfg_attr(docsrs, doc(cfg(feature = \"rpc-client-{package}\")))]"),
- )
+ .file_descriptor_set_path(out_dir.join("warden_descriptor.bin"))
.protoc_arg("-I=../..")
.compile_well_known_types(true)
.compile_protos(
- &entity.protos(),
- &["../../proto/googleapis", "../../proto"], // specify the root location to search proto dependencies
+ protos,
+ &["../../proto", "../../proto/googleapis"], // specify the root location to search proto dependencies
)?;
Ok(())
}
-#[cfg(all(feature = "serde", feature = "iso20022"))]
+#[cfg(all(feature = "serde", any(feature = "pseudonyms", feature = "message")))]
fn add_serde(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder {
let config = config.type_attribute(
".",
@@ -94,7 +106,7 @@ fn add_serde(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder {
config
}
-#[cfg(all(feature = "openapi", feature = "iso20022"))]
+#[cfg(all(feature = "openapi", any(feature = "message", feature = "pseudonyms")))]
fn add_openapi(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder {
config.type_attribute(".", "#[derive(utoipa::ToSchema)]")
}
diff --git a/lib/warden-core/src/google/parser.rs b/lib/warden-core/src/google/parser.rs
index f2fe5bc..7f160a3 100644
--- a/lib/warden-core/src/google/parser.rs
+++ b/lib/warden-core/src/google/parser.rs
@@ -1,4 +1,5 @@
#[cfg(feature = "time")]
mod dt;
+#[cfg(feature = "pseudonyms")]
mod money;
diff --git a/lib/warden-core/src/google/parser/dt.rs b/lib/warden-core/src/google/parser/dt.rs
index ced6f12..0e57833 100644
--- a/lib/warden-core/src/google/parser/dt.rs
+++ b/lib/warden-core/src/google/parser/dt.rs
@@ -1,100 +1,107 @@
-use crate::google::{protobuf::Timestamp, r#type::Date};
+use crate::google::protobuf::Timestamp;
-impl From<time::OffsetDateTime> for Date {
- fn from(dt: time::OffsetDateTime) -> Self {
- Self {
- year: dt.year(),
- month: dt.month() as i32,
- day: dt.day() as i32,
+#[cfg(feature = "message")]
+mod date {
+ use super::*;
+ use crate::google::r#type::Date;
+
+ impl From<time::OffsetDateTime> for Date {
+ fn from(dt: time::OffsetDateTime) -> Self {
+ Self {
+ year: dt.year(),
+ month: dt.month() as i32,
+ day: dt.day() as i32,
+ }
}
}
-}
-impl From<time::Date> for Date {
- fn from(value: time::Date) -> Self {
- Self {
- year: value.year(),
- month: value.month() as i32,
- day: value.day() as i32,
+ impl From<time::Date> for Date {
+ fn from(value: time::Date) -> Self {
+ Self {
+ year: value.year(),
+ month: value.month() as i32,
+ day: value.day() as i32,
+ }
}
}
-}
-impl TryFrom<Date> for time::Date {
- type Error = time::Error;
+ impl TryFrom<Date> for time::Date {
+ type Error = time::Error;
- fn try_from(value: Date) -> Result<Self, Self::Error> {
- Ok(Self::from_calendar_date(
- value.year,
- time::Month::try_from(value.month as u8)?,
- value.day as u8,
- )?)
+ fn try_from(value: Date) -> Result<Self, Self::Error> {
+ Ok(Self::from_calendar_date(
+ value.year,
+ time::Month::try_from(value.month as u8)?,
+ value.day as u8,
+ )?)
+ }
}
-}
-impl std::str::FromStr for Date {
- type Err = time::Error;
+ impl std::str::FromStr for Date {
+ type Err = time::Error;
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- let date = time::OffsetDateTime::parse(s, &time::format_description::well_known::Rfc3339)
- .map(Date::from);
-
- match date {
- Ok(dt) => Ok(dt),
- Err(_e) => {
- let my_format = time::macros::format_description!("[year]-[month]-[day]");
- let date = time::Date::parse(s, &my_format)?;
- Ok(Date::from(date))
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let date =
+ time::OffsetDateTime::parse(s, &time::format_description::well_known::Rfc3339)
+ .map(Date::from);
+
+ match date {
+ Ok(dt) => Ok(dt),
+ Err(_e) => {
+ let my_format = time::macros::format_description!("[year]-[month]-[day]");
+ let date = time::Date::parse(s, &my_format)?;
+ Ok(Date::from(date))
+ }
}
}
}
-}
-impl TryFrom<String> for Date {
- type Error = time::Error;
+ impl TryFrom<String> for Date {
+ type Error = time::Error;
- fn try_from(value: String) -> Result<Self, Self::Error> {
- <Date as std::str::FromStr>::from_str(&value)
+ fn try_from(value: String) -> Result<Self, Self::Error> {
+ <Date as std::str::FromStr>::from_str(&value)
+ }
}
-}
-
-impl TryFrom<DateItem> for Date {
- type Error = time::Error;
- fn try_from(value: DateItem) -> Result<Self, Self::Error> {
- match value {
- DateItem::String(ref string) => <Date as std::str::FromStr>::from_str(string),
- #[cfg(feature = "iso20022")]
- DateItem::Date { year, month, day } => Ok(Date { year, month, day }),
- DateItem::Timestamp { seconds, nanos } => {
- let odt = time::OffsetDateTime::try_from(crate::google::protobuf::Timestamp {
- seconds,
- nanos,
- })?;
- Ok(Self {
- year: odt.year(),
- month: odt.month() as i32,
- day: odt.day() as i32,
- })
+ impl TryFrom<DateItem> for Date {
+ type Error = time::Error;
+
+ fn try_from(value: DateItem) -> Result<Self, Self::Error> {
+ match value {
+ DateItem::String(ref string) => <Date as std::str::FromStr>::from_str(string),
+ #[cfg(feature = "message")]
+ DateItem::Date { year, month, day } => Ok(Date { year, month, day }),
+ DateItem::Timestamp { seconds, nanos } => {
+ let odt = time::OffsetDateTime::try_from(crate::google::protobuf::Timestamp {
+ seconds,
+ nanos,
+ })?;
+ Ok(Self {
+ year: odt.year(),
+ month: odt.month() as i32,
+ day: odt.day() as i32,
+ })
+ }
}
}
}
-}
-impl From<Date> for String {
- fn from(value: Date) -> Self {
- let prepend = |value: i32| -> String {
- match value.lt(&10) {
- true => format!("0{}", value),
- false => value.to_string(),
- }
- };
- format!(
- "{}-{}-{}",
- value.year,
- prepend(value.month),
- prepend(value.day),
- )
+ impl From<Date> for String {
+ fn from(value: Date) -> Self {
+ let prepend = |value: i32| -> String {
+ match value.lt(&10) {
+ true => format!("0{}", value),
+ false => value.to_string(),
+ }
+ };
+ format!(
+ "{}-{}-{}",
+ value.year,
+ prepend(value.month),
+ prepend(value.day),
+ )
+ }
}
}
@@ -108,7 +115,7 @@ pub enum DateItem {
/// ts
Timestamp { seconds: i64, nanos: i32 },
/// date
- #[cfg(feature = "iso20022")]
+ #[cfg(feature = "message")]
Date { year: i32, month: i32, day: i32 },
}
@@ -118,7 +125,7 @@ impl TryFrom<DateItem> for Timestamp {
fn try_from(value: DateItem) -> Result<Self, Self::Error> {
match value {
DateItem::String(ref string) => <Timestamp as std::str::FromStr>::from_str(string),
- #[cfg(feature = "iso20022")]
+ #[cfg(feature = "message")]
DateItem::Date { year, month, day } => {
let date = time::Date::try_from(crate::google::r#type::Date { year, month, day })?;
let time = time::Time::MIDNIGHT;
diff --git a/lib/warden-core/src/iso20022.rs b/lib/warden-core/src/iso20022.rs
index 78365a9..436ee2f 100644
--- a/lib/warden-core/src/iso20022.rs
+++ b/lib/warden-core/src/iso20022.rs
@@ -17,10 +17,6 @@ impl std::fmt::Display for TransactionType {
}
}
-/// Pacs008 file descriptor
-pub const ISO20022_FILE_DESCRIPTOR_SET: &[u8] =
- tonic::include_file_descriptor_set!("iso20022_descriptor");
-
/// pacs.008.001.12
pub mod pacs008 {
tonic::include_proto!("iso20022.pacs008");
diff --git a/lib/warden-core/src/lib.rs b/lib/warden-core/src/lib.rs
index 19d02f3..53f25f2 100644
--- a/lib/warden-core/src/lib.rs
+++ b/lib/warden-core/src/lib.rs
@@ -6,17 +6,27 @@
missing_debug_implementations
)]
+/// Type file descriptor
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
+pub const FILE_DESCRIPTOR_SET: &[u8] =
+ tonic::include_file_descriptor_set!("warden_descriptor");
+
/// Google well known types
#[allow(missing_docs)]
-#[cfg(feature = "iso20022")]
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
pub mod google;
/// ISO20022 messages
#[allow(missing_docs)]
-#[cfg(feature = "iso20022")]
+#[cfg(feature = "message")]
pub mod iso20022;
/// Message in transit
#[allow(missing_docs)]
-#[cfg(feature = "iso20022")]
+#[cfg(feature = "message")]
pub mod message;
+
+/// Pseudonyms
+#[allow(missing_docs)]
+#[cfg(feature = "pseudonyms")]
+pub mod pseudonyms;
diff --git a/lib/warden-core/src/pseudonyms.rs b/lib/warden-core/src/pseudonyms.rs
new file mode 100644
index 0000000..1d36074
--- /dev/null
+++ b/lib/warden-core/src/pseudonyms.rs
@@ -0,0 +1,15 @@
+pub mod account {
+ tonic::include_proto!("pseudonyms.account");
+}
+
+pub mod entity {
+ tonic::include_proto!("pseudonyms.entity");
+}
+
+pub mod transaction_relationship {
+ tonic::include_proto!("pseudonyms.transaction_relationship");
+}
+
+pub mod account_holder {
+ tonic::include_proto!("pseudonyms.account_holder");
+}
diff --git a/proto/pseudonyms/account.proto b/proto/pseudonyms/account.proto
new file mode 100644
index 0000000..bdca80c
--- /dev/null
+++ b/proto/pseudonyms/account.proto
@@ -0,0 +1,15 @@
+syntax = "proto3";
+
+package pseudonyms.account;
+
+import "google/protobuf/timestamp.proto";
+
+message Account {
+ string id = 1;
+}
+
+message CreateAccount {
+ string id = 1;
+ string account_id = 2;
+ google.protobuf.Timestamp cre_dt_tm = 3;
+}
diff --git a/proto/pseudonyms/account_holder.proto b/proto/pseudonyms/account_holder.proto
new file mode 100644
index 0000000..80c7557
--- /dev/null
+++ b/proto/pseudonyms/account_holder.proto
@@ -0,0 +1,11 @@
+syntax = "proto3";
+
+package pseudonyms.account_holder;
+
+import "google/protobuf/timestamp.proto";
+
+message AccountHolder {
+ string entity_id = 1;
+ string account_id = 2;
+ google.protobuf.Timestamp cre_dt_tm = 3;
+}
diff --git a/proto/pseudonyms/entity.proto b/proto/pseudonyms/entity.proto
new file mode 100644
index 0000000..d656193
--- /dev/null
+++ b/proto/pseudonyms/entity.proto
@@ -0,0 +1,10 @@
+syntax = "proto3";
+
+package pseudonyms.entity;
+
+import "google/protobuf/timestamp.proto";
+
+message Entity {
+ string id = 1;
+ google.protobuf.Timestamp cre_dt_tm = 2;
+}
diff --git a/proto/pseudonyms/transaction_relationship.proto b/proto/pseudonyms/transaction_relationship.proto
new file mode 100644
index 0000000..cd8bae5
--- /dev/null
+++ b/proto/pseudonyms/transaction_relationship.proto
@@ -0,0 +1,34 @@
+syntax = "proto3";
+
+package pseudonyms.transaction_relationship;
+
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/empty.proto";
+import "google/type/money.proto";
+import "google/type/latlng.proto";
+
+// TransactionRelationship message definition
+message TransactionRelationship {
+ string from = 1;
+ string to = 2;
+ optional google.type.Money amt = 3;
+ google.protobuf.Timestamp cre_dt_tm = 4;
+ string end_to_end_id = 5;
+ optional google.type.LatLng latlng = 6;
+ string msg_id = 7;
+ string pmt_inf_id = 8;
+ string tx_tp = 9;
+ optional string tx_sts = 10;
+}
+
+message CreatePseudonymRequest {
+ TransactionRelationship transaction_relationship = 1;
+ string debtor_id = 2;
+ string debtor_account_id = 3;
+ string creditor_id = 4;
+ string creditor_account_id = 5;
+}
+
+service MutatePseudonym {
+ rpc CreatePseudonym(CreatePseudonymRequest) returns (google.protobuf.Empty);
+}