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

Rename Extern to Deps #589

Merged
merged 1 commit into from
Oct 19, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Rename `StdError::ParseErr::source` to `StdError::ParseErr::source_type` and
`StdError::SerializeErr::target` to `StdError::SerializeErr::target_type` to
work around speacial treatment of the field name `source` in thiserror.
- Rename `Extern` to `Deps` to unify naming.

**cosmwasm-vm**

Expand Down
20 changes: 20 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ major releases of `cosmwasm`. Note that you can also view the
In order to use backtraces for debugging, run
`RUST_BACKTRACE=1 cargo +nightly unit-test --features backtraces`.

- Rename the type `Extern` to `Deps` in `init`/`handle`/`migrate`/`query`, e.g.

```rust
// before
pub fn migrate<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
_env: Env,
_info: MessageInfo,
msg: MigrateMsg,
) -> Result<MigrateResponse, HackError> {

// after
pub fn migrate<S: Storage, A: Api, Q: Querier>(
deps: &mut Deps<S, A, Q>,
_env: Env,
_info: MessageInfo,
msg: MigrateMsg,
) -> Result<MigrateResponse, HackError> {
```

## 0.10 -> 0.11

- Contracts now support any custom error type `E: ToString + From<StdError>`.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,27 @@ custom `InitMsg` and `HandleMsg` structs for parsing your custom message types

```rust
pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
env: Env,
info: MessageInfo,
msg: InitMsg,
) -> StdResult<InitResponse> {}

pub fn handle<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
env: Env,
info: MessageInfo,
msg: HandleMsg,
) -> Result<HandleResponse, ContractError> { }

pub fn query<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
env: Env,
msg: QueryMsg,
) -> StdResult<Binary> { }

pub fn migrate<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
env: Env,
info: MessageInfo,
msg: HandleMsg,
Expand Down
10 changes: 5 additions & 5 deletions contracts/burner/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use cosmwasm_std::{
attr, Api, BankMsg, Binary, Env, Extern, HandleResponse, InitResponse, MessageInfo,
attr, Api, BankMsg, Binary, Deps, Env, HandleResponse, InitResponse, MessageInfo,
MigrateResponse, Order, Querier, StdError, StdResult, Storage,
};

use crate::msg::{HandleMsg, InitMsg, MigrateMsg, QueryMsg};

pub fn init<S: Storage, A: Api, Q: Querier>(
_deps: &mut Extern<S, A, Q>,
_deps: &mut Deps<S, A, Q>,
_env: Env,
_info: MessageInfo,
_msg: InitMsg,
Expand All @@ -17,7 +17,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
}

pub fn handle<S: Storage, A: Api, Q: Querier>(
_deps: &mut Extern<S, A, Q>,
_deps: &mut Deps<S, A, Q>,
_env: Env,
_info: MessageInfo,
_msg: HandleMsg,
Expand All @@ -28,7 +28,7 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
}

pub fn migrate<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
env: Env,
_info: MessageInfo,
msg: MigrateMsg,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn migrate<S: Storage, A: Api, Q: Querier>(
}

pub fn query<S: Storage, A: Api, Q: Querier>(
_deps: &Extern<S, A, Q>,
_deps: &Deps<S, A, Q>,
_env: Env,
_msg: QueryMsg,
) -> StdResult<Binary> {
Expand Down
20 changes: 10 additions & 10 deletions contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::convert::TryInto;

use cosmwasm_std::{
from_slice, to_binary, to_vec, AllBalanceResponse, Api, BankMsg, Binary, CanonicalAddr,
Context, Env, Extern, HandleResponse, HumanAddr, InitResponse, MessageInfo, MigrateResponse,
Context, Deps, Env, HandleResponse, HumanAddr, InitResponse, MessageInfo, MigrateResponse,
Querier, QueryRequest, QueryResponse, StdError, StdResult, Storage, WasmQuery,
};

Expand Down Expand Up @@ -87,7 +87,7 @@ pub struct RecurseResponse {
pub const CONFIG_KEY: &[u8] = b"config";

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
_env: Env,
info: MessageInfo,
msg: InitMsg,
Expand All @@ -110,7 +110,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
}

pub fn migrate<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
_env: Env,
_info: MessageInfo,
msg: MigrateMsg,
Expand All @@ -127,7 +127,7 @@ pub fn migrate<S: Storage, A: Api, Q: Querier>(
}

pub fn handle<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
env: Env,
info: MessageInfo,
msg: HandleMsg,
Expand All @@ -144,7 +144,7 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
}

fn do_release<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
env: Env,
info: MessageInfo,
) -> Result<HandleResponse, HackError> {
Expand Down Expand Up @@ -184,7 +184,7 @@ fn do_cpu_loop() -> Result<HandleResponse, HackError> {
}

fn do_storage_loop<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
) -> Result<HandleResponse, HackError> {
let mut test_case = 0u64;
loop {
Expand Down Expand Up @@ -295,7 +295,7 @@ fn do_user_errors_in_api_calls<A: Api>(api: &A) -> Result<HandleResponse, HackEr
}

pub fn query<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
env: Env,
msg: QueryMsg,
) -> StdResult<QueryResponse> {
Expand All @@ -309,7 +309,7 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
}

fn query_verifier<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
) -> StdResult<VerifierResponse> {
let data = deps
.storage
Expand All @@ -321,15 +321,15 @@ fn query_verifier<S: Storage, A: Api, Q: Querier>(
}

fn query_other_balance<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
address: HumanAddr,
) -> StdResult<AllBalanceResponse> {
let amount = deps.querier.query_all_balances(address)?;
Ok(AllBalanceResponse { amount })
}

fn query_recurse<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
depth: u32,
work: u32,
contract: HumanAddr,
Expand Down
28 changes: 13 additions & 15 deletions contracts/queue/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_std::{
from_slice, to_binary, to_vec, Api, Binary, Env, Extern, HandleResponse, InitResponse,
from_slice, to_binary, to_vec, Api, Binary, Deps, Env, HandleResponse, InitResponse,
MessageInfo, Order, Querier, QueryResponse, StdResult, Storage,
};

Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct ListResponse {

// init is a no-op, just empty data
pub fn init<S: Storage, A: Api, Q: Querier>(
_deps: &mut Extern<S, A, Q>,
_deps: &mut Deps<S, A, Q>,
_env: Env,
_info: MessageInfo,
_msg: InitMsg,
Expand All @@ -74,7 +74,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
}

pub fn handle<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
_env: Env,
_info: MessageInfo,
msg: HandleMsg,
Expand All @@ -88,7 +88,7 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
const FIRST_KEY: u8 = 0;

fn enqueue<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
value: i32,
) -> StdResult<HandleResponse> {
// find the last element in the queue and extract key
Expand All @@ -106,9 +106,7 @@ fn enqueue<S: Storage, A: Api, Q: Querier>(
Ok(HandleResponse::default())
}

fn dequeue<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
) -> StdResult<HandleResponse> {
fn dequeue<S: Storage, A: Api, Q: Querier>(deps: &mut Deps<S, A, Q>) -> StdResult<HandleResponse> {
// find the first element in the queue and extract value
let first = deps.storage.range(None, None, Order::Ascending).next();

Expand All @@ -124,7 +122,7 @@ fn dequeue<S: Storage, A: Api, Q: Querier>(
}

pub fn query<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
_env: Env,
msg: QueryMsg,
) -> StdResult<QueryResponse> {
Expand All @@ -136,12 +134,12 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
}
}

fn query_count<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResult<CountResponse> {
fn query_count<S: Storage, A: Api, Q: Querier>(deps: &Deps<S, A, Q>) -> StdResult<CountResponse> {
let count = deps.storage.range(None, None, Order::Ascending).count() as u32;
Ok(CountResponse { count })
}

fn query_sum<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResult<SumResponse> {
fn query_sum<S: Storage, A: Api, Q: Querier>(deps: &Deps<S, A, Q>) -> StdResult<SumResponse> {
let values: StdResult<Vec<Item>> = deps
.storage
.range(None, None, Order::Ascending)
Expand All @@ -152,7 +150,7 @@ fn query_sum<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResul
}

fn query_reducer<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
) -> StdResult<ReducerResponse> {
let mut out: Vec<(i32, i32)> = vec![];
// val: StdResult<Item>
Expand Down Expand Up @@ -182,7 +180,7 @@ fn query_reducer<S: Storage, A: Api, Q: Querier>(

/// Does a range query with both bounds set. Not really useful but to debug an issue
/// between VM and Wasm: https://github.com/CosmWasm/cosmwasm/issues/508
fn query_list<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResult<ListResponse> {
fn query_list<S: Storage, A: Api, Q: Querier>(deps: &Deps<S, A, Q>) -> StdResult<ListResponse> {
let empty: Vec<u32> = deps
.storage
.range(Some(b"large"), Some(b"larger"), Order::Ascending)
Expand All @@ -209,19 +207,19 @@ mod tests {
};
use cosmwasm_std::{coins, from_binary};

fn create_contract() -> (Extern<MockStorage, MockApi, MockQuerier>, MessageInfo) {
fn create_contract() -> (Deps<MockStorage, MockApi, MockQuerier>, MessageInfo) {
let mut deps = mock_dependencies(&coins(1000, "earth"));
let info = mock_info("creator", &coins(1000, "earth"));
let res = init(&mut deps, mock_env(), info.clone(), InitMsg {}).unwrap();
assert_eq!(0, res.messages.len());
(deps, info)
}

fn get_count(deps: &Extern<MockStorage, MockApi, MockQuerier>) -> u32 {
fn get_count(deps: &Deps<MockStorage, MockApi, MockQuerier>) -> u32 {
query_count(deps).unwrap().count
}

fn get_sum(deps: &Extern<MockStorage, MockApi, MockQuerier>) -> i32 {
fn get_sum(deps: &Deps<MockStorage, MockApi, MockQuerier>) -> i32 {
query_sum(deps).unwrap().sum
}

Expand Down
20 changes: 10 additions & 10 deletions contracts/reflect/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{
attr, to_binary, to_vec, Api, Binary, ContractResult, CosmosMsg, Env, Extern, HandleResponse,
attr, to_binary, to_vec, Api, Binary, ContractResult, CosmosMsg, Deps, Env, HandleResponse,
HumanAddr, InitResponse, MessageInfo, Querier, QueryRequest, StdError, StdResult, Storage,
SystemResult,
};
Expand All @@ -12,7 +12,7 @@ use crate::msg::{
use crate::state::{config, config_read, State};

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
_env: Env,
info: MessageInfo,
_msg: InitMsg,
Expand All @@ -26,7 +26,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
}

pub fn handle<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
env: Env,
info: MessageInfo,
msg: HandleMsg,
Expand All @@ -38,7 +38,7 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
}

pub fn try_reflect<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
_env: Env,
info: MessageInfo,
msgs: Vec<CosmosMsg<CustomMsg>>,
Expand All @@ -65,7 +65,7 @@ pub fn try_reflect<S: Storage, A: Api, Q: Querier>(
}

pub fn try_change_owner<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
deps: &mut Deps<S, A, Q>,
_env: Env,
info: MessageInfo,
owner: HumanAddr,
Expand All @@ -89,7 +89,7 @@ pub fn try_change_owner<S: Storage, A: Api, Q: Querier>(
}

pub fn query<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
_env: Env,
msg: QueryMsg,
) -> StdResult<Binary> {
Expand All @@ -101,7 +101,7 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
}
}

fn query_owner<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResult<OwnerResponse> {
fn query_owner<S: Storage, A: Api, Q: Querier>(deps: &Deps<S, A, Q>) -> StdResult<OwnerResponse> {
let state = config_read(&deps.storage).load()?;
let resp = OwnerResponse {
owner: deps.api.human_address(&state.owner)?,
Expand All @@ -110,7 +110,7 @@ fn query_owner<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdRes
}

fn query_capitalized<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
text: String,
) -> StdResult<CapitalizedResponse> {
let req = SpecialQuery::Capitalized { text }.into();
Expand All @@ -119,7 +119,7 @@ fn query_capitalized<S: Storage, A: Api, Q: Querier>(
}

fn query_chain<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
request: &QueryRequest<SpecialQuery>,
) -> StdResult<ChainResponse> {
let raw = to_vec(request).map_err(|serialize_err| {
Expand All @@ -139,7 +139,7 @@ fn query_chain<S: Storage, A: Api, Q: Querier>(
}

fn query_raw<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
deps: &Deps<S, A, Q>,
contract: HumanAddr,
key: Binary,
) -> StdResult<RawResponse> {
Expand Down
Loading