pump and pump swap errTx parser

This commit is contained in:
thloyi
2026-02-26 16:11:34 +08:00
parent 972ddc7960
commit b0d4342fa2
12 changed files with 704 additions and 722 deletions

154
error.go
View File

@@ -79,54 +79,54 @@ const (
const (
GenericError InstructionErrorVariant = iota
/// The arguments provided to a program were invalid
// InvalidArgument / The arguments provided to a program were invalid
InvalidArgument
/// An instruction's data contents were invalid
// InvalidInstructionData / An instruction's data contents were invalid
InvalidInstructionData
/// An account's data contents was invalid
// InvalidAccountData / An account's data contents was invalid
InvalidAccountData
/// An account's data was too small
// AccountDataTooSmall / An account's data was too small
AccountDataTooSmall
/// An account's balance was too small to complete the instruction
// InsufficientFunds / An account's balance was too small to complete the instruction
InsufficientFunds
/// The account did not have the expected program id
// IncorrectProgramId / The account did not have the expected program id
IncorrectProgramId
/// A signature was required but not found
// MissingRequiredSignature / A signature was required but not found
MissingRequiredSignature
/// An initialize instruction was sent to an account that has already been initialized.
// AccountAlreadyInitialized / An initialize instruction was sent to an account that has already been initialized.
AccountAlreadyInitialized
/// An attempt to operate on an account that hasn't been initialized.
// UninitializedAccount / An attempt to operate on an account that hasn't been initialized.
UninitializedAccount
/// Program's instruction lamport balance does not equal the balance after the instruction
// UnbalancedInstruction / Program's instruction lamport balance does not equal the balance after the instruction
UnbalancedInstruction
/// Program illegally modified an account's program id
// ModifiedProgramId / Program illegally modified an account's program id
ModifiedProgramId
/// Program spent the lamports of an account that doesn't belong to it
// ExternalAccountLamportSpend / Program spent the lamports of an account that doesn't belong to it
ExternalAccountLamportSpend
/// Program modified the data of an account that doesn't belong to it
// ExternalAccountDataModified / Program modified the data of an account that doesn't belong to it
ExternalAccountDataModified
/// Read-only account's lamports modified
// ReadonlyLamportChange / Read-only account's lamports modified
ReadonlyLamportChange
/// Read-only account's data was modified
// ReadonlyDataModified / Read-only account's data was modified
ReadonlyDataModified
/// An account was referenced more than once in a single instruction
// DuplicateAccountIndex / An account was referenced more than once in a single instruction
// Deprecated, instructions can now contain duplicate accounts
DuplicateAccountIndex
/// Executable bit on account changed, but shouldn't have
// ExecutableModified / Executable bit on account changed, but shouldn't have
ExecutableModified
/// Rent_epoch account changed, but shouldn't have
// RentEpochModified / Rent_epoch account changed, but shouldn't have
RentEpochModified
/// The instruction expected additional account keys
// NotEnoughAccountKeys / The instruction expected additional account keys
NotEnoughAccountKeys
/// Program other than the account's owner changed the size of the account data
// AccountDataSizeChanged / Program other than the account's owner changed the size of the account data
AccountDataSizeChanged
/// The instruction expected an executable account
// AccountNotExecutable / The instruction expected an executable account
AccountNotExecutable
/// Failed to borrow a reference to account data, already borrowed
// AccountBorrowFailed / Failed to borrow a reference to account data, already borrowed
AccountBorrowFailed
/// Account data has an outstanding reference after a program's execution
// InstructionAccountBorrowOutstanding / Account data has an outstanding reference after a program's execution
InstructionAccountBorrowOutstanding
/// The same account was multiply passed to an on-chain program's entrypoint, but the program
// DuplicateAccountOutOfSync / The same account was multiply passed to an on-chain program's entrypoint, but the program
/// modified them differently. A program can only modify one instance of the account because
/// the runtime cannot determine which changes to pick or how to merge them if both are modified
DuplicateAccountOutOfSync
@@ -136,42 +136,42 @@ const (
Custom // Custom(u32),
/// The return value from the program was invalid. Valid errors are either a defined builtin
// InvalidError / The return value from the program was invalid. Valid errors are either a defined builtin
/// error value or a user-defined error in the lower 32 bits.
InvalidError
/// Executable account's data was modified
// ExecutableDataModified / Executable account's data was modified
ExecutableDataModified
/// Executable account's lamports modified
// ExecutableLamportChange / Executable account's lamports modified
ExecutableLamportChange
/// Executable accounts must be rent exempt
// ExecutableAccountNotRentExempt / Executable accounts must be rent exempt
ExecutableAccountNotRentExempt
/// Unsupported program id
// UnsupportedProgramId / Unsupported program id
UnsupportedProgramId
/// Cross-program invocation call depth too deep
// CallDepth / Cross-program invocation call depth too deep
CallDepth
/// An account required by the instruction is missing
// MissingAccount / An account required by the instruction is missing
MissingAccount
/// Cross-program invocation reentrancy not allowed for this instruction
// ReentrancyNotAllowed / Cross-program invocation reentrancy not allowed for this instruction
ReentrancyNotAllowed
/// Length of the seed is too long for address generation
// MaxSeedLengthExceeded / Length of the seed is too long for address generation
MaxSeedLengthExceeded
/// Provided seeds do not result in a valid address
// InvalidSeeds / Provided seeds do not result in a valid address
InvalidSeeds
/// Failed to reallocate account data of this length
// InvalidRealloc / Failed to reallocate account data of this length
InvalidRealloc
/// Computational budget exceeded
// ComputationalBudgetExceeded / Computational budget exceeded
ComputationalBudgetExceeded
/// Cross-program invocation with unauthorized signer or writable account
// PrivilegeEscalation / Cross-program invocation with unauthorized signer or writable account
PrivilegeEscalation
/// Failed to create program execution environment
// ProgramEnvironmentSetupFailure / Failed to create program execution environment
ProgramEnvironmentSetupFailure
/// Program failed to complete
// ProgramFailedToComplete / Program failed to complete
ProgramFailedToComplete
/// Program failed to compile
// ProgramFailedToCompile / Program failed to compile
ProgramFailedToCompile
/// Account is immutable
// Immutable / Account is immutable
Immutable
/// Incorrect authority provided
// IncorrectAuthority / Incorrect authority provided
IncorrectAuthority
/// Failed to serialize or deserialize account data
///
@@ -185,23 +185,23 @@ const (
BorshIoError // BorshIoError(String)
// An account does not have enough lamports to be rent-exempt
// AccountNotRentExempt An account does not have enough lamports to be rent-exempt
AccountNotRentExempt
/// Invalid account owner
// InvalidAccountOwner Invalid account owner
InvalidAccountOwner
/// Program arithmetic overflowed
// ArithmeticOverflow Program arithmetic overflowed
ArithmeticOverflow
/// Unsupported sysvar
// UnsupportedSysvar Unsupported sysvar
UnsupportedSysvar
/// Illegal account owner
// IllegalOwner Illegal account owner
IllegalOwner
/// Accounts data allocations exceeded the maximum allowed per transaction
// MaxAccountsDataAllocationsExceeded / Accounts data allocations exceeded the maximum allowed per transaction
MaxAccountsDataAllocationsExceeded
/// Max accounts exceeded
// MaxAccountsExceeded Max accounts exceeded
MaxAccountsExceeded
/// Max instruction trace length exceeded
// MaxInstructionTraceLengthExceeded Max instruction trace length exceeded
MaxInstructionTraceLengthExceeded
/// Builtin programs must consume compute units
// BuiltinProgramsMustConsumeComputeUnits Builtin programs must consume compute units
BuiltinProgramsMustConsumeComputeUnits
)
@@ -210,6 +210,15 @@ type TransactionError struct {
rest []byte
}
type TransactionParsedError struct {
Index uint8
Variant TransactionErrorVariant
Enum InstructionErrorVariant
CustomCode uint32
UnKnown string
}
var (
ErrInvalidTransactionError = errors.New("invalid transaction error")
NotAnInstructionError = errors.New("not an instruction error")
@@ -233,6 +242,49 @@ func DecodeTransactionError(data []byte) (*TransactionError, error) {
return &err, nil
}
func ParseTransactionErrorFromGeyser(data []byte) *TransactionParsedError {
if len(data) == 0 {
return nil
}
transactionError, err := DecodeTransactionError(data)
if err != nil {
return &TransactionParsedError{
UnKnown: string(data),
}
}
enumErr, err := transactionError.GetInstructionError()
if err != nil {
return &TransactionParsedError{
Variant: transactionError.Variant,
UnKnown: string(data),
}
}
if enumErr.Variant != Custom {
return &TransactionParsedError{
Index: enumErr.Index,
Variant: transactionError.Variant,
Enum: enumErr.Variant,
}
}
customCode, err := enumErr.Custom()
if err != nil {
return &TransactionParsedError{
Index: enumErr.Index,
Variant: transactionError.Variant,
Enum: enumErr.Variant,
UnKnown: string(data),
}
}
return &TransactionParsedError{
Index: enumErr.Index,
Variant: transactionError.Variant,
Enum: enumErr.Variant,
CustomCode: customCode.Code,
}
}
func (e *TransactionError) GetCustomErrorCode() (uint8, uint32, error) {
instr, err := e.GetInstructionError()
if err != nil {