loading address tables

This commit is contained in:
thloyi
2026-01-05 12:45:32 +08:00
parent 4afa412231
commit e6922e4561
7 changed files with 178 additions and 20 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"encoding/binary"
"fmt"
"log/slog"
"math/big"
"github.com/gagliardetto/solana-go"
@@ -193,7 +192,7 @@ type fjszBuyArgs struct {
}
// ParseTransaction mirrors the Rust parse_transaction entry point.
func ParseTransaction(update *SubscribeUpdateTransaction) []*TxSignal {
func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables) []*TxSignal {
versioned, err := toVersionedTransaction(update)
if err != nil || versioned == nil || len(versioned.Signatures) == 0 {
return nil
@@ -203,6 +202,22 @@ func ParseTransaction(update *SubscribeUpdateTransaction) []*TxSignal {
staticKeys := versioned.Message.StaticAccountKeys
instructions := versioned.Message.Instructions
if loader != nil && len(versioned.Message.AddressTableLookups) > 0 {
// currently we only care about photon table lookup
for _, lookup := range versioned.Message.AddressTableLookups {
accounts := loader.GetAddressTable(lookup.AccountKey, lookup.WritableIndexes)
if len(accounts) != len(lookup.WritableIndexes) {
break
}
staticKeys = append(staticKeys, accounts...)
accounts2 := loader.GetAddressTable(lookup.AccountKey, lookup.ReadonlyIndexes)
if len(accounts2) != len(lookup.ReadonlyIndexes) {
break
}
staticKeys = append(staticKeys, accounts2...)
}
}
var parsed []*TxSignal
for i := range instructions {
@@ -251,7 +266,7 @@ func ParseTransaction(update *SubscribeUpdateTransaction) []*TxSignal {
func appendParsed(list []*TxSignal, parsed *TxSignal, err error, txHash [64]byte, label string) []*TxSignal {
if err != nil {
slog.Error("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
logger.Debug("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
return list
}
if parsed != nil {
@@ -321,8 +336,11 @@ func formatSolAmount(lamports uint64) decimal.Decimal {
}
func getStaticKey(static []solana.PublicKey, index int) (solana.PublicKey, error) {
if index < 0 || index >= len(static) {
return solana.PublicKey{}, fmt.Errorf("account index %d out of bounds", index)
if index < 0 {
return solana.PublicKey{}, fmt.Errorf("account index %d less then 0", index)
}
if index >= len(static) {
return solana.PublicKey{}, fmt.Errorf("account index %d out of range", index)
}
return static[index], nil
}