kaspa_consensus_core/errors/
tx.rs

1use crate::constants::MAX_SOMPI;
2use crate::subnets::SubnetworkId;
3use crate::tx::TransactionOutpoint;
4use kaspa_txscript_errors::TxScriptError;
5use thiserror::Error;
6
7#[derive(Error, Debug, Clone, PartialEq, Eq)]
8pub enum TxRuleError {
9    #[error("transaction has no inputs")]
10    NoTxInputs,
11
12    #[error("transaction has duplicate inputs")]
13    TxDuplicateInputs,
14
15    #[error("transaction has non zero gas value")]
16    TxHasGas,
17
18    #[error("a non coinbase transaction has a payload")]
19    NonCoinbaseTxHasPayload,
20
21    #[error("transaction version {0} is unknown")]
22    UnknownTxVersion(u16),
23
24    #[error("transaction has {0} inputs where the max allowed is {1}")]
25    TooManyInputs(usize, usize),
26
27    #[error("transaction has {0} outputs where the max allowed is {1}")]
28    TooManyOutputs(usize, usize),
29
30    #[error("transaction input #{0} signature script is above {1} bytes")]
31    TooBigSignatureScript(usize, usize),
32
33    #[error("transaction input #{0} signature script is above {1} bytes")]
34    TooBigScriptPublicKey(usize, usize),
35
36    #[error("transaction input #{0} is not finalized")]
37    NotFinalized(usize),
38
39    #[error("coinbase transaction has {0} inputs while none are expected")]
40    CoinbaseHasInputs(usize),
41
42    #[error("coinbase transaction has {0} outputs while at most {1} are expected")]
43    CoinbaseTooManyOutputs(usize, u64),
44
45    #[error("script public key of coinbase output #{0} is too long")]
46    CoinbaseScriptPublicKeyTooLong(usize),
47
48    #[error(
49        "transaction input #{0} tried to spend coinbase outpoint {1} with daa score of {2} 
50    while the merging block daa score is {3} and the coinbase maturity period of {4} hasn't passed yet"
51    )]
52    ImmatureCoinbaseSpend(usize, TransactionOutpoint, u64, u64, u64),
53
54    #[error("transaction total inputs spending amount overflowed u64")]
55    InputAmountOverflow,
56
57    #[error("transaction total inputs spending amount is higher than the max allowed of {}", MAX_SOMPI)]
58    InputAmountTooHigh,
59
60    #[error("transaction output {0} has zero value")]
61    TxOutZero(usize),
62
63    #[error("transaction output {0} value is higher than the max allowed of {}", MAX_SOMPI)]
64    TxOutTooHigh(usize),
65
66    #[error("transaction total outputs value overflowed u64")]
67    OutputsValueOverflow,
68
69    #[error("transaction total outputs value is higher than the max allowed of {}", MAX_SOMPI)]
70    TotalTxOutTooHigh,
71
72    #[error("transaction tries to spend {0} while its total inputs amount is {1}")]
73    SpendTooHigh(u64, u64),
74
75    #[error("one of the transaction sequence locks conditions was not met")]
76    SequenceLockConditionsAreNotMet,
77
78    #[error("outpoints corresponding to some transaction inputs are missing from current utxo context")]
79    MissingTxOutpoints,
80
81    #[error("failed to verify the signature script: {0}")]
82    SignatureInvalid(TxScriptError),
83
84    #[error("failed to verify empty signature script. Inner error: {0}")]
85    SignatureEmpty(TxScriptError),
86
87    #[error("input {0} sig op count is {1}, but the calculated value is {2}")]
88    WrongSigOpCount(usize, u64, u64),
89
90    #[error("contextual mass (including storage mass) is incomputable")]
91    MassIncomputable,
92
93    #[error("calculated contextual mass (including storage mass) {0} is not equal to the committed mass field {1}")]
94    WrongMass(u64, u64),
95
96    #[error("transaction subnetwork id {0} is neither native nor coinbase")]
97    SubnetworksDisabled(SubnetworkId),
98
99    /// [`TxRuleError::FeerateTooLow`] is not a consensus error but a mempool error triggered by the
100    /// fee/mass RBF validation rule
101    #[error("fee rate per contextual mass gram is not greater than the fee rate of the replaced transaction")]
102    FeerateTooLow,
103}
104
105pub type TxResult<T> = std::result::Result<T, TxRuleError>;