use pubkey instead of string for account_id and program_id
This commit is contained in:
parent
d5e5caa5fc
commit
7f2a0be3c9
|
@ -1,10 +1,7 @@
|
|||
#![allow(unused_variables)]
|
||||
|
||||
use mango_feeds_connector::EntityFilter::{FilterByAccountIds, FilterByProgramId};
|
||||
use mango_feeds_connector::{
|
||||
grpc_plugin_source, metrics, AccountWrite, FilterConfig, GrpcSourceConfig, MetricsConfig,
|
||||
SlotUpdate, SnapshotSourceConfig, SourceConfig,
|
||||
};
|
||||
use mango_feeds_connector::EntityFilter::FilterByAccountIds;
|
||||
use mango_feeds_connector::{grpc_plugin_source, metrics, AccountWrite, FilterConfig, GrpcSourceConfig, MetricsConfig, SlotUpdate, SnapshotSourceConfig, SourceConfig, EntityFilter};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -72,20 +69,20 @@ async fn main() -> anyhow::Result<()> {
|
|||
});
|
||||
|
||||
let filter_config1 = FilterConfig {
|
||||
entity_filter: FilterByProgramId("11111111111111111111111111111111".to_string()),
|
||||
entity_filter: EntityFilter::filter_by_program_id("11111111111111111111111111111111"),
|
||||
};
|
||||
|
||||
// an account that exists
|
||||
let filter_config2 = FilterConfig {
|
||||
entity_filter: FilterByAccountIds(vec![
|
||||
"2z5cFZAmL5HgDYXPAfEVpWn33Nixsu3iSsg5PDCFDWSb".to_string()
|
||||
entity_filter: EntityFilter::filter_by_account_ids(vec![
|
||||
"2z5cFZAmL5HgDYXPAfEVpWn33Nixsu3iSsg5PDCFDWSb"
|
||||
]),
|
||||
};
|
||||
|
||||
// an account that does not exist
|
||||
let filter_config3 = FilterConfig {
|
||||
entity_filter: FilterByAccountIds(vec![
|
||||
"aorYUvexUBb6cRFpmauF3ofgUDDpFZcRpHpcp5B2Zip".to_string()
|
||||
entity_filter: EntityFilter::filter_by_account_ids(vec![
|
||||
"aorYUvexUBb6cRFpmauF3ofgUDDpFZcRpHpcp5B2Zip"
|
||||
]),
|
||||
};
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ async fn feed_data_geyser(
|
|||
"client".to_owned(),
|
||||
SubscribeRequestFilterAccounts {
|
||||
account: vec![],
|
||||
owner: vec![program_id.clone()],
|
||||
owner: vec![program_id.to_string()],
|
||||
filters: vec![],
|
||||
},
|
||||
);
|
||||
|
@ -108,7 +108,7 @@ async fn feed_data_geyser(
|
|||
accounts.insert(
|
||||
"client".to_owned(),
|
||||
SubscribeRequestFilterAccounts {
|
||||
account: account_ids.clone(),
|
||||
account: account_ids.into_iter().map(Pubkey::to_string).collect(),
|
||||
owner: vec![],
|
||||
filters: vec![],
|
||||
},
|
||||
|
@ -211,10 +211,11 @@ async fn feed_data_geyser(
|
|||
snapshot_needed = false;
|
||||
match &filter_config.entity_filter {
|
||||
EntityFilter::FilterByAccountIds(account_ids) => {
|
||||
snapshot_gma = tokio::spawn(get_snapshot_gma(snapshot_rpc_http_url.clone(), account_ids.clone())).fuse();
|
||||
let account_ids_typed = account_ids.into_iter().map(Pubkey::to_string).collect();
|
||||
snapshot_gma = tokio::spawn(get_snapshot_gma(snapshot_rpc_http_url.clone(), account_ids_typed)).fuse();
|
||||
},
|
||||
EntityFilter::FilterByProgramId(program_id) => {
|
||||
snapshot_gpa = tokio::spawn(get_snapshot_gpa(snapshot_rpc_http_url.clone(), program_id.clone())).fuse();
|
||||
snapshot_gpa = tokio::spawn(get_snapshot_gpa(snapshot_rpc_http_url.clone(), program_id.to_string())).fuse();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ pub mod metrics;
|
|||
pub mod snapshot;
|
||||
pub mod websocket_source;
|
||||
|
||||
use std::str::FromStr;
|
||||
use itertools::Itertools;
|
||||
use {
|
||||
serde_derive::Deserialize,
|
||||
solana_sdk::{account::Account, pubkey::Pubkey},
|
||||
|
@ -102,8 +104,20 @@ pub struct SnapshotSourceConfig {
|
|||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub enum EntityFilter {
|
||||
FilterByAccountIds(Vec<String>),
|
||||
FilterByProgramId(String),
|
||||
FilterByAccountIds(Vec<Pubkey>),
|
||||
FilterByProgramId(Pubkey),
|
||||
}
|
||||
impl EntityFilter {
|
||||
pub fn filter_by_program_id(program_id: &str) -> Self {
|
||||
EntityFilter::FilterByProgramId(Pubkey::from_str(program_id).unwrap())
|
||||
}
|
||||
pub fn filter_by_account_ids(account_ids: Vec<&str>) -> Self {
|
||||
let accounts_ids_typed =
|
||||
account_ids.into_iter()
|
||||
.map(|id| Pubkey::from_str(id).unwrap())
|
||||
.collect_vec();
|
||||
EntityFilter::FilterByAccountIds(accounts_ids_typed)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
|
|
|
@ -48,10 +48,11 @@ async fn feed_data(
|
|||
) -> anyhow::Result<()> {
|
||||
match &filter_config.entity_filter {
|
||||
EntityFilter::FilterByAccountIds(account_ids) => {
|
||||
feed_data_by_accounts(config, account_ids.clone(), sender).await
|
||||
let account_ids_typed = account_ids.into_iter().map(Pubkey::to_string).collect();
|
||||
feed_data_by_accounts(config, account_ids_typed, sender).await
|
||||
}
|
||||
EntityFilter::FilterByProgramId(program_id) => {
|
||||
feed_data_by_program(config, program_id.clone(), sender).await
|
||||
feed_data_by_program(config, program_id.to_string(), sender).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue