Skip to content

Commit bda0daa

Browse files
authored
Merge pull request #48 from blockscout/ll/add-alloy
feat: add alloy types
2 parents 2858b0c + e62e491 commit bda0daa

File tree

13 files changed

+87
-15
lines changed

13 files changed

+87
-15
lines changed

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ members = [
99
]
1010

1111
[workspace.package]
12-
version = "0.3.0"
12+
version = "0.3.1"
1313
edition = "2021"
1414
license = "MIT"
1515
repository = "https://github.com/blockscout/actix-prost"
1616
exclude = ["tests"]
1717

1818
[workspace.dependencies]
19-
actix-prost = { version = "0.3.0", path = "actix-prost" }
20-
actix-prost-build = { version = "0.3.0", path = "actix-prost-build" }
21-
actix-prost-macros = { version = "0.3.0", path = "actix-prost-macros" }
22-
convert-trait = { version = "0.3.0", path = "actix-prost-convert-trait", package = "actix-prost-convert-trait" }
19+
actix-prost = { version = "0.3.1", path = "actix-prost" }
20+
actix-prost-build = { version = "0.3.1", path = "actix-prost-build" }
21+
actix-prost-macros = { version = "0.3.1", path = "actix-prost-macros" }
22+
convert-trait = { version = "0.3.1", path = "actix-prost-convert-trait", package = "actix-prost-convert-trait" }
2323

2424
actix-http = { version = "3" }
2525
actix-web = { version = "4" }
2626
async-trait = { version = "0.1" }
2727
bytes = { version = "1.9" }
2828
ethers = { version = "2.0.14" }
29+
alloy = { version = "1.1.3" }
2930
ethers-core = { version = "2.0.14" }
3031
hex = { version = "0.4" }
3132
http = { version = "1.2" }

actix-prost-convert-trait/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ url = { workspace = true, optional = true }
1717
chrono = { version = "0.4", features = ["serde"], optional = true }
1818
uuid = { version = "1.0", features = ["serde"], optional = true }
1919
rust_decimal = { version = "1.32", features = ["serde"], optional = true }
20+
alloy = { version = "1.1.3", features = [], optional = true, default-features = false}
2021

2122
[dev-dependencies]
2223
pretty_assertions = { workspace = true }
@@ -26,6 +27,7 @@ default = [ "conv-full" ]
2627
conv-full = [
2728
"conv-bytes",
2829
"conv-address",
30+
"conv-hash",
2931
"conv-url",
3032
"conv-datetime",
3133
"conv-uuid",
@@ -35,7 +37,8 @@ conv-full = [
3537
"conv-decimal"
3638
]
3739
conv-bytes = [ "dep:bytes", "dep:hex" ]
38-
conv-address = [ "dep:ethers-core" ]
40+
conv-address = [ "dep:ethers-core", "dep:alloy" ]
41+
conv-hash = [ "dep:alloy" ]
3942
conv-url = [ "dep:url" ]
4043
conv-datetime = [ "dep:chrono" ]
4144
conv-uuid = [ "dep:uuid" ]

actix-prost-convert-trait/src/address.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{impl_try_convert_from_string, TryConvert};
2+
use alloy::primitives::Address as AlloyAddress;
23
use ethers_core::{types::Address, utils::to_checksum};
34

45
impl_try_convert_from_string!(Address);
@@ -9,6 +10,14 @@ impl TryConvert<Address> for String {
910
}
1011
}
1112

13+
impl_try_convert_from_string!(AlloyAddress);
14+
15+
impl TryConvert<AlloyAddress> for String {
16+
fn try_convert(input: AlloyAddress) -> Result<Self, String> {
17+
Ok(input.to_checksum(None))
18+
}
19+
}
20+
1221
#[cfg(test)]
1322
mod tests {
1423
use super::*;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use crate::{impl_try_convert_from_string, impl_try_convert_to_string};
2+
use alloy::primitives::B256;
3+
4+
impl_try_convert_from_string!(B256);
5+
impl_try_convert_to_string!(B256);

actix-prost-convert-trait/src/impls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ impl<K: std::cmp::Ord, T, R: TryConvert<T>> TryConvert<BTreeMap<K, T>> for BTree
4343
#[macro_export]
4444
macro_rules! impl_try_convert_from_string {
4545
($type:ty) => {
46-
impl_try_convert_from_string!($type, stringify!($type));
46+
$crate::impl_try_convert_from_string!($type, stringify!($type));
4747
};
4848
($type:ty, $type_name:expr) => {
49-
impl TryConvert<String> for $type {
49+
impl $crate::TryConvert<String> for $type {
5050
fn try_convert(value: String) -> Result<Self, String> {
5151
value.parse().map_err(|e| {
5252
$crate::failed_to_parse_error_message_with_description(&value, $type_name, e)
@@ -59,7 +59,7 @@ macro_rules! impl_try_convert_from_string {
5959
#[macro_export]
6060
macro_rules! impl_try_convert_to_string {
6161
($type:ty) => {
62-
impl TryConvert<$type> for String {
62+
impl $crate::TryConvert<$type> for String {
6363
fn try_convert(value: $type) -> Result<Self, String> {
6464
Ok(value.to_string())
6565
}

actix-prost-convert-trait/src/ip.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{impl_try_convert_from_string, impl_try_convert_to_string, TryConvert};
1+
use crate::{impl_try_convert_from_string, impl_try_convert_to_string};
22
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
33

44
impl_try_convert_from_string!(IpAddr);
@@ -13,6 +13,7 @@ impl_try_convert_to_string!(Ipv6Addr);
1313
#[cfg(test)]
1414
mod tests {
1515
use super::*;
16+
use crate::TryConvert;
1617

1718
#[test]
1819
fn test_conversion_ip() {

actix-prost-convert-trait/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ mod impls;
55
#[cfg(feature = "conv-address")]
66
mod address;
77

8+
#[cfg(feature = "conv-hash")]
9+
mod hash;
10+
811
#[cfg(feature = "conv-bytes")]
912
mod bytes;
1013

actix-prost-convert-trait/src/url.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{impl_try_convert_from_string, impl_try_convert_to_string, TryConvert};
1+
use crate::{impl_try_convert_from_string, impl_try_convert_to_string};
22
use url::Url;
33

44
impl_try_convert_from_string!(Url);
@@ -7,6 +7,7 @@ impl_try_convert_to_string!(Url);
77
#[cfg(test)]
88
mod tests {
99
use super::*;
10+
use crate::TryConvert;
1011

1112
#[test]
1213
fn test_conversion_url() {

actix-prost-convert-trait/src/uuid.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{impl_try_convert_from_string, impl_try_convert_to_string, TryConvert};
1+
use crate::{impl_try_convert_from_string, impl_try_convert_to_string};
22
use uuid::Uuid;
33

44
impl_try_convert_from_string!(Uuid);
@@ -7,6 +7,7 @@ impl_try_convert_to_string!(Uuid);
77
#[cfg(test)]
88
mod tests {
99
use super::*;
10+
use crate::TryConvert;
1011

1112
#[test]
1213
fn test_conversion_uuid() {

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async-trait = { workspace = true }
1616
actix-web = { workspace = true }
1717
convert-trait = { workspace = true }
1818
ethers = { workspace = true }
19+
alloy = { workspace = true, default-features = false }
1920
prost = { workspace = true }
2021
serde = { workspace = true, features = [ "derive" ] }
2122
serde_json = { workspace = true }

0 commit comments

Comments
 (0)