use crate::constants::{MAX_OPS_PER_SCRIPT, MAX_SCRIPT_ELEMENT_SIZE, MAX_STACK_SIZE};
use crate::interpreter::{CheckMultiSigError, CheckSigError};
use crate::num::NumError;
use crate::signature_checker::SignatureError;
use crate::stack::StackError;
#[derive(Debug, Eq, PartialEq, thiserror::Error)]
pub enum Error {
#[error("script terminated with a false stack element")]
EvalFalse,
#[error("Return early if OP_RETURN is executed in the script.")]
OpReturn,
#[error("Exceeds max script size")]
ScriptSize,
#[error("Size of the element pushed to the stack exceeds MAX_SCRIPT_ELEMENT_SIZE ({MAX_SCRIPT_ELEMENT_SIZE})")]
PushSize,
#[error("Exceeds max operations ({MAX_OPS_PER_SCRIPT}) per script")]
OpCount,
#[error("Exceeds stack limit ({MAX_STACK_SIZE})")]
StackSize,
#[error("sig count")]
SigCount,
#[error("pubkey count")]
PubkeyCount,
#[error("OP_VERIFY failed at opcode: {0:?}")]
Verify(bitcoin::opcodes::Opcode),
#[error("bad opcode")]
BadOpcode,
#[error("attempt to execute disabled opcode {0}")]
DisabledOpcode(bitcoin::opcodes::Opcode),
#[error(transparent)]
Stack(#[from] StackError),
#[error("unbalanced conditional")]
UnbalancedConditional,
#[error("Locktime is negative")]
NegativeLocktime,
#[error("Required lock time has not been reached.")]
UnsatisfiedLocktime,
#[error("sig hash type")]
SigHashType,
#[error("Native witness program cannot also have a signature script")]
WitnessMalleated,
#[error("witness unexpected")]
WitnessUnexpected,
#[error("witness malleated p2sh")]
WitnessMalleatedP2SH,
#[error("clean stack")]
CleanStack,
#[error("minimal if")]
Minimalif,
#[error("signature push only")]
SigPushOnly,
#[error("witness program witness empty")]
WitnessProgramWitnessEmpty,
#[error("witness program mismatch")]
WitnessProgramMismatch,
#[error("witness program wrong length")]
WitnessProgramWrongLength,
#[error("NOP opcode encountered when DISCOURAGE_UPGRADABLE_NOPS flag is set")]
DiscourageUpgradableNops,
#[error("discourage upgradable witness program")]
DiscourageUpgradableWitnessProgram,
#[error("discourage upgradable taproot program")]
DiscourageUpgradableTaprootProgram,
#[error("discourage upgradable taproot version")]
DiscourageUpgradableTaprootVersion,
#[error("OP_SUCCESS encountered when ScriptVerifyDiscourageOpSuccess is active.")]
DiscourageOpSuccess,
#[error("discourage upgrable pubkey type")]
DiscourageUpgradablePubkeyType,
#[error("schnorr sig size")]
SchnorrSigSize,
#[error("schnorr sig hash type")]
SchnorrSigHashType,
#[error("schnorr sig")]
SchnorrSig,
#[error("Taproot control block has a bad length")]
TaprootWrongControlSize,
#[error("taproot validation weight")]
TaprootValidationWeight,
#[error("taproot checkmultisig")]
TaprootCheckmultisig,
#[error("taproot minimalif")]
TaprootMinimalif,
#[error("OP_CODESEPARATOR is used in a non-segwit script.")]
OpCodeSeparator,
#[error("sig findanddelete")]
SigFindAndDelete,
#[error("error count")]
ErrorCount,
#[error("No script execution")]
NoScriptExecution,
#[error("Invalid alt stack operation")]
InvalidAltStackOperation,
#[error("{0} is unknown")]
UnknownOpcode(bitcoin::opcodes::Opcode),
#[error("Failed to read instruction: {0:?}")]
ReadInstruction(bitcoin::script::Error),
#[error(transparent)]
CheckSig(#[from] CheckSigError),
#[error(transparent)]
CheckMultiSig(#[from] CheckMultiSigError),
#[error(transparent)]
Num(#[from] NumError),
#[error(transparent)]
Signature(#[from] SignatureError),
#[error("schnorr signature error: {0:?}")]
SchnorrSignature(bitcoin::taproot::SigFromSliceError),
#[error("taproot error: {0:?}")]
Taproot(bitcoin::taproot::TaprootError),
#[error("secp256k1 error: {0:?}")]
Secp256k1(bitcoin::secp256k1::Error),
}