Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for vote tranasction #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ func (t *Transaction) GetAccountIndex(account PublicKey) (uint16, error) {
return t.Message.GetAccountIndex(account)
}

// 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 (t *Transaction) IsSimpleVoteTransaction() bool {
// Check signature count (condition 1)
if len(t.Signatures) == 0 || len(t.Signatures) > 2 {
return false
}

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

// Get the program ID for the instruction
programID := t.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 := VoteProgramID // This is a built-in constant in solana-go

return programID.Equals(voteProgram)
}

// TransactionFromDecoder decodes a transaction from a decoder.
func TransactionFromDecoder(decoder *bin.Decoder) (*Transaction, error) {
var out *Transaction
Expand Down