aboutsummaryrefslogtreecommitdiffstats
path: root/lib/warden-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/warden-core/src')
-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
5 files changed, 113 insertions, 84 deletions
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");
+}