solana-accountsdb-connector/connector-lib/src/main.rs

56 lines
1.3 KiB
Rust
Raw Normal View History

2021-11-01 13:48:17 -07:00
mod grpc_plugin_source;
2021-11-02 00:55:39 -07:00
mod postgres_target;
2021-11-01 13:48:17 -07:00
mod websocket_source;
2021-11-01 02:34:25 -07:00
2021-11-01 13:48:17 -07:00
use solana_sdk::pubkey::Pubkey;
2021-11-02 00:55:39 -07:00
use log::*;
2021-11-01 02:34:25 -07:00
trait AnyhowWrap {
type Value;
fn map_err_anyhow(self) -> anyhow::Result<Self::Value>;
}
impl<T, E: std::fmt::Debug> AnyhowWrap for Result<T, E> {
type Value = T;
fn map_err_anyhow(self) -> anyhow::Result<Self::Value> {
self.map_err(|err| anyhow::anyhow!("{:?}", err))
}
}
#[derive(Clone, PartialEq, Debug)]
pub struct AccountWrite {
pub pubkey: Pubkey,
pub slot: i64,
pub write_version: i64,
pub lamports: i64,
pub owner: Pubkey,
pub executable: bool,
pub rent_epoch: i64,
pub data: Vec<u8>,
}
#[derive(Clone, PartialEq, Debug)]
2021-11-01 13:48:17 -07:00
pub struct SlotUpdate {
pub slot: i64,
pub parent: Option<i64>,
pub status: String,
2021-11-01 02:34:25 -07:00
}
#[tokio::main]
async fn main() {
2021-11-02 04:54:39 -07:00
solana_logger::setup_with_default("info");
2021-11-02 00:55:39 -07:00
info!("startup");
2021-11-01 02:34:25 -07:00
let postgres_connection_string = "host=/var/run/postgresql user=kamm port=5433";
let (account_write_queue_sender, slot_queue_sender) =
2021-11-02 00:55:39 -07:00
postgres_target::init(postgres_connection_string.into());
2021-11-01 02:34:25 -07:00
2021-11-01 13:48:17 -07:00
let use_accountsdb = true;
if use_accountsdb {
grpc_plugin_source::process_events(account_write_queue_sender, slot_queue_sender);
} else {
websocket_source::process_events(account_write_queue_sender, slot_queue_sender);
2021-11-01 02:34:25 -07:00
}
}