Skip to content

Commit 7655375

Browse files
authored
Merge pull request #832 from CosmWasm/init-to-instantiate
Rename entry point init to instantiate
2 parents 30e48b8 + 7bd1889 commit 7655375

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+420
-354
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ and this project adheres to
6767

6868
- contracts: Rename `HandleMsg` to `ExecuteMsg`.
6969
- all: Rename `handle` entry point to `execute`.
70+
- all: Rename `init` entry point to `instantiate`.
7071
- all: Rename `system` entry point to `sudo`.
7172
- all: Drop support for Rust versions lower than 1.50.0.
7273
- all: The `query` enpoint is now optional. It is still highly recommended to

MIGRATING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ major releases of `cosmwasm`. Note that you can also view the
2323
# ...
2424
```
2525

26+
- Rename the `init` entry point to `instantiate`. Also, rename `InitMsg` to
27+
`InstantiateMsg`.
28+
2629
- Rename the `handle` entry point to `execute`. Also, rename `HandleMsg` to
2730
`ExecuteMsg`.
2831

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The required exports provided by the cosmwasm smart contract are:
101101
extern "C" fn allocate(size: usize) -> u32;
102102
extern "C" fn deallocate(pointer: u32);
103103

104-
extern "C" fn init(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -> u32;
104+
extern "C" fn instantiate(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -> u32;
105105
extern "C" fn execute(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -> u32;
106106
extern "C" fn query(env_ptr: u32, msg_ptr: u32) -> u32;
107107
extern "C" fn migrate(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -> u32;
@@ -110,7 +110,7 @@ extern "C" fn migrate(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -> u32;
110110
`allocate`/`deallocate` allow the host to manage data within the Wasm VM. If
111111
you're using Rust, you can implement them by simply
112112
[re-exporting them from cosmwasm::exports](https://github.com/CosmWasm/cosmwasm/blob/v0.6.3/contracts/hackatom/src/lib.rs#L5).
113-
`init`, `execute` and `query` must be defined by your contract.
113+
`instantiate`, `execute` and `query` must be defined by your contract.
114114

115115
### Imports
116116

@@ -194,16 +194,16 @@ pub struct Region {
194194
If you followed the [instructions above](#Creating), you should have a runable
195195
smart contract. You may notice that all of the Wasm exports are taken care of by
196196
`lib.rs`, which should shouldn't need to modify. What you need to do is simply
197-
look in `contract.rs` and implement `init` and `execute` functions, defining
198-
your custom `InitMsg` and `ExecuteMsg` structs for parsing your custom message
199-
types (as json):
197+
look in `contract.rs` and implement `instantiate` and `execute` functions,
198+
defining your custom `InstantiateMsg` and `ExecuteMsg` structs for parsing your
199+
custom message types (as json):
200200

201201
```rust
202-
pub fn init<S: Storage, A: Api, Q: Querier>(
202+
pub fn instantiate<S: Storage, A: Api, Q: Querier>(
203203
deps: &mut Deps<S, A, Q>,
204204
env: Env,
205205
info: MessageInfo,
206-
msg: InitMsg,
206+
msg: InstantiateMsg,
207207
) -> StdResult<Response> {}
208208

209209
pub fn execute<S: Storage, A: Api, Q: Querier>(

contracts/burner/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
This is a simple contract to demonstrate using migrations to shutdown (or
44
"burn") contracts using the migration feature added in CosmWasm 0.9.
55

6-
This contract cannot be installed directly (via `init`), but is only designed to
7-
be used for `migrate`. When migrating any existing contract to this burner
8-
contract, we delete all storage and send all bank tokens to a specified address,
9-
doing a basic cleanup of the contract.
6+
This contract cannot be installed directly (via `instantiate`), but is only
7+
designed to be used for `migrate`. When migrating any existing contract to this
8+
burner contract, we delete all storage and send all bank tokens to a specified
9+
address, doing a basic cleanup of the contract.
1010

1111
You can use this contract as-is, or fork it and customize it more if you want to
1212
do more detailed cleanup.

contracts/burner/examples/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs::create_dir_all;
33

44
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
55

6-
use burner::msg::{ExecuteMsg, InitMsg, MigrateMsg};
6+
use burner::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg};
77

88
fn main() {
99
let mut out_dir = current_dir().unwrap();
@@ -12,6 +12,6 @@ fn main() {
1212
remove_schemas(&out_dir).unwrap();
1313

1414
export_schema(&schema_for!(ExecuteMsg), &out_dir);
15-
export_schema(&schema_for!(InitMsg), &out_dir);
15+
export_schema(&schema_for!(InstantiateMsg), &out_dir);
1616
export_schema(&schema_for!(MigrateMsg), &out_dir);
1717
}

contracts/burner/schema/init_msg.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "InstantiateMsg",
4+
"description": "A placeholder where we don't take any input",
5+
"type": "object"
6+
}

contracts/burner/src/contract.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ use cosmwasm_std::{
22
attr, entry_point, BankMsg, DepsMut, Env, MessageInfo, Order, Response, StdError, StdResult,
33
};
44

5-
use crate::msg::{ExecuteMsg, InitMsg, MigrateMsg};
5+
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg};
66

77
#[entry_point]
8-
pub fn init(_deps: DepsMut, _env: Env, _info: MessageInfo, _msg: InitMsg) -> StdResult<Response> {
8+
pub fn instantiate(
9+
_deps: DepsMut,
10+
_env: Env,
11+
_info: MessageInfo,
12+
_msg: InstantiateMsg,
13+
) -> StdResult<Response> {
914
Err(StdError::generic_err(
1015
"You can only use this contract for migrations",
1116
))
@@ -60,13 +65,13 @@ mod tests {
6065
use cosmwasm_std::{coins, HumanAddr, StdError, Storage};
6166

6267
#[test]
63-
fn init_fails() {
68+
fn instantiate_fails() {
6469
let mut deps = mock_dependencies(&[]);
6570

66-
let msg = InitMsg {};
71+
let msg = InstantiateMsg {};
6772
let info = mock_info("creator", &coins(1000, "earth"));
6873
// we can just call .unwrap() to assert this was a success
69-
let res = init(deps.as_mut(), mock_env(), info, msg);
74+
let res = instantiate(deps.as_mut(), mock_env(), info, msg);
7075
match res.unwrap_err() {
7176
StdError::GenericErr { msg, .. } => {
7277
assert_eq!(msg, "You can only use this contract for migrations")

contracts/burner/src/msg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub struct MigrateMsg {
1010
pub payout: HumanAddr,
1111
}
1212

13-
/// InitMsg is a placeholder where we don't take any input
13+
/// A placeholder where we don't take any input
1414
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
15-
pub struct InitMsg {}
15+
pub struct InstantiateMsg {}
1616

1717
/// ExecuteMsg is a placeholder where we don't take any input
1818
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]

contracts/burner/tests/integration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
//! 4. Anywhere you see query(&deps, ...) you must replace it with query(&mut deps, ...)
1919
2020
use cosmwasm_std::{coins, BankMsg, ContractResult, HumanAddr, Order, Response};
21-
use cosmwasm_vm::testing::{init, migrate, mock_env, mock_info, mock_instance};
21+
use cosmwasm_vm::testing::{instantiate, migrate, mock_env, mock_info, mock_instance};
2222

23-
use burner::msg::{InitMsg, MigrateMsg};
23+
use burner::msg::{InstantiateMsg, MigrateMsg};
2424
use cosmwasm_vm::Storage;
2525

2626
// This line will test the output of cargo wasm
@@ -29,13 +29,13 @@ static WASM: &[u8] = include_bytes!("../target/wasm32-unknown-unknown/release/bu
2929
// static WASM: &[u8] = include_bytes!("../contract.wasm");
3030

3131
#[test]
32-
fn init_fails() {
32+
fn instantiate_fails() {
3333
let mut deps = mock_instance(WASM, &[]);
3434

35-
let msg = InitMsg {};
35+
let msg = InstantiateMsg {};
3636
let info = mock_info("creator", &coins(1000, "earth"));
3737
// we can just call .unwrap() to assert this was a success
38-
let res: ContractResult<Response> = init(&mut deps, mock_env(), info, msg);
38+
let res: ContractResult<Response> = instantiate(&mut deps, mock_env(), info, msg);
3939
let msg = res.unwrap_err();
4040
assert_eq!(
4141
msg,

0 commit comments

Comments
 (0)