diff --git a/src/campaign.cairo b/src/campaign.cairo index 5eb2d6b..310b7d7 100644 --- a/src/campaign.cairo +++ b/src/campaign.cairo @@ -1,7 +1,7 @@ use starknet::ContractAddress; -#[starknet::component] -mod CampaignComponent { +#[starknet::contract] +mod TokengiverC { // ************************************************************************* // IMPORT // ************************************************************************* @@ -53,12 +53,10 @@ mod CampaignComponent { // ************************************************************************* // EXTERNAL FUNCTIONS // ************************************************************************* - #[embeddable_as(TokenGiverCampaign)] - impl CampaignImpl< - TContractState, +HasComponent - > of ICampaign> { + #[external(v0)] + impl CampaignImpl of ICampaign { fn create_campaign( - ref self: ComponentState, + ref self: ContractState, token_giverNft_contract_address: ContractAddress, registry_hash: felt252, implementation_hash: felt252, @@ -94,9 +92,7 @@ mod CampaignComponent { /// @params campaign_address the targeted campaign address /// @params metadata_uri the campaign CID fn set_campaign_metadata_uri( - ref self: ComponentState, - campaign_address: ContractAddress, - metadata_uri: ByteArray + ref self: ContractState, campaign_address: ContractAddress, metadata_uri: ByteArray ) { let mut campaign: Campaign = self.campaign.read(campaign_address); assert(get_caller_address() == campaign.campaign_owner, NOT_CAMPAIGN_OWNER); @@ -105,25 +101,17 @@ mod CampaignComponent { } - fn set_donation_count( - ref self: ComponentState, campaign_address: ContractAddress - ) { + fn set_donation_count(ref self: ContractState, campaign_address: ContractAddress) { let prev_count: u16 = self.donation_count.read(campaign_address); self.donation_count.write(campaign_address, prev_count + 1); } - fn set_donations( - ref self: ComponentState, - campaign_address: ContractAddress, - amount: u256 - ) { + fn set_donations(ref self: ContractState, campaign_address: ContractAddress, amount: u256) { self.donations.write(campaign_address, amount); } fn set_available_withdrawal( - ref self: ComponentState, - campaign_address: ContractAddress, - amount: u256 + ref self: ContractState, campaign_address: ContractAddress, amount: u256 ) { self.withdrawal_balance.write(campaign_address, amount); } @@ -132,13 +120,11 @@ mod CampaignComponent { // GETTERS // ************************************************************************* - fn get_donations( - self: @ComponentState, campaign_address: ContractAddress - ) -> u256 { + fn get_donations(self: @ContractState, campaign_address: ContractAddress) -> u256 { self.donations.read(campaign_address) } fn get_available_withdrawal( - self: @ComponentState, campaign_address: ContractAddress + self: @ContractState, campaign_address: ContractAddress ) -> u256 { self.withdrawal_balance.read(campaign_address) } @@ -146,57 +132,49 @@ mod CampaignComponent { // @notice returns the campaign struct of a campaign address // @params campaign_address the targeted campaign address - fn get_campaign( - self: @ComponentState, campaign_address: ContractAddress - ) -> Campaign { + fn get_campaign(self: @ContractState, campaign_address: ContractAddress) -> Campaign { self.campaign.read(campaign_address) } fn get_campaign_metadata( - self: @ComponentState, campaign_address: ContractAddress + self: @ContractState, campaign_address: ContractAddress ) -> ByteArray { let campaign: Campaign = self.campaign.read(campaign_address); campaign.metadata_URI } - fn get_campaigns(self: @ComponentState) -> Array { + fn get_campaigns(self: @ContractState) -> Array { let mut campaigns = ArrayTrait::new(); let count = self.count.read(); let mut i: u16 = 1; - while i < count - + 1 { - let campaignAddress: ContractAddress = self.campaigns.read(i); - let campaign: Campaign = self.campaign.read(campaignAddress); - campaigns.append(campaign.metadata_URI); - i += 1; - }; + while i < count + 1 { + let campaignAddress: ContractAddress = self.campaigns.read(i); + let campaign: Campaign = self.campaign.read(campaignAddress); + campaigns.append(campaign.metadata_URI); + i += 1; + }; campaigns } - fn get_user_campaigns( - self: @ComponentState, user: ContractAddress - ) -> Array { + fn get_user_campaigns(self: @ContractState, user: ContractAddress) -> Array { let mut campaigns = ArrayTrait::new(); let count = self.count.read(); let mut i: u16 = 1; - while i < count - + 1 { - let campaignAddress: ContractAddress = self.campaigns.read(i); - let campaign: Campaign = self.campaign.read(campaignAddress); - if campaign.campaign_owner == user { - campaigns.append(campaign.metadata_URI); - } - i += 1; - }; + while i < count + 1 { + let campaignAddress: ContractAddress = self.campaigns.read(i); + let campaign: Campaign = self.campaign.read(campaignAddress); + if campaign.campaign_owner == user { + campaigns.append(campaign.metadata_URI); + } + i += 1; + }; campaigns } - fn get_donation_count( - self: @ComponentState, campaign_address: ContractAddress - ) -> u16 { + fn get_donation_count(self: @ContractState, campaign_address: ContractAddress) -> u16 { self.donation_count.read(campaign_address) } } diff --git a/src/presets/campaign.cairo b/src/presets/campaign.cairo index 2c46b66..dcccfcf 100644 --- a/src/presets/campaign.cairo +++ b/src/presets/campaign.cairo @@ -1,23 +1,23 @@ -#[starknet::contract] -mod TokenGiverCampaign { - use starknet::{ContractAddress, get_caller_address}; - use tokengiver::campaign::CampaignComponent; +// #[starknet::contract] +// mod TokenGiverCampaign { +// use starknet::{ContractAddress, get_caller_address}; +// use tokengiver::campaign::CampaignComponent; - component!(path: CampaignComponent, storage: campaign, event: CampaignEvent); +// component!(path: CampaignComponent, storage: campaign, event: CampaignEvent); - #[abi(embed_v0)] - impl CampaignImpl = CampaignComponent::TokenGiverCampaign; +// #[abi(embed_v0)] +// impl CampaignImpl = CampaignComponent::TokenGiverCampaign; - #[storage] - struct Storage { - #[substorage(v0)] - campaign: CampaignComponent::Storage - } +// #[storage] +// struct Storage { +// #[substorage(v0)] +// campaign: CampaignComponent::Storage +// } - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - CampaignEvent: CampaignComponent::Event - } -} +// #[event] +// #[derive(Drop, starknet::Event)] +// enum Event { +// #[flat] +// CampaignEvent: CampaignComponent::Event +// } +// }