Skip to content

Commit 0e07326

Browse files
Make Address::from_contract_id pub (#989)
### What Make Address::from_contract_id public and accessible to contracts. ### Why I recently hid the function because it presents some problems and constraints if used in contracts. From an portability point-of-view to be able to run a contract already built on multiple networks contracts would not have any hardcoded global state. However @orbitlens pointed out that from an optimization standpoint it may be preferred to have global state hardcoded even if that means recompiling the contract for each network it is deployed on, or for each specific deployment. The why is because no rent payments are required on the additional data entries, and that there may be some savings in not having to load a storage ledger entry. We haven't yet done the work to confirm if it is indeed cheaper, but it seems reasonable not to block developers from trying out different workflows. The SDK doesn't need to be strongly opinionated on everything, and this is an area where it feels like the SDK might be being too parental. Discussion about this occurred on Discord at: https://discord.com/channels/897514728459468821/1118888566349631561/1119051351528321054 ### Merging This change is intended to be merged to `main`, and then backported into a patch release based on the most recent release so that it can be enjoyed today. (cherry picked from commit 6d4b0b5)
1 parent 1eefa1e commit 0e07326

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

soroban-sdk/src/address.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ impl Address {
236236
/// Prefer using the `Address` directly as input or output argument. Only
237237
/// use this in special cases, for example to get an Address of a freshly
238238
/// deployed contract.
239-
pub(crate) fn from_contract_id(contract_id: &BytesN<32>) -> Self {
239+
///
240+
/// TODO: Replace this function in its pub form with a function that accepts
241+
/// a strkey instead. Dependent on https://github.com/stellar/rs-stellar-strkey/issues/56.
242+
pub fn from_contract_id(contract_id: &BytesN<32>) -> Self {
240243
let env = contract_id.env();
241244
unsafe {
242245
Self::unchecked_new(
@@ -310,10 +313,6 @@ impl crate::testutils::Address for Address {
310313
Self::try_from_val(env, &sc_addr).unwrap()
311314
}
312315

313-
fn from_contract_id(contract_id: &crate::BytesN<32>) -> crate::Address {
314-
Self::from_contract_id(contract_id)
315-
}
316-
317316
fn contract_id(&self) -> crate::BytesN<32> {
318317
self.contract_id()
319318
}

soroban-sdk/src/testutils.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ pub trait Address {
180180
/// the underlying Address value.
181181
fn random(env: &Env) -> crate::Address;
182182

183-
/// Creates an `Address` corresponding to the provided contract identifier.
184-
fn from_contract_id(contract_id: &crate::BytesN<32>) -> crate::Address;
185-
186183
/// Get the contract ID of an Address as a BytesN<32>.
187184
///
188185
/// ### Panics

0 commit comments

Comments
 (0)