pump and pump swap errTx parser
This commit is contained in:
101
rawtx.go
101
rawtx.go
@@ -73,6 +73,10 @@ func (tx *RawTx) GetAccountLust() []solana.PublicKey {
|
||||
return tx.getAccountList()
|
||||
}
|
||||
|
||||
func (tx *RawTx) GetAccountList() []solana.PublicKey {
|
||||
return tx.getAccountList()
|
||||
}
|
||||
|
||||
func (tx *RawTx) TxHash() string {
|
||||
if len(tx.Transaction.Signatures) > 0 {
|
||||
return tx.Transaction.Signatures[0].String()
|
||||
@@ -146,17 +150,17 @@ func (tb *TokenBalance) ParseAccount() {
|
||||
}
|
||||
|
||||
type Meta struct {
|
||||
Err interface{} `json:"err"`
|
||||
Fee uint64 `json:"fee"`
|
||||
InnerInstructions []InnerInstructions `json:"innerInstructions"`
|
||||
LoadedAddresses LoadedAddresses `json:"loadedAddresses"`
|
||||
LogMessages []string `json:"logMessages"`
|
||||
PostBalances []uint64 `json:"postBalances"`
|
||||
PostTokenBalances []TokenBalance `json:"postTokenBalances"`
|
||||
PreBalances []uint64 `json:"preBalances"`
|
||||
PreTokenBalances []TokenBalance `json:"preTokenBalances"`
|
||||
Rewards []interface{} `json:"rewards"`
|
||||
ComputeUnitsConsumed uint64 `json:"computeUnitsConsumed"`
|
||||
Err *TransactionParsedError `json:"err"`
|
||||
Fee uint64 `json:"fee"`
|
||||
InnerInstructions []InnerInstructions `json:"innerInstructions"`
|
||||
LoadedAddresses LoadedAddresses `json:"loadedAddresses"`
|
||||
LogMessages []string `json:"logMessages"`
|
||||
PostBalances []uint64 `json:"postBalances"`
|
||||
PostTokenBalances []TokenBalance `json:"postTokenBalances"`
|
||||
PreBalances []uint64 `json:"preBalances"`
|
||||
PreTokenBalances []TokenBalance `json:"preTokenBalances"`
|
||||
Rewards []interface{} `json:"rewards"`
|
||||
ComputeUnitsConsumed uint64 `json:"computeUnitsConsumed"`
|
||||
}
|
||||
type Header struct {
|
||||
NumReadonlySignedAccounts int `json:"numReadonlySignedAccounts"`
|
||||
@@ -294,6 +298,16 @@ func InstructionsFromRpc(instructions []solana.CompiledInstruction) []Instructio
|
||||
return instrs
|
||||
}
|
||||
|
||||
type RpcTransactionErr []interface{}
|
||||
|
||||
func marshalRpcTransactionErr(err any) string {
|
||||
e, _ := json.Marshal(err)
|
||||
if len(e) == 0 {
|
||||
return "UnKnown"
|
||||
}
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func FromRpcTransactionWithMeta(tx rpc.TransactionWithMeta, blockTime *uint64, slot uint64, index int64) (*RawTx, error) {
|
||||
created := int64(0)
|
||||
if blockTime != nil {
|
||||
@@ -321,8 +335,62 @@ func FromRpcTransactionWithMeta(tx rpc.TransactionWithMeta, blockTime *uint64, s
|
||||
yTx, _ := tx.GetTransaction()
|
||||
|
||||
if meta.Err != nil {
|
||||
e, _ := json.Marshal(meta.Err)
|
||||
sTx.Meta.Err = string(e)
|
||||
if iErr, ok := meta.Err.(map[string]any); ok {
|
||||
instructionError := iErr["InstructionError"]
|
||||
if instructionError == nil {
|
||||
sTx.Meta.Err = &TransactionParsedError{
|
||||
UnKnown: marshalRpcTransactionErr(meta.Err),
|
||||
}
|
||||
} else {
|
||||
if oErr, ok := instructionError.([]any); ok {
|
||||
if len(oErr) <= 1 {
|
||||
sTx.Meta.Err = &TransactionParsedError{
|
||||
UnKnown: marshalRpcTransactionErr(meta.Err),
|
||||
}
|
||||
} else if instrIdx, ok := oErr[0].(float64); ok {
|
||||
sTx.Meta.Err = &TransactionParsedError{
|
||||
Index: uint8(instrIdx),
|
||||
Variant: InstructionError,
|
||||
}
|
||||
errDetail, ok := oErr[1].(string)
|
||||
if ok {
|
||||
if errDetail == "ComputationalBudgetExceeded" {
|
||||
sTx.Meta.Err.Enum = ComputationalBudgetExceeded
|
||||
} else {
|
||||
sTx.Meta.Err.UnKnown = errDetail
|
||||
}
|
||||
} else {
|
||||
errDetail2, ok := oErr[1].(map[string]any)
|
||||
if ok && len(errDetail2) > 0 && errDetail2["Custom"] != nil {
|
||||
custom, ok := errDetail2["Custom"].(float64)
|
||||
if ok {
|
||||
sTx.Meta.Err.Enum = Custom
|
||||
sTx.Meta.Err.CustomCode = uint32(custom)
|
||||
} else {
|
||||
sTx.Meta.Err.UnKnown = marshalRpcTransactionErr(meta.Err)
|
||||
}
|
||||
|
||||
} else {
|
||||
sTx.Meta.Err.UnKnown = marshalRpcTransactionErr(meta.Err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sTx.Meta.Err = &TransactionParsedError{
|
||||
UnKnown: marshalRpcTransactionErr(meta.Err),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sTx.Meta.Err = &TransactionParsedError{
|
||||
UnKnown: marshalRpcTransactionErr(meta.Err),
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sTx.Meta.Err = &TransactionParsedError{
|
||||
UnKnown: marshalRpcTransactionErr(meta.Err),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
sTx.Meta.Fee = meta.Fee
|
||||
//sTx.Meta.InnerInstructions = meta.InnerInstructions
|
||||
@@ -799,12 +867,7 @@ func ConvertYellowstoneGrpcTransactionToSolanaTransaction(y *pb.SubscribeUpdateT
|
||||
|
||||
if meta.Err != nil && len(meta.Err.GetErr()) > 0 {
|
||||
// If the transaction has an error, we set the error in the Meta
|
||||
transError, err := DecodeTransactionError(meta.Err.GetErr())
|
||||
if err != nil {
|
||||
sTx.Meta.Err = err
|
||||
} else {
|
||||
sTx.Meta.Err = transError
|
||||
}
|
||||
sTx.Meta.Err = ParseTransactionErrorFromGeyser(meta.Err.GetErr())
|
||||
// sTx.Meta.Err = meta.Err.GetErr()
|
||||
}
|
||||
sTx.Meta.Fee = meta.Fee
|
||||
|
||||
Reference in New Issue
Block a user