Skip to content

Commit

Permalink
Re-export initialize_contract function (#1077)
Browse files Browse the repository at this point in the history
* Re-export the `initialize_contract` function

* Use re-exported version in example contracts

* Re-export `initialize_contract` from `utils` module

* Change remaining usage of `ink_lang::codegen` to `ink_lang::utils`
  • Loading branch information
HCastano committed Feb 17, 2022
1 parent d35b3d7 commit e345679
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions crates/lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub mod result_info;
#[cfg_attr(not(feature = "show-codegen-docs"), doc(hidden))]
pub mod codegen;

/// Utility functions for contract development.
pub mod utils {
// We want to expose this function without making users go through
// the `codgen` module
pub use super::codegen::initialize_contract;
}

pub mod reflect;

mod chain_extension;
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/tests/ui/contract/pass/example-erc20-works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod erc20 {
/// Creates a new ERC-20 contract with the specified initial supply.
#[ink(constructor)]
pub fn new(initial_supply: Balance) -> Self {
ink_lang::codegen::initialize_contract(|contract| {
ink_lang::utils::initialize_contract(|contract| {
Self::new_init(contract, initial_supply)
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/tests/ui/contract/pass/example-erc721-works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod erc721 {
pub fn new() -> Self {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
ink_lang::codegen::initialize_contract(|_| {})
ink_lang::utils::initialize_contract(|_| {})
}

/// Returns the balance of the owner.
Expand Down
4 changes: 3 additions & 1 deletion examples/dns/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ mod dns {
/// Creates a new domain name service contract.
#[ink(constructor)]
pub fn new() -> Self {
ink_lang::codegen::initialize_contract(|contract: &mut Self| {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
ink_lang::utils::initialize_contract(|contract: &mut Self| {
contract.default_address = Default::default();
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/erc1155/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ mod erc1155 {
// `Mapping`s of our contract.
//
// Not that `token_id_nonce` will be initialized to its `Default` value.
ink_lang::codegen::initialize_contract(|_| {})
ink_lang::utils::initialize_contract(|_| {})
}

/// Create the initial supply for a token.
Expand Down
4 changes: 3 additions & 1 deletion examples/erc20/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ mod erc20 {
/// Creates a new ERC-20 contract with the specified initial supply.
#[ink(constructor)]
pub fn new(initial_supply: Balance) -> Self {
ink_lang::codegen::initialize_contract(|contract| {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
ink_lang::utils::initialize_contract(|contract| {
Self::new_init(contract, initial_supply)
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/erc721/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod erc721 {
pub fn new() -> Self {
// This call is required in order to correctly initialize the
// `Mapping`s of our contract.
ink_lang::codegen::initialize_contract(|_| {})
ink_lang::utils::initialize_contract(|_| {})
}

/// Returns the balance of the owner.
Expand Down
2 changes: 1 addition & 1 deletion examples/multisig/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ mod multisig {
/// If `requirement` violates our invariant.
#[ink(constructor)]
pub fn new(requirement: u32, mut owners: Vec<AccountId>) -> Self {
ink_lang::codegen::initialize_contract(|contract: &mut Self| {
ink_lang::utils::initialize_contract(|contract: &mut Self| {
owners.sort_unstable();
owners.dedup();
ensure_requirement_is_valid(owners.len() as u32, requirement);
Expand Down
2 changes: 1 addition & 1 deletion examples/trait-erc20/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod erc20 {
/// Creates a new ERC-20 contract with the specified initial supply.
#[ink(constructor)]
pub fn new(initial_supply: Balance) -> Self {
ink_lang::codegen::initialize_contract(|contract| {
ink_lang::utils::initialize_contract(|contract| {
Self::new_init(contract, initial_supply)
})
}
Expand Down

0 comments on commit e345679

Please sign in to comment.