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

Re-export initialize_contract function #1077

Merged
merged 4 commits into from
Feb 17, 2022
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
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
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
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