package geyser import ( "fmt" "github.com/shopspring/decimal" types "github.com/thloyi/pump-parser" ) type PumpHandler struct { callback func(*types.Tx, *types.RawTx) } func NewPumpHandler(cb func(*types.Tx, *types.RawTx)) *PumpHandler { return &PumpHandler{ callback: func(tx *types.Tx, tx2 *types.RawTx) { //tx.Check(tx2) cb(tx, tx2) }, } } func (h *PumpHandler) HandleMessage(rawTx *types.RawTx) { if rawTx.Meta.Err != nil { // Notify the channel about the failed transaction beforeSolBalance := decimal.Zero afterSolBalance := decimal.Zero if rawTx.Meta.PreBalances != nil && len(rawTx.Meta.PreBalances) > 0 { beforeSolBalance = decimal.NewFromUint64(rawTx.Meta.PreBalances[0]).Div(decimal.NewFromInt(1e9)) } if rawTx.Meta.PostBalances != nil && len(rawTx.Meta.PostBalances) > 0 { afterSolBalance = decimal.NewFromUint64(rawTx.Meta.PostBalances[0]).Div(decimal.NewFromInt(1e9)) } h.callback(&types.Tx{ TxHash: (*[64]byte)((rawTx.Transaction.Signatures[0][:])), Err: rawTx.Meta.Err, Signer: rawTx.GetSigner(), Block: rawTx.Slot, BlockIndex: uint64(rawTx.IndexWithinBlock), BeforeSolBalance: beforeSolBalance, AfterSOLBalance: afterSolBalance, }, rawTx) return } parsedTx, err := types.Parser(rawTx) if err != nil { fmt.Printf("parser error: %s, block: %d tx: %s\n", err, rawTx.Slot, rawTx.TxHash()) return } if len(parsedTx.Swaps) == 0 { // no swap, ignore return } // fmt.Println(parsedTx.GetTxHash(), len(parsedTx.Swaps)) if h.callback != nil { h.callback(parsedTx, rawTx) } }