Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion to base64 string #35

Open
wants to merge 2 commits into
base: polkadot-v1.1.0
Choose a base branch
from

Conversation

b-yap
Copy link
Contributor

@b-yap b-yap commented Oct 15, 2024

Move implementation of
https://github.com/pendulum-chain/spacewalk/blob/7c7989875e95e1cfe3b0aeba9bb6af01d9e33e58/clients/stellar-relay-lib/src/connection/helper.rs#L39-L42

pub fn to_base64_xdr_string<T: XdrCodec>(msg: &T) -> String {
	let xdr = msg.to_base64_xdr();
	String::from_utf8(xdr.clone()).unwrap_or(format!("{:?}", xdr))
}

to this repo

Cleanup of pendulum-chain/spacewalk#545

@b-yap b-yap requested a review from a team October 15, 2024 15:30
Copy link
Contributor

@gianfra-t gianfra-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@TorstenStueber TorstenStueber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @b-yap, just one question.

src/utils/std.rs Outdated
impl <T: XdrCodec> StellarTypeToBase64String for T {
fn as_base64_encoded_string(&self) -> String {
let xdr = self.to_base64_xdr();
String::from_utf8(xdr.clone()).unwrap_or(format!("{:?}", xdr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the or case ever happen? I think we can prove that the unwrap can never fail (something the compiler can't guarantee) because to_base64_xdr will always return an ASCII string, which is always valid utf8.

That way we should be able to safely use unrwap and we would not need to add the std::format or alloc::format dependency. Or is this bad practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the or case ever happen?

True, it will not.

I have reverted std.rs file and use unwrap().
I do not think it is bad practice, as long as explained well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants