Skip to content

Commit

Permalink
check vote
Browse files Browse the repository at this point in the history
  • Loading branch information
anjor committed Dec 11, 2024
1 parent 5d7c796 commit c56cd24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion grpc-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,9 @@ func (multi *MultiEpoch) processSlotTransactions(
return true
}

// add Vote
if !(*filter.Vote) && IsSimpleVoteTransaction(&tx) { // If vote is false, we should filter out vote transactions
return false
}

if !(*filter.Failed) { // If failed is false, we should filter out failed transactions
err := getErr(meta)
Expand Down
33 changes: 33 additions & 0 deletions vote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"github.com/gagliardetto/solana-go"
)

// IsSimpleVoteTransaction checks if a transaction is a simple vote transaction.
// A simple vote transaction meets these conditions:
// 1. has 1 or 2 signatures
// 2. is legacy message (this is implicit in solana-go as it mainly handles legacy messages)
// 3. has only one instruction
// 4. which must be Vote instruction
func IsSimpleVoteTransaction(tx *solana.Transaction) bool {
// Check signature count (condition 1)
if len(tx.Signatures) == 0 || len(tx.Signatures) > 2 {
return false
}

// Check instruction count (condition 3)
instructions := tx.Message.Instructions
if len(instructions) != 1 {
return false
}

// Get the program ID for the instruction
programID := tx.Message.AccountKeys[instructions[0].ProgramIDIndex]

// Check if it's a Vote instruction (condition 4)
// Note: This is the Vote Program ID on Solana mainnet
voteProgram := solana.VoteProgramID // This is a built-in constant in solana-go

return programID.Equals(voteProgram)
}

0 comments on commit c56cd24

Please sign in to comment.