Skip to content

Commit

Permalink
Add filters (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: P-Yevhenii <[email protected]>
  • Loading branch information
P-Yevhenii and P-Yevhenii authored Nov 3, 2023
1 parent 7ea6cc0 commit 4f7dae0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
**/target
test-ledger
.history
config.json
config.json

.idea
25 changes: 25 additions & 0 deletions solana-geyser-plugin-scaffold/src/fb_serializers/update_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ use solana_sdk::signature::Signature;
const BPF_LOADER_WRITE_INSTRUCTION_FIRST_BYTE: u8 = 0;
const BPF_UPGRADEABLE_LOADER_WRITE_INSTRUCTION_FIRST_BYTE: u8 = 1;

const NFT_KEYS: &[&str] = &[
"BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY",
"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
];

pub struct AccountUpdate {
/// The account's public key
pub key: Pubkey,
Expand Down Expand Up @@ -85,6 +91,14 @@ impl AccountUpdate {
}
}
}

pub fn is_nft_account(&self) -> bool {
if NFT_KEYS.contains(&self.key.to_string().as_str()) {
return true;
}

NFT_KEYS.contains(&self.owner.to_string().as_str())
}
}

pub struct TransactionUpdate {
Expand Down Expand Up @@ -145,6 +159,17 @@ impl TransactionUpdate {

false
}

pub fn is_nft_transaction(&self) -> bool {
let account_keys = self.transaction.message().account_keys();
for account_key in account_keys.iter() {
if NFT_KEYS.contains(&account_key.to_string().as_str()) {
return true;
}
}

false
}
}

pub struct BlockUpdate<'a> {
Expand Down
9 changes: 7 additions & 2 deletions solana-geyser-plugin-scaffold/src/geyser_plugin_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ impl GeyserPlugin for GeyserPluginHook {
|| GeyserPluginError::AccountsUpdateError { msg: UNINIT.into() },
|inner| {
let acc_update = &AccountUpdate::from_account(account, slot, is_startup)?;
// TODO: add filter by accounts from config

if !acc_update.is_nft_account() {
return Ok(());
}

let data = serialize_account(acc_update);

Expand Down Expand Up @@ -204,7 +207,9 @@ impl GeyserPlugin for GeyserPluginHook {
return Ok(());
}

// TODO: add filter by programs from config
if !tx_update.is_nft_transaction() {
return Ok(());
}

let data = serialize_transaction(&tx_update)?;

Expand Down

0 comments on commit 4f7dae0

Please sign in to comment.