diff --git a/Makefile b/Makefile index 5318775..68a5c88 100644 --- a/Makefile +++ b/Makefile @@ -9,26 +9,32 @@ optimize: test: cargo unit-test +<<<<<<< HEAD FROM=nibi10rdtquh3jl44hg00x0plzeawuclqqet0he4692 AIRDROP_CONTRACT=nibi10jwwkmmn0rzxvfec5swhgvtkh4l94fshz0r8ndj9ldym87lkgdjs4z4cyp +======= +WALLET=nibi1d3lmwkgjgdyfpsn4xgh299jnpk4r89kd5xs420 +AIRDROP_CONTRACT=nibi1lz6h4tav6q8jrpxxs6kv63hztlmpu27jj50jcnrt9p7wd2nrmz9s9600vz +CODE_ID=421 +WALLET_NAME=jarvis +>>>>>>> f8a4af504d3b45ae487ba064c7d39c846c54be0e make-wallet: - @nibid keys add wallet + @nibid keys add wallet ${WALLET_NAME} show-wallet: - @nibid keys show -a ${id} + @nibid keys show -a ${WALLET} + +get-balance: + @nibid query bank balances ${WALLET} --denom unibi upload-testnet: - @nibid tx wasm store artifacts/jarvis_airdrop.wasm --from ${FROM} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes + @nibid tx wasm store artifacts/jarvis_airdrop.wasm --from ${WALLET} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes instantiate-testnet: - @nibid tx wasm instantiate ${id} '{"count": 1}' --admin ${FROM} --label airdrop --from ${FROM} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes - -get-count: - $(eval GET_COUNT := $$(shell cat ./commands/get_count.json)) - @nibid query wasm contract-state smart ${AIRDROP_CONTRACT} '$(GET_COUNT)' + @nibid tx wasm instantiate ${CODE_ID} --admin ${WALLET} --label airdrop --from ${WALLET} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes -get-nft-contract-addres: +get-nft-contract-address: $(eval GET_NFT_CONTRACT_ADDRESS := $$(shell cat ./commands/get_nft_contract_addr.json)) @nibid query wasm contract-state smart ${AIRDROP_CONTRACT} '$(GET_NFT_CONTRACT_ADDRESS)' @@ -38,8 +44,8 @@ get-all-nfts: exe-set-nft-contract-addr: $(eval SET_NFT_CONTRACT_ADDR := $$(shell cat ./commands/set_nft_contract_addr.json)) - @nibid tx wasm execute ${AIRDROP_CONTRACT} '$(SET_NFT_CONTRACT_ADDR)' --from ${FROM} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes + @nibid tx wasm execute ${AIRDROP_CONTRACT} '$(SET_NFT_CONTRACT_ADDR)' --from ${WALLET} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes exe-send-nfts: $(eval SEND_NFTS := $$(shell cat ./commands/send_nfts.json)) - @nibid tx wasm execute ${AIRDROP_CONTRACT} '$(SEND_NFTS)' --from ${FROM} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes \ No newline at end of file + @nibid tx wasm execute ${AIRDROP_CONTRACT} '$(SEND_NFTS)' --from ${WALLET} --gas auto --gas-adjustment 1.5 --gas-prices 0.025unibi --yes \ No newline at end of file diff --git a/artifacts/checksums.txt b/artifacts/checksums.txt index be43b23..572282b 100644 --- a/artifacts/checksums.txt +++ b/artifacts/checksums.txt @@ -1 +1,5 @@ +<<<<<<< HEAD 6cad51fd1cd844c98c7e367b1b0910c4389e8f0c4a69edab1821e7aeb99094f9 jarvis_airdrop.wasm +======= +d63576084b69def9913aae0899dcba97a22482511bd860bac1345e455332fbfc jarvis_airdrop.wasm +>>>>>>> f8a4af504d3b45ae487ba064c7d39c846c54be0e diff --git a/artifacts/checksums_intermediate.txt b/artifacts/checksums_intermediate.txt index c7da107..93b6cc8 100644 --- a/artifacts/checksums_intermediate.txt +++ b/artifacts/checksums_intermediate.txt @@ -1 +1,5 @@ +<<<<<<< HEAD deddb63d42e3a8126c7edda8a28755f4ec6f28ee7f40becb1755b5e3c1be49f7 /target/wasm32-unknown-unknown/release/jarvis_airdrop.wasm +======= +5f9d4a5aeeef32dfe13b0866f83378a51934ead6a95938042e1cc2966ab31032 /target/wasm32-unknown-unknown/release/jarvis_airdrop.wasm +>>>>>>> f8a4af504d3b45ae487ba064c7d39c846c54be0e diff --git a/src/contract.rs b/src/contract.rs index 7b00aaa..4405b97 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -1,11 +1,14 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Addr, CosmosMsg, WasmMsg, SubMsg}; +use cosmwasm_std::{ + to_json_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdResult, + SubMsg, WasmMsg, +}; use cw2::set_contract_version; use cw721::Cw721ExecuteMsg; use crate::error::ContractError; -use crate::msg::{ExecuteMsg, GetCountResponse, InstantiateMsg, QueryMsg, AllNftsResponse, NftContractAddrResponse, SendNftParam}; +use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg, AllNftsResponse, NftContractAddrResponse, SendNftParam}; use crate::state::{State, STATE, NFTS, NFT_CONTRACT_ADDR}; // version info for migration info @@ -20,7 +23,6 @@ pub fn instantiate( msg: InstantiateMsg, ) -> Result { let state = State { - count: msg.count, owner: info.sender.clone(), }; set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; @@ -28,8 +30,7 @@ pub fn instantiate( Ok(Response::new() .add_attribute("method", "instantiate") - .add_attribute("owner", info.sender) - .add_attribute("count", msg.count.to_string())) + .add_attribute("owner", info.sender)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -40,37 +41,21 @@ pub fn execute( msg: ExecuteMsg, ) -> Result { match msg { - ExecuteMsg::Increment {} => execute::increment(deps), - ExecuteMsg::Reset { count } => execute::reset(deps, info, count), - ExecuteMsg::SetNftContractAddr { addr } => execute::set_nft_contract_addr(deps, env, info, addr), - ExecuteMsg::ReceiveNft { sender, token_id, msg } => execute::receive_nft(deps, env, info, token_id), - ExecuteMsg::SendNfts { allocations } => execute::send_nfts(deps, env, info, allocations), + ExecuteMsg::SetNftContractAddr { addr } => { + execute::set_nft_contract_addr(deps, env, info, addr) + } + ExecuteMsg::ReceiveNft { + sender, + token_id, + msg, + } => execute::receive_nft(deps, env, info, token_id), + ExecuteMsg::SendNfts { allocations } => execute::send_nfts(deps, env, info, allocations), } } pub mod execute { use super::*; - pub fn increment(deps: DepsMut) -> Result { - STATE.update(deps.storage, |mut state| -> Result<_, ContractError> { - state.count += 1; - Ok(state) - })?; - - Ok(Response::new().add_attribute("action", "increment")) - } - - pub fn reset(deps: DepsMut, info: MessageInfo, count: i32) -> Result { - STATE.update(deps.storage, |mut state| -> Result<_, ContractError> { - if info.sender != state.owner { - return Err(ContractError::Unauthorized {}); - } - state.count = count; - Ok(state) - })?; - Ok(Response::new().add_attribute("action", "reset")) - } - pub fn set_nft_contract_addr( deps: DepsMut, _env: Env, @@ -87,7 +72,9 @@ pub mod execute { // Optionally, add authorization checks here to ensure only specific addresses can update this let nft_contract_addr = deps.api.addr_validate(&addr)?; NFT_CONTRACT_ADDR.save(deps.storage, &nft_contract_addr)?; - Ok(Response::new().add_attribute("action", "set_nft_contract_addr").add_attribute("address", addr)) + Ok(Response::new() + .add_attribute("action", "set_nft_contract_addr") + .add_attribute("address", addr)) } pub fn receive_nft( @@ -99,10 +86,9 @@ pub mod execute { let mut nfts = NFTS.load(deps.storage).unwrap_or_default(); nfts.push(token_id); NFTS.save(deps.storage, &nfts)?; - + Ok(Response::new().add_attribute("action", "receive_nft")) } - pub fn send_nfts( deps: DepsMut, @@ -132,20 +118,20 @@ pub mod execute { recipient: ele.recipient.to_string(), token_id: token_id, }; - + let msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: validated_addr.clone().to_string(), msg: to_json_binary(&transfer_msg)?, funds: vec![], }); - + response.messages.push(SubMsg::new(msg)); } else { return Err(ContractError::InsufficientNFTs {}); } } } - + NFTS.save(deps.storage, &nfts)?; Ok(response) } @@ -154,25 +140,19 @@ pub mod execute { #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetCount {} => to_json_binary(&query::count(deps)?), - QueryMsg::GetAllNfts { } => to_json_binary(&query::all_nfts(deps)?), - QueryMsg::GetNftContractAddr { } => to_json_binary(&query::nft_contract_addr(deps)?), + QueryMsg::GetAllNfts {} => to_json_binary(&query::all_nfts(deps)?), + QueryMsg::GetNftContractAddr {} => to_json_binary(&query::nft_contract_addr(deps)?), } } pub mod query { use super::*; - pub fn count(deps: Deps) -> StdResult { - let state = STATE.load(deps.storage)?; - Ok(GetCountResponse { count: state.count }) - } - pub fn all_nfts(deps: Deps) -> StdResult { let nfts = NFTS.load(deps.storage)?; Ok(AllNftsResponse { nfts }) } - + pub fn nft_contract_addr(deps: Deps) -> StdResult { let nft_contract_addr = NFT_CONTRACT_ADDR.load(deps.storage)?; Ok(NftContractAddrResponse { nft_contract_addr }) @@ -189,63 +169,11 @@ mod tests { fn proper_initialization() { let mut deps = mock_dependencies(); - let msg = InstantiateMsg { count: 17 }; + let msg = InstantiateMsg {}; let info = mock_info("creator", &coins(1000, "earth")); // we can just call .unwrap() to assert this was a success let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); assert_eq!(0, res.messages.len()); - - // it worked, let's query the state - let res = query(deps.as_ref(), mock_env(), QueryMsg::GetCount {}).unwrap(); - let value: GetCountResponse = from_json(&res).unwrap(); - assert_eq!(17, value.count); - } - - #[test] - fn increment() { - let mut deps = mock_dependencies(); - - let msg = InstantiateMsg { count: 17 }; - let info = mock_info("creator", &coins(2, "token")); - let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); - - // beneficiary can release it - let info = mock_info("anyone", &coins(2, "token")); - let msg = ExecuteMsg::Increment {}; - let _res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); - - // should increase counter by 1 - let res = query(deps.as_ref(), mock_env(), QueryMsg::GetCount {}).unwrap(); - let value: GetCountResponse = from_json(&res).unwrap(); - assert_eq!(18, value.count); - } - - #[test] - fn reset() { - let mut deps = mock_dependencies(); - - let msg = InstantiateMsg { count: 17 }; - let info = mock_info("creator", &coins(2, "token")); - let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); - - // beneficiary can release it - let unauth_info = mock_info("anyone", &coins(2, "token")); - let msg = ExecuteMsg::Reset { count: 5 }; - let res = execute(deps.as_mut(), mock_env(), unauth_info, msg); - match res { - Err(ContractError::Unauthorized {}) => {} - _ => panic!("Must return unauthorized error"), - } - - // only the original creator can reset the counter - let auth_info = mock_info("creator", &coins(2, "token")); - let msg = ExecuteMsg::Reset { count: 5 }; - let _res = execute(deps.as_mut(), mock_env(), auth_info, msg).unwrap(); - - // should now be 5 - let res = query(deps.as_ref(), mock_env(), QueryMsg::GetCount {}).unwrap(); - let value: GetCountResponse = from_json(&res).unwrap(); - assert_eq!(5, value.count); } } diff --git a/src/helpers.rs b/src/helpers.rs index 6d988cc..95fbc39 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -6,7 +6,7 @@ use cosmwasm_std::{ WasmQuery, }; -use crate::msg::{ExecuteMsg, GetCountResponse, QueryMsg}; +use crate::msg::{ExecuteMsg, QueryMsg}; /// CwTemplateContract is a wrapper around Addr that provides a lot of helpers /// for working with this. @@ -27,21 +27,4 @@ impl CwTemplateContract { } .into()) } - - /// Get Count - pub fn count(&self, querier: &Q) -> StdResult - where - Q: Querier, - T: Into, - CQ: CustomQuery, - { - let msg = QueryMsg::GetCount {}; - let query = WasmQuery::Smart { - contract_addr: self.addr().into(), - msg: to_json_binary(&msg)?, - } - .into(); - let res: GetCountResponse = QuerierWrapper::::new(querier).query(&query)?; - Ok(res) - } } diff --git a/src/integration_tests.rs b/src/integration_tests.rs index 4c50784..b3a853a 100644 --- a/src/integration_tests.rs +++ b/src/integration_tests.rs @@ -38,7 +38,7 @@ mod tests { let mut app = mock_app(); let cw_template_id = app.store_code(contract_template()); - let msg = InstantiateMsg { count: 1i32 }; + let msg = InstantiateMsg {}; let cw_template_contract_addr = app .instantiate_contract( cw_template_id, @@ -63,7 +63,6 @@ mod tests { fn count() { let (mut app, cw_template_contract) = proper_instantiate(); - let msg = ExecuteMsg::Increment {}; let cosmos_msg = cw_template_contract.call(msg).unwrap(); app.execute(Addr::unchecked(USER), cosmos_msg).unwrap(); } diff --git a/src/msg.rs b/src/msg.rs index 460d206..90c6e5e 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -2,14 +2,10 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Binary}; #[cw_serde] -pub struct InstantiateMsg { - pub count: i32, -} +pub struct InstantiateMsg {} #[cw_serde] pub enum ExecuteMsg { - Increment {}, - Reset { count: i32 }, ReceiveNft { sender: String, token_id: String, @@ -24,10 +20,6 @@ pub enum ExecuteMsg { #[cw_serde] #[derive(QueryResponses)] pub enum QueryMsg { - // GetCount returns the current count as a json-encoded number - #[returns(GetCountResponse)] - GetCount {}, - #[returns(AllNftsResponse)] GetAllNfts {}, @@ -35,12 +27,6 @@ pub enum QueryMsg { GetNftContractAddr {}, } -// We define a custom struct for each query response -#[cw_serde] -pub struct GetCountResponse { - pub count: i32, -} - #[cw_serde] pub struct AllNftsResponse { pub nfts: Vec, diff --git a/src/state.rs b/src/state.rs index b88cb87..105be50 100644 --- a/src/state.rs +++ b/src/state.rs @@ -6,7 +6,6 @@ use cw_storage_plus::Item; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct State { - pub count: i32, pub owner: Addr, }