-
Notifications
You must be signed in to change notification settings - Fork 355
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
Migrate to v0.11 #104
Merged
Merged
Migrate to v0.11 #104
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
87aaddc
Migrate contracts to >0.10.1 (0.11)
maurolacy bfbd3fa
Migrate to 0.11
maurolacy f11ff50
Update dependencies to 0.11.0-alpha2
maurolacy bd8c8b2
Change to new bucket parameters order
maurolacy 0551997
(Manually) fix rebase from master
maurolacy b6c116e
Update deps to v0.11.0-alpha3
maurolacy a1e8c26
Migrate cw1-whitelist to ContractError
maurolacy c3bbfc2
Migrate cw1-subkeys to thiserror / custom ContractError
maurolacy 4b47e56
Update Cargo.lock
maurolacy ccf4f9a
Migrate cw20-atomic-swap to thiserror / ContractError
maurolacy 9bd5bda
Fix Underflow error match
maurolacy 1c8bbb3
Fix Cargo.lock
maurolacy 2b0f72d
Better / consolidated error types
maurolacy a89ffee
Reverting NotFound to NoAllowance
maurolacy b31a5f8
Custom errors specialization
maurolacy 0ffdab5
Migrate cw20-base to thiserror / ContractError
maurolacy 9685727
Migrate cw20-escrow to thiserror / ContractError
maurolacy 678dba9
Migrate cw20-staking to thiserror / ContractError
maurolacy c4389eb
Upstream versions of cw* pkgs for cw3-fixed-multisig (not yet migrate…
maurolacy 8e48aaa
Upstream versions of cw* pkgs for cw721-nft (not yet migrated to 0.11)
maurolacy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
use cosmwasm_std::{ | ||
attr, from_binary, to_binary, Api, BankMsg, Binary, Coin, CosmosMsg, Env, Extern, | ||
HandleResponse, HumanAddr, InitResponse, Querier, StdError, StdResult, Storage, WasmMsg, | ||
attr, from_binary, to_binary, Api, BankMsg, Binary, CosmosMsg, Env, Extern, HandleResponse, | ||
HumanAddr, InitResponse, Querier, StdResult, Storage, WasmMsg, | ||
}; | ||
use cosmwasm_storage::prefixed; | ||
|
||
use cw2::set_contract_version; | ||
use cw20::{Cw20Coin, Cw20CoinHuman, Cw20HandleMsg, Cw20ReceiveMsg}; | ||
use cw20_atomic_swap::balance::Balance; | ||
|
||
use crate::error::ContractError; | ||
use crate::msg::{ | ||
CreateMsg, DetailsResponse, HandleMsg, InitMsg, ListResponse, QueryMsg, ReceiveMsg, | ||
}; | ||
|
@@ -31,7 +32,7 @@ pub fn handle<S: Storage, A: Api, Q: Querier>( | |
deps: &mut Extern<S, A, Q>, | ||
env: Env, | ||
msg: HandleMsg, | ||
) -> StdResult<HandleResponse> { | ||
) -> Result<HandleResponse, ContractError> { | ||
match msg { | ||
HandleMsg::Create(msg) => try_create( | ||
deps, | ||
|
@@ -50,10 +51,10 @@ pub fn try_receive<S: Storage, A: Api, Q: Querier>( | |
deps: &mut Extern<S, A, Q>, | ||
env: Env, | ||
wrapper: Cw20ReceiveMsg, | ||
) -> StdResult<HandleResponse> { | ||
) -> Result<HandleResponse, ContractError> { | ||
let msg: ReceiveMsg = match wrapper.msg { | ||
Some(bin) => from_binary(&bin), | ||
None => Err(StdError::parse_err("ReceiveMsg", "no data")), | ||
Some(bin) => Ok(from_binary(&bin)?), | ||
None => Err(ContractError::NoData {}), | ||
}?; | ||
let balance = Balance::Cw20(Cw20Coin { | ||
address: deps.api.canonical_address(&env.message.sender)?, | ||
|
@@ -70,9 +71,9 @@ pub fn try_create<S: Storage, A: Api, Q: Querier>( | |
msg: CreateMsg, | ||
balance: Balance, | ||
sender: &HumanAddr, | ||
) -> StdResult<HandleResponse> { | ||
) -> Result<HandleResponse, ContractError> { | ||
if balance.is_empty() { | ||
return Err(StdError::generic_err("Send some coins to create an escrow")); | ||
return Err(ContractError::EmptyBalance {}); | ||
} | ||
|
||
let mut cw20_whitelist = msg.canonical_whitelist(&deps.api)?; | ||
|
@@ -107,7 +108,7 @@ pub fn try_create<S: Storage, A: Api, Q: Querier>( | |
// try to store it, fail if the id was already in use | ||
escrows(&mut deps.storage).update(msg.id.as_bytes(), |existing| match existing { | ||
None => Ok(escrow), | ||
Some(_) => Err(StdError::generic_err("escrow id already in use")), | ||
Some(_) => Err(ContractError::AlreadyInUse {}), | ||
})?; | ||
|
||
let mut res = HandleResponse::default(); | ||
|
@@ -119,21 +120,17 @@ pub fn try_top_up<S: Storage, A: Api, Q: Querier>( | |
deps: &mut Extern<S, A, Q>, | ||
id: String, | ||
balance: Balance, | ||
) -> StdResult<HandleResponse> { | ||
) -> Result<HandleResponse, ContractError> { | ||
if balance.is_empty() { | ||
return Err(StdError::generic_err( | ||
"Send some amount to increase an escrow", | ||
)); | ||
return Err(ContractError::EmptyBalance {}); | ||
} | ||
// this fails is no escrow there | ||
let mut escrow = escrows_read(&deps.storage).load(id.as_bytes())?; | ||
|
||
if let Balance::Cw20(token) = &balance { | ||
// ensure the token is on the whitelist | ||
if !escrow.cw20_whitelist.iter().any(|t| t == &token.address) { | ||
return Err(StdError::generic_err( | ||
"Only accepts tokens on the cw20_whitelist", | ||
)); | ||
return Err(ContractError::NotInWhitelist {}); | ||
} | ||
}; | ||
|
||
|
@@ -151,14 +148,14 @@ pub fn try_approve<S: Storage, A: Api, Q: Querier>( | |
deps: &mut Extern<S, A, Q>, | ||
env: Env, | ||
id: String, | ||
) -> StdResult<HandleResponse> { | ||
) -> Result<HandleResponse, ContractError> { | ||
// this fails is no escrow there | ||
let escrow = escrows_read(&deps.storage).load(id.as_bytes())?; | ||
|
||
if deps.api.canonical_address(&env.message.sender)? != escrow.arbiter { | ||
Err(StdError::unauthorized()) | ||
Err(ContractError::Unauthorized {}) | ||
} else if escrow.is_expired(&env) { | ||
Err(StdError::generic_err("escrow expired")) | ||
Err(ContractError::Expired {}) | ||
} else { | ||
// we delete the escrow (TODO: expose this in Bucket for simpler API) | ||
prefixed(&mut deps.storage, PREFIX_ESCROW).remove(id.as_bytes()); | ||
|
@@ -181,15 +178,15 @@ pub fn try_refund<S: Storage, A: Api, Q: Querier>( | |
deps: &mut Extern<S, A, Q>, | ||
env: Env, | ||
id: String, | ||
) -> StdResult<HandleResponse> { | ||
) -> Result<HandleResponse, ContractError> { | ||
// this fails is no escrow there | ||
let escrow = escrows_read(&deps.storage).load(id.as_bytes())?; | ||
|
||
// the arbiter can send anytime OR anyone can send after expiration | ||
if !escrow.is_expired(&env) | ||
&& deps.api.canonical_address(&env.message.sender)? != escrow.arbiter | ||
{ | ||
Err(StdError::unauthorized()) | ||
Err(ContractError::Unauthorized {}) | ||
} else { | ||
// we delete the escrow (TODO: expose this in Bucket for simpler API) | ||
prefixed(&mut deps.storage, PREFIX_ESCROW).remove(id.as_bytes()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, this is now in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change those in another branch / PR. |
||
|
@@ -373,7 +370,7 @@ mod tests { | |
let env = mock_env(&create.arbiter, &[]); | ||
let res = handle(&mut deps, env, HandleMsg::Approve { id }); | ||
match res.unwrap_err() { | ||
StdError::NotFound { .. } => {} | ||
ContractError::Std(StdError::NotFound { .. }) => {} | ||
e => panic!("Expected NotFound, got {}", e), | ||
} | ||
} | ||
|
@@ -455,7 +452,7 @@ mod tests { | |
let env = mock_env(&create.arbiter, &[]); | ||
let res = handle(&mut deps, env, HandleMsg::Approve { id }); | ||
match res.unwrap_err() { | ||
StdError::NotFound { .. } => {} | ||
ContractError::Std(StdError::NotFound { .. }) => {} | ||
e => panic!("Expected NotFound, got {}", e), | ||
} | ||
} | ||
|
@@ -571,9 +568,7 @@ mod tests { | |
let env = mock_env(&baz_token, &[]); | ||
let res = handle(&mut deps, env, top_up); | ||
match res.unwrap_err() { | ||
StdError::GenericErr { msg, .. } => { | ||
assert_eq!(msg, "Only accepts tokens on the cw20_whitelist") | ||
} | ||
ContractError::NotInWhitelist {} => {} | ||
e => panic!("Unexpected error: {}", e), | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use cosmwasm_std::StdError; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
maurolacy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub enum ContractError { | ||
#[error("{0}")] | ||
Std(#[from] StdError), | ||
|
||
#[error("No data in ReceiveMsg")] | ||
NoData {}, | ||
|
||
#[error("Unauthorized")] | ||
Unauthorized {}, | ||
|
||
#[error("Only accepts tokens in the cw20_whitelist")] | ||
NotInWhitelist {}, | ||
|
||
#[error("Escrow is expired")] | ||
Expired {}, | ||
|
||
#[error("Send some coins to create an escrow")] | ||
EmptyBalance {}, | ||
|
||
#[error("Escrow id already in use")] | ||
AlreadyInUse {}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod contract; | ||
mod error; | ||
pub mod msg; | ||
pub mod state; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here... time to update