lib.rs
1 use candid::Principal; 2 use ic_cdk::api; 3 use ic_cdk_macros::*; 4 use ic_stable_structures::{ 5 memory_manager::{MemoryId, MemoryManager, VirtualMemory}, 6 {DefaultMemoryImpl, StableBTreeMap}, 7 }; 8 use interface::{ 9 item::ItemId, 10 market::{ 11 MarketDataForHomeFirstLoadArgs, MarketDataForHomeFirstLoadResult, MarketDataResult, 12 MarketId, 13 }, 14 }; 15 use std::cell::RefCell; 16 17 mod actor; 18 mod item; 19 mod log; 20 mod market; 21 mod store; 22 mod tag; 23 mod test_init; 24 25 use actor::Actor; 26 use item::Item; 27 use market::Market; 28 use store::Store; 29 use tag::Tag; 30 31 type Memory = VirtualMemory<DefaultMemoryImpl>; 32 33 thread_local! { 34 static MEMORY_MANAGER: RefCell<MemoryManager<DefaultMemoryImpl>> = 35 RefCell::new(MemoryManager::init(DefaultMemoryImpl::default())); 36 37 38 pub static ACTORS: RefCell<StableBTreeMap<String, Actor, Memory>> = RefCell::new( 39 StableBTreeMap::init( 40 MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(2))), 41 ) 42 ); 43 44 pub static ITEMS: RefCell<StableBTreeMap<ItemId, Item, Memory>> = RefCell::new( 45 StableBTreeMap::init( 46 MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(3))), 47 ) 48 ); 49 50 pub static STORES: RefCell<StableBTreeMap<u128, Store, Memory>> = RefCell::new( 51 StableBTreeMap::init( 52 MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(4))), 53 ) 54 ); 55 56 pub static MARKETS: RefCell<StableBTreeMap<MarketId, Market, Memory>> = RefCell::new( 57 StableBTreeMap::init( 58 MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(5))), 59 ) 60 ); 61 62 pub static TAGS: RefCell<StableBTreeMap<u128, Tag, Memory>> = RefCell::new( 63 StableBTreeMap::init( 64 MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(6))), 65 ) 66 ); 67 } 68 69 #[update] 70 fn test_init() { 71 test_init::test_init(); 72 } 73 74 #[query] 75 fn get_item_page_info( 76 arg: interface::item::ItemPageArgs, 77 ) -> Option<interface::item::ItemPageResult> { 78 item::get_item_page_info(&arg) 79 } 80 81 #[query] 82 fn get_item_core_data_vec( 83 args: Vec<interface::item::ItemCoreDataArgs>, 84 ) -> Vec<Option<interface::item::ItemCoreDataResult>> { 85 item::get_item_core_data_vec(args) 86 } 87 88 #[query] 89 fn get_markets(market_ids: Vec<MarketId>) -> Vec<MarketDataResult> { 90 market::get_markets(market_ids) 91 } 92 93 #[query] 94 fn get_markets_for_home_first_load( 95 arg: MarketDataForHomeFirstLoadArgs, 96 ) -> Vec<MarketDataForHomeFirstLoadResult> { 97 market::get_markets_for_home_first_load(arg) 98 } 99 100 #[query] 101 fn whoami() -> Principal { 102 api::caller() 103 } 104 105 #[update] 106 async fn get_trusted_origins() -> Vec<String> { 107 vec![ 108 // Origins should be in the format defined by the Window.postMessage method (https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#the_dispatched_event) 109 String::from("https://anthol.net"), 110 String::from("https://www.anthol.net"), 111 String::from("https://qqyox-jyaaa-aaaap-abtwa-cai.icp0.io/"), 112 ] 113 } 114 115 ic_cdk::export_candid!();