Skip to content

Commit

Permalink
Change package name, update dependencies, clean up Clippy warnings, a…
Browse files Browse the repository at this point in the history
…dd Reply and Migrate entry points
  • Loading branch information
drewstaylor committed Aug 4, 2023
1 parent bcca30a commit 2b6d8d2
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 206 deletions.
360 changes: 213 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[package]
name = "test"
name = "archid-marketplace"
version = "0.1.0"
authors = ["johhonn <jjj.may377@gmail.com>"]
authors = [
"johhonn <jjj.may377@gmail.com>",
"Drew Taylor <drew.taylor@philabs.xyz>"
]
edition = "2018"

exclude = [
Expand Down Expand Up @@ -41,18 +44,18 @@ optimize = """docker run --rm -v "$(pwd)":/code \
"""

[dependencies]
cosmwasm-std = "1.0.0-beta5"
cosmwasm-storage = "1.0.0-beta5"
cosmwasm-std = "~1.0.0"
cosmwasm-storage = "~1.0.0"
cw-storage-plus = "0.12"
cw2 = "0.12"
cw20 = { version = "0.13.2" }
cw20-base = "0.13.2"
cw721-base = "0.13.2"
cw721 = "0.11"
cw20 = { version = "0.13.4" }
cw20-base = "0.13.4"
cw721-base = "0.13.4"
cw721 = "0.13.4"
schemars = "0.8"
serde = { version = "1.0", default-features = false, features = ["derive"] }
thiserror = "1.0"
cw-multi-test = "0.13.2"
cw-multi-test = "0.13.4"

[dev-dependencies]
cosmwasm-schema = "1.0.0-beta5"
cosmwasm-schema = "~1.0.0"
31 changes: 11 additions & 20 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "test",
"name": "archid-marketplace",
"developer": {
"archwayd": {
"docker": true
"docker": false
},
"scripts": {
"test": "cargo unit-test",
Expand All @@ -12,40 +12,31 @@
"query": "archwayd query wasm",
"tx": "archwayd tx wasm execute"
},
"deployments": [
{
"type": "create",
"chainId": "constantine-1",
"codeId": 95
}
]
"deployments": []
},
"network": {
"name": "augusta",
"chainId": "augusta-1",
"name": "constantine",
"chainId": "constantine-3",
"type": "testnet",
"fees": {
"feeDenom": "uaugust"
"feeDenom": "aconst"
},
"gas": {
"prices": "0.002uaugust",
"prices": "0.002aconst",
"mode": "auto",
"adjustment": "1.3"
"adjustment": "1.5"
},
"wasm": {
"bech32Hrp": "archway",
"archwayd": "0.0.4",
"archwayd": "1.0.0-rc.2",
"configDir": ".archway",
"binary": "archwayd"
},
"urls": {
"rpc": {
"url": "https://rpc.augusta-1.archway.tech",
"url": "https://rpc.constantine.archway.tech",
"port": 443
},
"faucets": [
"https://faucet.augusta-1.archway.tech"
]
}
}
}
}
2 changes: 1 addition & 1 deletion examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs::create_dir_all;

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

use test::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg};
use archid_marketplace::msg::{ ExecuteMsg, InstantiateMsg, QueryMsg};


fn main() {
Expand Down
72 changes: 47 additions & 25 deletions src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Addr, StdResult, Response,
CosmosMsg, WasmMsg,
Addr, Binary, CosmosMsg, Deps, DepsMut, entry_point, Env, MessageInfo,
Reply, Response, StdResult, SubMsgResult, to_binary, WasmMsg,
};
use cw_storage_plus::Bound;

Expand All @@ -14,14 +13,15 @@ use cw721_base::{
};

use crate::msg::{
CreateMsg, DetailsResponse, ExecuteMsg, InstantiateMsg, QueryMsg, CancelMsg, ListResponse
CancelMsg, CreateMsg, DetailsResponse, ExecuteMsg, InstantiateMsg,
QueryMsg, ListResponse, MigrateMsg,
};
use crate::state::{ CW721Swap, SWAPS, CANCELLED, COMPLETED, all_swap_ids, };

use cw2::set_contract_version;
use cw2::{get_contract_version, set_contract_version};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:test";
const CONTRACT_NAME: &str = "crates.io:archid-marketplace";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
Expand All @@ -48,21 +48,46 @@ pub fn execute(
ExecuteMsg::Cancel(msg) =>{execute_cancel(deps,_env,info,msg)}
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::List { start_after, limit } => to_binary(&query_list(deps, start_after, limit)?),
QueryMsg::Details { id } => to_binary(&query_details(deps, id)?)
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
match msg.result {
SubMsgResult::Ok(_) => Ok(Response::default()),
SubMsgResult::Err(_) => Err(ContractError::Unauthorized {}),
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
let original_version = get_contract_version(deps.storage)?;
let name = CONTRACT_NAME.to_string();
let version = CONTRACT_VERSION.to_string();
if original_version.contract != name {
return Err(ContractError::InvalidInput {});
}
if original_version.version >= version {
return Err(ContractError::InvalidInput {});
}
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

fn query_details(deps: Deps, id: String) -> StdResult<DetailsResponse> {
let swap = SWAPS.load(deps.storage, &id)?;

// Convert balance to human balance
let _can = CANCELLED.may_load(deps.storage, &id)?;
let _com = COMPLETED.may_load(deps.storage,&id)?;
let can = CANCELLED.may_load(deps.storage, &id)?;
let com = COMPLETED.may_load(deps.storage,&id)?;

let available: bool =! (_can!=None || _com!=None);
let available: bool =! (can.is_some() || com.is_some());

let details = DetailsResponse{
creator: swap.creator,
Expand All @@ -72,7 +97,7 @@ fn query_details(deps: Deps, id: String) -> StdResult<DetailsResponse> {
expires: swap.expires,
price: swap.price,
swap_type: swap.swap_type,
open: available.clone(),
open: available,
};
Ok(details)
}
Expand All @@ -98,11 +123,10 @@ pub fn execute_create(
info: MessageInfo,
msg: CreateMsg,
) -> Result<Response, ContractError> {

if msg.expires.is_expired(&env.block) {
return Err(ContractError::Expired {});
}

// let recipient = deps.api.addr_validate(&msg.recipient)?;
let swap = CW721Swap {
creator:info.sender,
Expand All @@ -113,46 +137,46 @@ pub fn execute_create(
price:msg.price,
swap_type:msg.swap_type,
};

// Try to store it, fail if the id already exists (unmodifiable swaps)
SWAPS.update(deps.storage, &msg.id, |existing| match existing {
None => Ok(swap),
Some(_) => Err(ContractError::AlreadyExists {}),
})?;

let res = Response::new();

Ok(res)
}
pub fn execute_finish(deps: DepsMut,
env: Env,
info: MessageInfo,
msg: CreateMsg)-> Result<Response, ContractError> {
let swap = SWAPS.load(deps.storage, &msg.id)?;
let _can = CANCELLED.may_load(deps.storage, &msg.id)?;
let _com= COMPLETED.may_load(deps.storage,&msg.id)?;
let can = CANCELLED.may_load(deps.storage, &msg.id)?;
let com = COMPLETED.may_load(deps.storage,&msg.id)?;

if msg.expires.is_expired(&env.block) {
return Err(ContractError::Expired {});
}
if _can!=None{
if can.is_some() {
return Err(ContractError::Cancelled {});
}
if _com!=None{
if com.is_some() {
return Err(ContractError::Completed {});
}

let transfer_results= match msg.swap_type{
true => handle_swap_transfers(&swap.creator,&info.sender,swap.clone())?,
false=> handle_swap_transfers(&info.sender,&swap.creator,swap.clone())?,
};



COMPLETED.update(deps.storage, &msg.id, |existing| match existing {
None => Ok(true),
Some(_) => Err(ContractError::AlreadyExists {}),
})?;

let res = Response::new().add_messages(transfer_results);

Ok(res)
}

Expand All @@ -173,8 +197,6 @@ pub fn execute_cancel(deps: DepsMut,
}

fn handle_swap_transfers(nft_sender:&Addr,nft_receiver: &Addr,details:CW721Swap) -> StdResult<Vec<CosmosMsg>> {


let token_transfer_msg = Cw20ExecuteMsg::TransferFrom {
owner: nft_receiver.to_string(),
recipient:nft_sender.to_string(),
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub enum ContractError {
#[error("Send some coins to create an atomic swap")]
EmptyBalance {},

#[error("InvalidInput")]
InvalidInput {},

#[error("Atomic swap not yet expired")]
NotExpired,
#[error("Atomic swap not yet expired")]
Expand Down
6 changes: 5 additions & 1 deletion src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub enum QueryMsg {
Details { id: String },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MigrateMsg {}

// We define a custom struct for each query response
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ListResponse {
Expand All @@ -62,4 +66,4 @@ pub struct DetailsResponse {
pub price: Uint128,
pub swap_type:bool,
pub open:bool,
}
}
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_std::{
to_binary, Addr, Binary, Deps, DepsMut, Env, QueryRequest, StdError, StdResult, WasmQuery,
to_binary, Addr, DepsMut, QueryRequest, StdError, WasmQuery,
};
use cw721_base::{Extension, QueryMsg as Cw721QueryMsg};
use cw721_base::{QueryMsg as Cw721QueryMsg};
use cw721::OwnerOfResponse;

pub fn query_name_owner(
Expand Down

0 comments on commit 2b6d8d2

Please sign in to comment.