Skip to content

Commit e2071ac

Browse files
authored
refactor(agent): rename adapter->state (#124)
* refactor(agent): move adapter out of pythd * refactor(agent): fix adapter imports * refactor(agent): rename adapter->state
1 parent c5a717e commit e2071ac

18 files changed

+91
-104
lines changed

src/agent.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ pub mod metrics;
6969
pub mod pythd;
7070
pub mod remote_keypair_loader;
7171
pub mod solana;
72+
pub mod state;
7273
pub mod store;
7374
use {
7475
self::{
7576
config::Config,
76-
pythd::{
77-
adapter::notifier,
78-
api::rpc,
79-
},
77+
pythd::api::rpc,
8078
solana::network,
79+
state::notifier,
8180
},
8281
anyhow::Result,
8382
futures_util::future::join_all,
@@ -122,9 +121,8 @@ impl Agent {
122121
let (secondary_keypair_loader_tx, secondary_keypair_loader_rx) = mpsc::channel(10);
123122

124123
// Create the Pythd Adapter.
125-
let adapter = Arc::new(
126-
pythd::adapter::Adapter::new(self.config.pythd_adapter.clone(), logger.clone()).await,
127-
);
124+
let adapter =
125+
Arc::new(state::State::new(self.config.pythd_adapter.clone(), logger.clone()).await);
128126

129127
// Spawn the primary network
130128
jhs.extend(network::spawn_network(
@@ -197,6 +195,7 @@ pub mod config {
197195
pythd,
198196
remote_keypair_loader,
199197
solana::network,
198+
state,
200199
},
201200
anyhow::Result,
202201
config as config_rs,
@@ -216,7 +215,7 @@ pub mod config {
216215
pub primary_network: network::Config,
217216
pub secondary_network: Option<network::Config>,
218217
#[serde(default)]
219-
pub pythd_adapter: pythd::adapter::Config,
218+
pub pythd_adapter: state::Config,
220219
#[serde(default)]
221220
pub pythd_api_server: pythd::api::rpc::Config,
222221
#[serde(default)]

src/agent/dashboard.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use {
22
super::{
3-
pythd::adapter::{
3+
solana::{
4+
network::Network,
5+
oracle::PriceEntry,
6+
},
7+
state::{
48
global::GlobalStore,
59
local::{
610
LocalStore,
711
PriceInfo,
812
},
913
},
10-
solana::{
11-
network::Network,
12-
oracle::PriceEntry,
13-
},
1414
},
1515
crate::agent::{
1616
metrics::MetricsServer,
17-
pythd::adapter::global::{
17+
state::global::{
1818
AllAccountsData,
1919
AllAccountsMetadata,
2020
PriceAccountMetadata,

src/agent/metrics.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use {
2-
super::pythd::adapter::{
2+
super::state::{
33
local::PriceInfo,
4-
Adapter,
4+
State,
55
},
66
crate::agent::{
77
solana::oracle::PriceEntry,
@@ -69,16 +69,12 @@ lazy_static! {
6969
pub struct MetricsServer {
7070
pub start_time: Instant,
7171
pub logger: Logger,
72-
pub adapter: Arc<Adapter>,
72+
pub adapter: Arc<State>,
7373
}
7474

7575
impl MetricsServer {
7676
/// Instantiate a metrics API with a dashboard
77-
pub async fn spawn(
78-
addr: impl Into<SocketAddr> + 'static,
79-
logger: Logger,
80-
adapter: Arc<Adapter>,
81-
) {
77+
pub async fn spawn(addr: impl Into<SocketAddr> + 'static, logger: Logger, adapter: Arc<State>) {
8278
let server = MetricsServer {
8379
start_time: Instant::now(),
8480
logger,

src/agent/pythd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
pub mod adapter;
21
pub mod api;

src/agent/pythd/api/rpc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use {
88
super::{
9-
super::adapter,
109
Conf,
1110
NotifyPrice,
1211
NotifyPriceSched,
1312
Price,
1413
Pubkey,
1514
SubscriptionID,
1615
},
16+
crate::agent::state,
1717
anyhow::{
1818
anyhow,
1919
Result,
@@ -120,7 +120,7 @@ async fn handle_connection<S>(
120120
notify_price_sched_tx_buffer: usize,
121121
logger: Logger,
122122
) where
123-
S: adapter::AdapterApi,
123+
S: state::StateApi,
124124
S: Send,
125125
S: Sync,
126126
S: 'static,
@@ -168,7 +168,7 @@ async fn handle_next<S>(
168168
notify_price_sched_rx: &mut mpsc::Receiver<NotifyPriceSched>,
169169
) -> Result<()>
170170
where
171-
S: adapter::AdapterApi,
171+
S: state::StateApi,
172172
{
173173
tokio::select! {
174174
msg = ws_rx.next() => {
@@ -210,7 +210,7 @@ async fn handle<S>(
210210
msg: Message,
211211
) -> Result<()>
212212
where
213-
S: adapter::AdapterApi,
213+
S: state::StateApi,
214214
{
215215
// Ignore control and binary messages
216216
if !msg.is_text() {
@@ -296,7 +296,7 @@ async fn dispatch_and_catch_error<S>(
296296
request: &Request<Method, Value>,
297297
) -> Response<serde_json::Value>
298298
where
299-
S: adapter::AdapterApi,
299+
S: state::StateApi,
300300
{
301301
debug!(
302302
logger,
@@ -436,7 +436,7 @@ pub async fn run<S>(
436436
adapter: Arc<S>,
437437
shutdown_rx: broadcast::Receiver<()>,
438438
) where
439-
S: adapter::AdapterApi,
439+
S: state::StateApi,
440440
S: Send,
441441
S: Sync,
442442
S: 'static,
@@ -454,7 +454,7 @@ async fn serve<S>(
454454
mut shutdown_rx: broadcast::Receiver<()>,
455455
) -> Result<()>
456456
where
457-
S: adapter::AdapterApi,
457+
S: state::StateApi,
458458
S: Send,
459459
S: Sync,
460460
S: 'static,

src/agent/pythd/api/rpc/get_all_products.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use {
2-
crate::agent::pythd::adapter,
2+
crate::agent::state,
33
anyhow::Result,
44
};
55

66
pub async fn get_all_products<S>(adapter: &S) -> Result<serde_json::Value>
77
where
8-
S: adapter::AdapterApi,
8+
S: state::StateApi,
99
{
1010
let products = adapter.get_all_products().await?;
1111
Ok(serde_json::to_value(products)?)

src/agent/pythd/api/rpc/get_product.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use {
33
GetProductParams,
44
Method,
55
},
6-
crate::agent::pythd::adapter,
6+
crate::agent::state,
77
anyhow::{
88
anyhow,
99
Result,
@@ -19,7 +19,7 @@ pub async fn get_product<S>(
1919
request: &Request<Method, Value>,
2020
) -> Result<serde_json::Value>
2121
where
22-
S: adapter::AdapterApi,
22+
S: state::StateApi,
2323
{
2424
let params: GetProductParams = {
2525
let value = request.params.clone();

src/agent/pythd/api/rpc/get_product_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use {
2-
crate::agent::pythd::adapter,
2+
crate::agent::state,
33
anyhow::Result,
44
};
55

66
pub async fn get_product_list<S>(adapter: &S) -> Result<serde_json::Value>
77
where
8-
S: adapter::AdapterApi,
8+
S: state::StateApi,
99
{
1010
let product_list = adapter.get_product_list().await?;
1111
Ok(serde_json::to_value(product_list)?)

src/agent/pythd/api/rpc/subscribe_price.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
SubscribePriceParams,
66
SubscribeResult,
77
},
8-
crate::agent::pythd::adapter,
8+
crate::agent::state,
99
anyhow::{
1010
anyhow,
1111
Result,
@@ -23,7 +23,7 @@ pub async fn subscribe_price<S>(
2323
request: &Request<Method, Value>,
2424
) -> Result<serde_json::Value>
2525
where
26-
S: adapter::AdapterApi,
26+
S: state::StateApi,
2727
{
2828
let params: SubscribePriceParams = serde_json::from_value(
2929
request

src/agent/pythd/api/rpc/subscribe_price_sched.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
SubscribePriceSchedParams,
66
SubscribeResult,
77
},
8-
crate::agent::pythd::adapter,
8+
crate::agent::state,
99
anyhow::{
1010
anyhow,
1111
Result,
@@ -23,7 +23,7 @@ pub async fn subscribe_price_sched<S>(
2323
request: &Request<Method, Value>,
2424
) -> Result<serde_json::Value>
2525
where
26-
S: adapter::AdapterApi,
26+
S: state::StateApi,
2727
{
2828
let params: SubscribePriceSchedParams = serde_json::from_value(
2929
request

0 commit comments

Comments
 (0)