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

Implement deployer functions that return the deployed contract id. #1086

Merged
merged 3 commits into from
Sep 15, 2023
Merged
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
24 changes: 18 additions & 6 deletions soroban-sdk/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
//! # pub fn f(env: Env, wasm_hash: BytesN<32>) {
//! # let salt = [0u8; 32];
//! # let deployer = env.deployer().with_current_contract(salt);
//! # // Deployed contract address is deterministic and can be accessed
//! # // before deploying the contract.
//! # let _ = deployer.deployed_address();
//! # let contract_address = deployer.deploy(wasm_hash);
//! # }
//! # }
Expand Down Expand Up @@ -150,10 +153,14 @@ pub struct DeployerWithAddress {

impl DeployerWithAddress {
/// Return the address of the contract defined by the deployer.
#[doc(hidden)]
/// Returns what the address of the contract will be once deployed.
///
/// This function can be called at anytime, before or after the contract is
/// deployed, because contract addresses are deterministic.
pub fn deployed_address(&self) -> Address {
todo!()
self.env
.get_contract_id(self.address.to_object(), self.salt.to_object())
.unwrap_infallible()
.into_val(&self.env)
}

/// Deploy a contract that uses Wasm executable with provided hash.
Expand Down Expand Up @@ -182,9 +189,14 @@ pub struct DeployerWithAsset {

impl DeployerWithAsset {
/// Return the address of the contract defined by the deployer.
#[doc(hidden)]
pub fn contract_address(&self) -> Address {
todo!()
///
/// This function can be called at anytime, before or after the contract is
/// deployed, because contract addresses are deterministic.
pub fn deployed_address(&self) -> Address {
self.env
.get_asset_contract_id(self.serialized_asset.to_object())
.unwrap_infallible()
.into_val(&self.env)
}

pub fn deploy(&self) -> Address {
Expand Down