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

Add Address::from_str #1342

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions soroban-sdk/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ impl Address {
self.env.require_auth(self);
}

/// Creates an `Address` corresponding to the provided Stellar strkey.
///
/// The only supported strkey types are account keys (`G...`) and contract keys (`C...`). Any
/// other valid or invalid strkey will cause this to panic.
///
/// Prefer using the `Address` directly as input or output argument. Only
/// use this in special cases when addresses need to be shared between
/// different environments (e.g. different chains).
pub fn from_str(env: &Env, strkey: &str) -> Address {
Address::from_string(&String::from_str(env, strkey))
}

/// Creates an `Address` corresponding to the provided Stellar strkey.
///
/// The only supported strkey types are account keys (`G...`) and contract keys (`C...`). Any
Expand Down
13 changes: 13 additions & 0 deletions soroban-sdk/src/tests/address.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
use crate::{Address, Bytes, Env, String, TryIntoVal};

#[test]
fn test_account_address_str_conversions() {
let env = Env::default();

let strkey = "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ";

let address = Address::from_str(&env, &strkey);
assert_eq!(
address.to_string().to_string(),
"GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"
);
}

#[test]
fn test_account_address_conversions() {
let env = Env::default();
Expand Down
Loading