@@ -4,6 +4,7 @@ use anyhow::anyhow;
44use bech32:: { Bech32 , Hrp } ;
55use serde:: { ser:: SerializeMap , Deserialize , Serializer } ;
66use serde_with:: { ser:: SerializeAsWrap , DeserializeAs , SerializeAs } ;
7+ use crate :: PoolId ;
78
89pub struct SerializeMapAs < KAs , VAs > ( std:: marker:: PhantomData < ( KAs , VAs ) > ) ;
910
@@ -60,7 +61,31 @@ impl HrpPrefix for AddrPrefix {
6061// Generic Bech32 converter with HRP parameter
6162pub struct DisplayFromBech32 < PREFIX : HrpPrefix > ( PhantomData < PREFIX > ) ;
6263
63- // Serialization implementation
64+ // PoolID serialization implementation
65+ impl SerializeAs < PoolId > for DisplayFromBech32 < PoolPrefix >
66+ {
67+ fn serialize_as < S > ( source : & PoolId , serializer : S ) -> Result < S :: Ok , S :: Error >
68+ where
69+ S : Serializer ,
70+ {
71+ let bech32_string = source. to_bech32 ( ) . map_err ( serde:: ser:: Error :: custom) ?;
72+ serializer. serialize_str ( & bech32_string)
73+ }
74+ }
75+
76+ // PoolID deserialization implementation
77+ impl < ' de > DeserializeAs < ' de , PoolId > for DisplayFromBech32 < PoolPrefix >
78+ {
79+ fn deserialize_as < D > ( deserializer : D ) -> Result < PoolId , D :: Error >
80+ where
81+ D : serde:: de:: Deserializer < ' de > ,
82+ {
83+ let s = String :: deserialize ( deserializer) ?;
84+ PoolId :: from_bech32 ( & s) . map_err ( serde:: de:: Error :: custom)
85+ }
86+ }
87+
88+ // Vec<u8> serialization implementation
6489impl < PREFIX > SerializeAs < Vec < u8 > > for DisplayFromBech32 < PREFIX >
6590where
6691 PREFIX : HrpPrefix ,
0 commit comments