Skip to content

Commit

Permalink
timestamp tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed May 6, 2024
1 parent e278c14 commit f60e9f2
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions examples/stream_token_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use yellowstone_grpc_proto::geyser::subscribe_update::UpdateOneof;
use yellowstone_grpc_proto::geyser::{SubscribeRequest, SubscribeRequestFilterAccounts, SubscribeUpdate};
use yellowstone_grpc_proto::prost::Message as _;


const ENABLE_TIMESTAMP_TAGGING: bool = true;

#[tokio::main]
pub async fn main() {
// RUST_LOG=info,stream_blocks_mainnet=debug,geyser_grpc_connector=trace
Expand Down Expand Up @@ -71,6 +74,11 @@ pub async fn main() {
trace!("got account update (green)!!! {} - {:?} - {} bytes",
update.slot, account_pk, account.data.len());

if ENABLE_TIMESTAMP_TAGGING {
let since_the_epoch = std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH).expect("Time went backwards");
info!("got account update: write_version={};timestamp_us={};slot={}", account.write_version, since_the_epoch.as_micros(), update.slot);
}

match parse_token(&account.data, Some(6)) {
Ok(TokenAccountType::Account(account_ui)) => {
// UiTokenAccount {
Expand All @@ -89,19 +97,23 @@ pub async fn main() {
// close_authority: None,
// extensions: []
// }
if matches!(account_ui.state, Initialized) {
let owner = Pubkey::from_str(&account_ui.owner).unwrap();
let mint = Pubkey::from_str(&account_ui.mint).unwrap();
// 6 decimals as requested
let amount = &account_ui.token_amount.amount;
// groovie wallet
if account_ui.owner.starts_with("66fEFnKy") {
info!("update balance for mint {} of owner {}: {}", mint, owner, amount);
}
token_account_by_ownermint.entry(owner)
.or_insert_with(DashMap::new)
.insert(mint, account_ui);
// all different states are covered
// is_native: both true+false are sent
assert_eq!(account.executable, false);
assert_eq!(account.rent_epoch, u64::MAX);

let owner = Pubkey::from_str(&account_ui.owner).unwrap();
let mint = Pubkey::from_str(&account_ui.mint).unwrap();
// 6 decimals as requested
let amount = &account_ui.token_amount.amount;
// groovie wallet
if account_ui.owner.starts_with("66fEFnKy") {
info!("update balance for mint {} of owner {}: {}", mint, owner, amount);
}
token_account_by_ownermint.entry(owner)
.or_insert_with(DashMap::new)
.insert(mint, account_ui);

}
Ok(TokenAccountType::Mint(mint)) => {
// not interesting
Expand Down Expand Up @@ -136,7 +148,7 @@ pub async fn main() {
for token_account_mint in accounts_by_mint.iter() {
total += 1;
let (owner, mint, account) = (accounts_by_mint.key(), token_account_mint.key(), token_account_mint.value());
debug!("{} - {} - {}", owner, mint, account.token_amount.ui_amount_string);
// debug!("{} - {} - {}", owner, mint, account.token_amount.ui_amount_string);
}
}
info!("Total owner x mint entries in cache map: {}", total);
Expand Down

0 comments on commit f60e9f2

Please sign in to comment.