Skip to content

Commit

Permalink
fix: Marketing: remove collection stuff from contract, cargo check
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Oct 3, 2024
1 parent 00c98fc commit adf1db5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 119 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 2 additions & 117 deletions rust/cw-contracts/marketing/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Banner {
}

#[cw_serde]
pub struct Action {
pub struct NewsAction {
pub label: String,
pub url: String,
}
Expand All @@ -25,17 +25,7 @@ pub struct News {
pub subtitle: String,
pub text: String,
pub image: String,
pub actions: Option<Vec<Action>>,
}

#[cw_serde]
pub struct MarketingCollectionPreview {
pub address: String,
pub image_uri: String,
pub collection_name: String,
pub creator_name: String,
pub twitter_url: String,
pub secondary_during_mint: bool,
pub actions: Option<Vec<NewsAction>>,
}

#[cw_serde]
Expand All @@ -47,9 +37,6 @@ pub struct MarketingContract {
pub(crate) config: Item<'static, Config>,
pub(crate) banners: Map<'static, u64, Banner>,
pub(crate) news: Map<'static, u64, News>,
pub(crate) upcoming_collections: Map<'static, u64, MarketingCollectionPreview>,
pub(crate) live_collections: Map<'static, u64, MarketingCollectionPreview>,
pub(crate) highlighted_collections: Map<'static, u64, MarketingCollectionPreview>,
}

#[entry_points]
Expand All @@ -61,9 +48,6 @@ impl MarketingContract {
config: Item::new("config"),
banners: Map::new("banners"),
news: Map::new("news"),
upcoming_collections: Map::new("upcoming_collections"),
live_collections: Map::new("live_collections"),
highlighted_collections: Map::new("highlighted_collections"),
}
}

Expand Down Expand Up @@ -142,72 +126,6 @@ impl MarketingContract {
Ok(Response::new().add_attributes(attributes))
}

#[msg(exec)]
// Only the admin can execute it
pub fn update_live_collections(
&self,
ctx: ExecCtx,
live_collections: Vec<MarketingCollectionPreview>,
) -> Result<Response, ContractError> {
let attributes = vec![attr("action", "update_live_collections")];
let config = self.config.load(ctx.deps.storage)?;
// Permission check
if ctx.info.sender != config.admin_addr {
return Err(ContractError::Unauthorized);
}
// Replace all live_collections with the new ones
self.live_collections.clear(ctx.deps.storage);
for (index, live_collection) in live_collections.into_iter().enumerate() {
self.live_collections.save(ctx.deps.storage, index as u64, &live_collection)?;
}

Ok(Response::new().add_attributes(attributes))
}

#[msg(exec)]
// Only the admin can execute it
pub fn update_upcoming_collections(
&self,
ctx: ExecCtx,
upcoming_collections: Vec<MarketingCollectionPreview>,
) -> Result<Response, ContractError> {
let attributes = vec![attr("action", "update_upcoming_collections")];
let config = self.config.load(ctx.deps.storage)?;
// Permission check
if ctx.info.sender != config.admin_addr {
return Err(ContractError::Unauthorized);
}
// Replace all upcoming_collections with the new ones
self.upcoming_collections.clear(ctx.deps.storage);
for (index, upcoming_collection) in upcoming_collections.into_iter().enumerate() {
self.upcoming_collections.save(ctx.deps.storage, index as u64, &upcoming_collection)?;
}

Ok(Response::new().add_attributes(attributes))
}

#[msg(exec)]
// Only the admin can execute it
pub fn update_highlighted_collections(
&self,
ctx: ExecCtx,
highlighted_collections: Vec<MarketingCollectionPreview>,
) -> Result<Response, ContractError> {
let attributes = vec![attr("action", "update_highlighted_collections")];
let config = self.config.load(ctx.deps.storage)?;
// Permission check
if ctx.info.sender != config.admin_addr {
return Err(ContractError::Unauthorized);
}
// Replace all highlighted_collections with the new ones
self.highlighted_collections.clear(ctx.deps.storage);
for (index, highlighted_collection) in highlighted_collections.into_iter().enumerate() {
self.highlighted_collections.save(ctx.deps.storage, index as u64, &highlighted_collection)?;
}

Ok(Response::new().add_attributes(attributes))
}

#[msg(query)]
pub fn get_config(&self, ctx: QueryCtx) -> StdResult<Config> {
let config = self.config.load(ctx.deps.storage)?;
Expand Down Expand Up @@ -235,39 +153,6 @@ impl MarketingContract {

Ok(news)
}

#[msg(query)]
pub fn get_live_collections(&self, ctx: QueryCtx) -> StdResult<Vec<MarketingCollectionPreview>> {
let live_collections: Vec<MarketingCollectionPreview> = self
.live_collections
.range(ctx.deps.storage, None, None, cosmwasm_std::Order::Ascending)
.map(|item| item.map(|(_, live_collection)| live_collection))
.collect::<StdResult<Vec<MarketingCollectionPreview>>>()?;

Ok(live_collections)
}

#[msg(query)]
pub fn get_upcoming_collections(&self, ctx: QueryCtx) -> StdResult<Vec<MarketingCollectionPreview>> {
let upcoming_collections: Vec<MarketingCollectionPreview> = self
.upcoming_collections
.range(ctx.deps.storage, None, None, cosmwasm_std::Order::Ascending)
.map(|item| item.map(|(_, upcoming_collection)| upcoming_collection))
.collect::<StdResult<Vec<MarketingCollectionPreview>>>()?;

Ok(upcoming_collections)
}

#[msg(query)]
pub fn get_highlighted_collections(&self, ctx: QueryCtx) -> StdResult<Vec<MarketingCollectionPreview>> {
let highlighted_collections: Vec<MarketingCollectionPreview> = self
.highlighted_collections
.range(ctx.deps.storage, None, None, cosmwasm_std::Order::Ascending)
.map(|item| item.map(|(_, highlighted_collection)| highlighted_collection))
.collect::<StdResult<Vec<MarketingCollectionPreview>>>()?;

Ok(highlighted_collections)
}
}


4 changes: 2 additions & 2 deletions rust/cw-contracts/marketing/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sylvia::multitest::App;

use crate::contract::{multitest_utils::CodeId, Action, News};
use crate::contract::{multitest_utils::CodeId, NewsAction, News};
use crate::error::ContractError;

#[test]
Expand All @@ -13,7 +13,7 @@ fn basic_full_flow() {
let contract_creator = "creator";
let unauthorized_sender = "unauthorized_sender";

let action = Action {
let action = NewsAction {
label: "".to_string(),
url: "".to_string()
};
Expand Down

0 comments on commit adf1db5

Please sign in to comment.