pump and pump swap errTx parser
This commit is contained in:
48
parser.go
48
parser.go
@@ -2,7 +2,6 @@ package pump_parser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"slices"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
@@ -14,6 +13,11 @@ var defaultSwapPrograms = map[solana.PublicKey]swapParser{
|
||||
pumpProgram: pumpParser,
|
||||
}
|
||||
|
||||
var errTxParserPrograms = map[solana.PublicKey]swapParser{
|
||||
pumpAmmProgram: pumpAmmParser,
|
||||
pumpProgram: pumpParser,
|
||||
}
|
||||
|
||||
var swapPrograms = cloneSwapPrograms(defaultSwapPrograms)
|
||||
|
||||
type ParserOption func(*parserConfig)
|
||||
@@ -97,6 +101,46 @@ func (tx *Tx) Parser() error {
|
||||
|
||||
tx.Token = make(map[solana.PublicKey]TokenMeta)
|
||||
|
||||
if tx.rawTx.Meta.Err != nil {
|
||||
tx.Err = tx.rawTx.Meta.Err
|
||||
if tx.Err.UnKnown != "" {
|
||||
return nil
|
||||
}
|
||||
if len(tx.rawTx.Transaction.Message.Instructions) <= int(tx.Err.Index) {
|
||||
return nil
|
||||
}
|
||||
programIdx := tx.rawTx.Transaction.Message.Instructions[tx.Err.Index].ProgramIDIndex
|
||||
if len(accountList) <= programIdx {
|
||||
return nil
|
||||
}
|
||||
programAccount := accountList[programIdx]
|
||||
parserFunc, exists := errTxParserPrograms[programAccount]
|
||||
|
||||
if !exists {
|
||||
return nil
|
||||
}
|
||||
// parse failed tx
|
||||
swaps, _, err := parserFunc(tx, tx.rawTx.Transaction.Message.Instructions[tx.Err.Index], InnerInstructions{}, [2]uint{uint(tx.Err.Index), uint(0)})
|
||||
if err != nil {
|
||||
return nil
|
||||
//fmt.Printf("parser failed tx error: %s, block: %d tx: %s\n", err, tx.Block, tx.GetTxHash())
|
||||
}
|
||||
if len(swaps) > 0 {
|
||||
tx.Swaps = swaps
|
||||
}
|
||||
for i, instr := range tx.rawTx.Transaction.Message.Instructions {
|
||||
if p, exists := actionPrograms[programAccount]; exists {
|
||||
_, err := p(tx, instr, InnerInstructions{}, [2]uint{uint(i), uint(0)})
|
||||
if err != nil {
|
||||
if errors.Is(err, InstructionIgnoredError) {
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
var innersMap = make(map[int]InnerInstructions)
|
||||
for _, inner := range tx.rawTx.Meta.InnerInstructions {
|
||||
innersMap[inner.Index] = inner
|
||||
@@ -144,7 +188,7 @@ func (tx *Tx) Parser() error {
|
||||
innerLength := len(innersMap[i].Instructions)
|
||||
for j := 1; j <= innerLength; {
|
||||
if j <= 0 || j > innerLength {
|
||||
log.Printf("inner instruction index is out if range, block: %d, tx: %s, outerIndex: %d, innerIndex: %d", tx.Block, tx.GetTxHash(), ii, j)
|
||||
//log.Printf("inner instruction index is out if range, block: %d, tx: %s, outerIndex: %d, innerIndex: %d", tx.Block, tx.GetTxHash(), ii, j)
|
||||
break
|
||||
}
|
||||
innerInstr := innersMap[i].Instructions[j-1]
|
||||
|
||||
Reference in New Issue
Block a user