From 008d48f00109d2962dcd64de15575d78862e0e80 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 9 Dec 2021 17:15:55 -0500 Subject: [PATCH 1/4] Re-export the `initialize_contract` function --- crates/lang/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lang/src/lib.rs b/crates/lang/src/lib.rs index bbc261dcc8e..9bc6320ef62 100644 --- a/crates/lang/src/lib.rs +++ b/crates/lang/src/lib.rs @@ -20,6 +20,7 @@ pub mod result_info; #[cfg_attr(not(feature = "show-codegen-docs"), doc(hidden))] pub mod codegen; +pub use codegen::initialize_contract; pub mod reflect; From d146eb0f89c1aa37bade29a32d97b3af950629a6 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 9 Dec 2021 17:16:11 -0500 Subject: [PATCH 2/4] Use re-exported version in example contracts --- examples/dns/lib.rs | 4 +++- examples/erc1155/lib.rs | 2 +- examples/erc20/lib.rs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/dns/lib.rs b/examples/dns/lib.rs index 80342142ead..7bcb83f5f5d 100644 --- a/examples/dns/lib.rs +++ b/examples/dns/lib.rs @@ -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::initialize_contract(|contract: &mut Self| { contract.default_address = Default::default(); }) } diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index 7360d0ae654..f448a0bfbc0 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -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::initialize_contract(|_| {}) } /// Create the initial supply for a token. diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index a767914fdf9..f9e303b2b45 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -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::initialize_contract(|contract| { Self::new_init(contract, initial_supply) }) } From 0a2c7cf98d62fe941ac9853ff195f8642a89d149 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Fri, 10 Dec 2021 17:47:33 -0500 Subject: [PATCH 3/4] Re-export `initialize_contract` from `utils` module --- crates/lang/src/lib.rs | 8 +++++++- examples/dns/lib.rs | 2 +- examples/erc1155/lib.rs | 2 +- examples/erc20/lib.rs | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/lang/src/lib.rs b/crates/lang/src/lib.rs index 9bc6320ef62..b65981a7189 100644 --- a/crates/lang/src/lib.rs +++ b/crates/lang/src/lib.rs @@ -20,7 +20,13 @@ pub mod result_info; #[cfg_attr(not(feature = "show-codegen-docs"), doc(hidden))] pub mod codegen; -pub use codegen::initialize_contract; + +/// 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; diff --git a/examples/dns/lib.rs b/examples/dns/lib.rs index 7bcb83f5f5d..7dfe29cd1eb 100644 --- a/examples/dns/lib.rs +++ b/examples/dns/lib.rs @@ -87,7 +87,7 @@ mod dns { pub fn new() -> Self { // This call is required in order to correctly initialize the // `Mapping`s of our contract. - ink_lang::initialize_contract(|contract: &mut Self| { + ink_lang::utils::initialize_contract(|contract: &mut Self| { contract.default_address = Default::default(); }) } diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index f448a0bfbc0..4404ec4de15 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -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::initialize_contract(|_| {}) + ink_lang::utils::initialize_contract(|_| {}) } /// Create the initial supply for a token. diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index f9e303b2b45..088f8bfcc0b 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -62,7 +62,7 @@ mod erc20 { pub fn new(initial_supply: Balance) -> Self { // This call is required in order to correctly initialize the // `Mapping`s of our contract. - ink_lang::initialize_contract(|contract| { + ink_lang::utils::initialize_contract(|contract| { Self::new_init(contract, initial_supply) }) } From 17fd88d92ca350f9df11dfb7a1919427b551949b Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 15 Feb 2022 11:26:45 -0700 Subject: [PATCH 4/4] Change remaining usage of `ink_lang::codegen` to `ink_lang::utils` --- crates/lang/tests/ui/contract/pass/example-erc20-works.rs | 2 +- crates/lang/tests/ui/contract/pass/example-erc721-works.rs | 2 +- examples/erc721/lib.rs | 2 +- examples/multisig/lib.rs | 2 +- examples/trait-erc20/lib.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/lang/tests/ui/contract/pass/example-erc20-works.rs b/crates/lang/tests/ui/contract/pass/example-erc20-works.rs index 2f5b96661e2..f1d50541ae6 100644 --- a/crates/lang/tests/ui/contract/pass/example-erc20-works.rs +++ b/crates/lang/tests/ui/contract/pass/example-erc20-works.rs @@ -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) }) } diff --git a/crates/lang/tests/ui/contract/pass/example-erc721-works.rs b/crates/lang/tests/ui/contract/pass/example-erc721-works.rs index f97a7e564aa..3e4c4fc3a7f 100644 --- a/crates/lang/tests/ui/contract/pass/example-erc721-works.rs +++ b/crates/lang/tests/ui/contract/pass/example-erc721-works.rs @@ -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. diff --git a/examples/erc721/lib.rs b/examples/erc721/lib.rs index 919937d80f4..44a4a803729 100644 --- a/examples/erc721/lib.rs +++ b/examples/erc721/lib.rs @@ -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. diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index cc2d4174733..abf63a5be54 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -281,7 +281,7 @@ mod multisig { /// If `requirement` violates our invariant. #[ink(constructor)] pub fn new(requirement: u32, mut owners: Vec) -> 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); diff --git a/examples/trait-erc20/lib.rs b/examples/trait-erc20/lib.rs index 66665fcf9d4..a3268c8a65f 100644 --- a/examples/trait-erc20/lib.rs +++ b/examples/trait-erc20/lib.rs @@ -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) }) }