-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathlib.rs
More file actions
115 lines (101 loc) · 3.55 KB
/
Copy pathlib.rs
File metadata and controls
115 lines (101 loc) · 3.55 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
pub mod api_query;
pub mod error;
mod indexer;
use std::{path::PathBuf, sync::Arc};
pub use api::ocean_router;
use error::OceanError;
pub use indexer::{
index_block, invalidate_block,
transaction::{
index_transaction, invalidate_transaction, invalidate_transaction_vin,
invalidate_transaction_vout,
},
tx_result, BlockV2Info,
};
use repository::{
AuctionHistoryByHeightRepository, AuctionHistoryRepository, BlockByHeightRepository,
BlockRepository, MasternodeByHeightRepository, MasternodeRepository, MasternodeStatsRepository,
PoolSwapRepository, RawBlockRepository, TransactionRepository, TransactionVinRepository,
TransactionVoutRepository, TxResultRepository,
};
pub mod api;
mod model;
mod repository;
pub mod storage;
use defichain_rpc::{Auth, Client};
use crate::storage::ocean_store::OceanStore;
pub type Result<T> = std::result::Result<T, OceanError>;
lazy_static::lazy_static! {
// Global services exposed by the library
pub static ref SERVICES: Services = {
Services::new().expect("Error initialization Ocean services")
};
}
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 PoolService {
by_id: PoolSwapRepository,
}
pub struct TransactionService {
by_id: TransactionRepository,
vin_by_id: TransactionVinRepository,
vout_by_id: TransactionVoutRepository,
}
pub struct Services {
masternode: MasternodeService,
block: BlockService,
auction: AuctionService,
result: TxResultRepository,
pool: PoolService,
client: Arc<Client>,
transaction: TransactionService,
}
impl Services {
fn new() -> Result<Self> {
let datadir = ain_cpp_imports::get_datadir();
let store = Arc::new(OceanStore::new(&PathBuf::from(datadir))?);
let (user, pass) = ain_cpp_imports::get_rpc_auth()?;
let client = Arc::new(Client::new(
&format!("localhost:{}", ain_cpp_imports::get_rpc_port()),
Auth::UserPass(user, pass),
)?);
Ok(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)),
},
result: TxResultRepository::new(Arc::clone(&store)),
pool: PoolService {
by_id: PoolSwapRepository::new(Arc::clone(&store)),
},
transaction: TransactionService {
by_id: TransactionRepository::new(Arc::clone(&store)),
vin_by_id: TransactionVinRepository::new(Arc::clone(&store)),
vout_by_id: TransactionVoutRepository::new(Arc::clone(&store)),
},
client,
})
}
}