Skip to content

Token 2022 decoder not decoding accounts #395

@iarlacrewe

Description

@iarlacrewe

The Token 2022 decoder does not seem to be processing any accounts unless I remove the

#[carbon(discriminator = "0x6a5edd53c00a4a4a")]

from the accounts struct in accounts/mint.rs, accounts/token.rs, and accounts/multisig.rs. Once the discriminator flag is removed, the decoder processes all accounts fine. Not sure if other people have been able to get it running without this temporary workaround, or if I've misconfigured something on my end.

Here's my minimal setup to run the decoder, adapted from the token-indexing example repo:

use {
    async_trait::async_trait,
    carbon_core::{
        account::{AccountMetadata, DecodedAccount},
        error::CarbonResult,
        metrics::MetricsCollection,
        processor::Processor,
    },
    carbon_token_2022_decoder::{
        accounts::Token2022Account, Token2022Decoder, PROGRAM_ID as TOKEN_2022_PROGRAM_ID,
    },
    carbon_yellowstone_grpc_datasource::YellowstoneGrpcGeyserClient,
    std::{
        collections::{HashMap, HashSet},
        env,
        sync::Arc,
    },
    tokio::sync::RwLock,
    yellowstone_grpc_proto::geyser::{CommitmentLevel, SubscribeRequestFilterAccounts},
};

#[tokio::main]
pub async fn main() -> CarbonResult<()> {
    env_logger::init();
    dotenv::dotenv().ok();
    // NOTE: Workaround, that solving issue https://github.com/rustls/rustls/issues/1877
    rustls::crypto::aws_lc_rs::default_provider()
        .install_default()
        .expect("Can't set crypto provider to aws_lc_rs");

    let mut account_filters: HashMap<String, SubscribeRequestFilterAccounts> = HashMap::new();
    account_filters.insert(
        "spl_token_account_filter".to_string(),
        SubscribeRequestFilterAccounts {
            account: vec![],
            owner: vec![TOKEN_2022_PROGRAM_ID.to_string()],
            filters: vec![],
            nonempty_txn_signature: None,
        },
    );

    let yellowstone_grpc = YellowstoneGrpcGeyserClient::new(
        env::var("GEYSER_URL").unwrap_or_default(),
        env::var("X_TOKEN").ok(),
        Some(CommitmentLevel::Confirmed),
        account_filters,
        HashMap::new(),
        Default::default(),
        Arc::new(RwLock::new(HashSet::new())),
    );

    carbon_core::pipeline::Pipeline::builder()
        .datasource(yellowstone_grpc)
        .account(Token2022Decoder, TokenProgramAccountProcessor {})
        .shutdown_strategy(carbon_core::pipeline::ShutdownStrategy::Immediate)
        .build()?
        .run()
        .await?;

    Ok(())
}

pub struct TokenProgramAccountProcessor {}

#[async_trait]
impl Processor for TokenProgramAccountProcessor {
    type InputType = (
        AccountMetadata,
        DecodedAccount<Token2022Account>,
        solana_account::Account,
    );

    async fn process(
        &mut self,
        data: Self::InputType,
        _metrics: Arc<MetricsCollection>,
    ) -> CarbonResult<()> {
        let (metadata, account, solana_account) = data;

        log::info!(
            "Received account update - Owner: {}, Address: {}",
            solana_account.owner,
            metadata.pubkey
        );

        match account.data {
            Token2022Account::Token(account) => {
                log::info!("Token Account: {:#?}", account);
            }
            Token2022Account::Mint(mint) => {
                log::info!("Token Mint: {:#?}", mint);
            }
            Token2022Account::Multisig(multisig) => {
                log::info!("Token Multisig: {:#?}", multisig);
            }
        };

        Ok(())
    }
}

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions