Skip to content

Commit

Permalink
interface separation
Browse files Browse the repository at this point in the history
  • Loading branch information
eddnewgate committed Aug 11, 2024
1 parent e11473d commit 9402205
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
38 changes: 38 additions & 0 deletions src/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use starknet::ContractAddress;

#[starknet::interface]
pub trait IPushComm<TContractState> {
// Push Admin
fn complete_migration(ref self: TContractState);
fn get_migration_status(self: @TContractState) -> bool;
fn set_push_core_address(ref self: TContractState, core_address: felt252);
fn get_push_core_address(self: @TContractState) -> felt252;
fn get_push_governance_address(self: @TContractState) -> felt252;
fn set_push_governance_address(ref self: TContractState, governance_address: felt252);
fn get_push_token_address(self: @TContractState) -> felt252;
fn set_push_token_address(ref self: TContractState, push_token_address: felt252);
// Channel
fn verify_channel_alias(ref self: TContractState, channel_address: felt252);
fn add_delegate(ref self: TContractState, delegate: ContractAddress);
fn remove_delegate(ref self: TContractState, delegate: ContractAddress);
fn send_notification(
ref self: TContractState,
channel: ContractAddress,
recipient: ContractAddress,
identity: ByteArray
) -> bool;
fn change_user_channel_settings(
ref self: TContractState,
channel: ContractAddress,
notif_id: u256,
notif_settings: ByteArray
);
// User
fn is_user_subscribed(
self: @TContractState, channel: ContractAddress, user: ContractAddress
) -> bool;
fn subscribe(ref self: TContractState, channel: ContractAddress);
fn unsubscribe(ref self: TContractState, channel: ContractAddress);
fn batch_subscribe(ref self: TContractState, channels: Array<ContractAddress>);
fn batch_unsubscribe(ref self: TContractState, channels: Array<ContractAddress>);
}
40 changes: 4 additions & 36 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
pub mod interface;

use starknet::ContractAddress;
pub use interface::IPushComm;

#[starknet::interface]
pub trait IPushComm<TContractState> {
// Push Admin
fn complete_migration(ref self: TContractState);
fn get_migration_status(self: @TContractState) -> bool;
fn set_push_core_address(ref self: TContractState, core_address: felt252);
fn get_push_core_address(self: @TContractState) -> felt252;
fn get_push_governance_address(self: @TContractState) -> felt252;
fn set_push_governance_address(ref self: TContractState, governance_address: felt252);
fn get_push_token_address(self: @TContractState) -> felt252;
fn set_push_token_address(ref self: TContractState, push_token_address: felt252);
// Channel
fn verify_channel_alias(ref self: TContractState, channel_address: felt252);
fn add_delegate(ref self: TContractState, delegate: ContractAddress);
fn remove_delegate(ref self: TContractState, delegate: ContractAddress);
fn send_notification(
ref self: TContractState,
channel: ContractAddress,
recipient: ContractAddress,
identity: ByteArray
) -> bool;
fn change_user_channel_settings(
ref self: TContractState,
channel: ContractAddress,
notif_id: u256,
notif_settings: ByteArray
);
// User
fn is_user_subscribed(
self: @TContractState, channel: ContractAddress, user: ContractAddress
) -> bool;
fn subscribe(ref self: TContractState, channel: ContractAddress);
fn unsubscribe(ref self: TContractState, channel: ContractAddress);
fn batch_subscribe(ref self: TContractState, channels: Array<ContractAddress>);
fn batch_unsubscribe(ref self: TContractState, channels: Array<ContractAddress>);
}

#[starknet::contract]
pub mod PushComm {
Expand All @@ -50,6 +17,7 @@ pub mod PushComm {
use core::starknet::storage::StoragePointerWriteAccess;
use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess};
use starknet::{ContractAddress, get_caller_address};
use starknet::{get_execution_info};
use openzeppelin::access::ownable::OwnableComponent;

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_channel_alias.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use snforge_std::{
declare, ContractClassTrait, cheat_caller_address, CheatSpan, spy_events,
EventSpyAssertionsTrait, Event, EventSpyTrait
};
use push_comm::{PushComm, IPushCommDispatcher, IPushCommDispatcherTrait};
use push_comm::{PushComm, interface::IPushCommDispatcher, interface::IPushCommDispatcherTrait};
use super::common::{USER_1, deploy_contract, CHAIN_NAME, CHAIN_ID};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_push_admin.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use starknet::ContractAddress;

use snforge_std::{declare, ContractClassTrait, cheat_caller_address, CheatSpan, spy_events};
use push_comm::{IPushCommDispatcher, IPushCommDispatcherTrait};
use push_comm::interface::{IPushCommDispatcher, IPushCommDispatcherTrait};
use super::common::{PUSH_ADMIN, deploy_contract};

#[test]
Expand Down

0 comments on commit 9402205

Please sign in to comment.