-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathlib.rs
More file actions
76 lines (67 loc) · 2.27 KB
/
Copy pathlib.rs
File metadata and controls
76 lines (67 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
pub mod api_paged_response;
pub mod api_query;
pub mod error;
mod indexer;
use std::{path::PathBuf, sync::Arc};
pub use api::ocean_router;
pub use indexer::{BlockV2Info, index_block, invalidate_block};
use repository::{
AuctionHistoryByHeightRepository, AuctionHistoryRepository, BlockByHeightRepository,
BlockRepository, MasternodeByHeightRepository, MasternodeRepository, MasternodeStatsRepository,
RawBlockRepository,
};
pub mod api;
mod model;
mod repository;
pub mod storage;
use crate::storage::ocean_store::OceanStore;
pub(crate) type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
lazy_static::lazy_static! {
// Global services exposed by the library
pub static ref SERVICES: Services = {
let datadir = ain_cpp_imports::get_datadir();
let store = OceanStore::new(&PathBuf::from(datadir)).expect("Error initialization Ocean storage");
Services::new(
Arc::new(store)
)
};
}
pub struct MasternodeService {
by_id: MasternodeRepository,
by_height: MasternodeByHeightRepository,
stats: MasternodeStatsRepository,
}
pub struct BlockService {
raw: RawBlockRepository,
by_id: BlockRepository,
by_height: BlockByHeightRepository,
}
pub struct AuctionService {
by_id: AuctionHistoryRepository,
by_height: AuctionHistoryByHeightRepository,
}
pub struct Services {
masternode: MasternodeService,
block: BlockService,
auction: AuctionService,
}
impl Services {
fn new(store: Arc<OceanStore>) -> Self {
Self {
masternode: MasternodeService {
by_id: MasternodeRepository::new(Arc::clone(&store)),
by_height: MasternodeByHeightRepository::new(Arc::clone(&store)),
stats: MasternodeStatsRepository::new(Arc::clone(&store)),
},
block: BlockService {
raw: RawBlockRepository::new(Arc::clone(&store)),
by_id: BlockRepository::new(Arc::clone(&store)),
by_height: BlockByHeightRepository::new(Arc::clone(&store)),
},
auction: AuctionService {
by_id: AuctionHistoryRepository::new(Arc::clone(&store)),
by_height: AuctionHistoryByHeightRepository::new(Arc::clone(&store)),
},
}
}
}