Skip to content

Commit

Permalink
Merge branch 'polkadot-v1.1.0' into polkadot-v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gianfra-t committed Nov 19, 2024
2 parents 5d75308 + 6ff899a commit 6f2f05c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub use xdr::impls::transaction_set_type::*;
#[allow(unused_imports)]
pub use xdr::impls::error::*;

pub use utils::std::StellarTypeToString;
pub use utils::std::*;

pub use amount::*;
pub use binary::*;
Expand Down
15 changes: 15 additions & 0 deletions src/utils/std.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::lib::String;
use crate::XdrCodec;

/// A trait used to convert any Stellar specific type `T` as a String
/// This also immediately converts the standard Error to a user-defined Error `E`
Expand All @@ -9,3 +10,17 @@ use crate::lib::String;
pub trait StellarTypeToString<T, E: From<sp_std::str::Utf8Error>> {
fn as_encoded_string(&self) -> Result<String, E>;
}

/// A trait used to convert a structure into Base64 String
pub trait StellarTypeToBase64String {
/// returns a Base64 encoded String or a vec of bytes [xdr]
fn as_base64_encoded_string(&self) -> String;
}

impl <T: XdrCodec> StellarTypeToBase64String for T {
fn as_base64_encoded_string(&self) -> String {
let xdr = self.to_base64_xdr();
// safe to use `unwrap`, since `to_base64_xdr()` will always return a valid vec of
String::from_utf8(xdr.clone()).unwrap()
}
}

0 comments on commit 6f2f05c

Please sign in to comment.