This is based on https://proposals.decred.org/proposals/c96290a but was modified in order to deal with realities that were unknown at the time of the specification draft. It is large and could not really be broken apart due to the pervasive use of the isTreasuryEnabled flag. It was primarily authored by * Marco Peereboom <marco@peereboom.us> * Dave Collins <davec@conformal.com> * Matheus Degiovani <opensource@matheusd.com> With additional contributions from * Donald Adu-Poku <donald.adu@gmail.com> * Jamie Holdstock <jholdstock@decred.org> Major changes: * Add decentralized treasury agenda, as specified in DCP0006, to all supported nets. * Add functions to determine if the decentralized treasury agenda is active at given block. * Add new opcode OP_TADD that is a nop in txscript but is used to tag scripts that credit the treasury account. This opcode is overloaded for treasurybase and for normal transactions. * Add new opcode OP_TSPEND that is a nop in txscript but is used to tag scripts that debit the treasury account. * Add new opcode OP_TGEN that is a nop in txscript but is used to tag P2PKH and P2SH outputs in a TSpend transaction. * Add functions that detect if a transaction is a valid TAdd, TSpend or treasurybase transaction. * Add error codes that return specific treasurybase/TAdd/TSpend consensus violations. * Modify countSpentOutputs to deal with treasury opcodes accordingly. * Modify indexBlock to skip treasury transactions that do not have inputs. * Add IsTreasuryEnabled call to ChainQueryer interface. * Add treasury logger for debugging and logging the decentralized treasury subsystem. * Add IsTreasuryActive flag to BlockConnectedNtfnsData and BlockDisconnectedNtfnsData. * Modify OP_SSGEN to allow an optional output that contains votes for a TSpend transaction hash. * Add function that returns TSpend votes from an SSGen transaction. * Modify CalcStakeVoteSubsidy so that treasurybase, unlike coinbase, is always awarded the full percentage of the assigned block reward. * Add helper functions to do all TSpend math so that callers don't roll their own. * Modify IsCoinBaseTx to not mistake a TSpend transaction as a coinbase. * Add checkTreasuryBase function that verifies that a treasurybase is properly constructed and pays the right amount to the treasury account. * Add functions to calculate treasury balance for the provided block hash/node. * Add function that verifies if a TSpend has a valid signature. * Add functions to determine if a TSpend is not overspending. * Add function to determine if a TSpend has been mined on the provided chain. * Add functions that count and verifies treasury spend votes. * Modify connectTransaction and disconnectTransactions to deal with the various treasury transactions. * Split CheckTransactionSanity in two functions checkTransactionSanityContextFree and checkTransactionSanityContextual. This is done in order to keep the decentralized treasury, which is always contextual, from infecting the context free checks. * Modify checkTransactionSanityContextual to recognize and verify treasury transactions. * Modify CheckTransactionSanity to deal with treasury transactions. * Split checkBlockSanity in two functions checkBlockSanityContextFree and checkBlockSanityContextual. This is done in order to keep the decentralized treasury, which is always contextual, from infecting the context free checks. * Modify checkBlockSanityContextual to enforce treasurybase and TAdd consensus checks. * Modify checkBlockPositional by unindenting it and adding TSpend consensus enforcement. * Modify checkCoinbaseUniqueHeightWithAddress to deal with the removal of the project subsidy from output 0. * Add checkCoinbaseUniqueHeightWithTreasuryBase that verifies coinbase and treasurybase in the provided block. * Unindent checkBlockContext. * Modify checkTicketRedeemerCommitments and checkVoteInputs to deal with potential tspend votes. * Modify CheckTransactionInputs to skip treasurybase transactions. * Modify CheckTransactionInputs to deal with TSpend transactions. Ensure the provided Pi key is valid and that the signature is valid for the transaction. Ensure that treasury TAdd and TSpend transaction utxo can only be spent after coinbase maturity. * Modify CountSigOps to deal with treasury transactions. * Modify CountP2SHSigOps to deal with treasury transactions. * Modify getStakeTreeFees to skip treasury transactions. Modify totalOutputs to subtract ValueIn 0 for TSpend and treasurybase transactions. * Modify checkTransactionsAndConnect to deal with modified amounts. * Add tspendChecks function that verifies an entire TSpend transaction validity at the point of the provided block. It ensures a TSpend is on a TVI. It ensures the TSpend is in the valid window. It verifies that a TSpend In and Out amounts match. It ensures a TSpend has the ValueIn amount encoded in the OP_RETURN in Out 0. It ensures a TSpend has not been mined before on this chain. It ensures a TSpend has the requisite votes. It ensures a TSpend is not overspending. * Modify checkConnectBlock to call checkTreasuryBase and tspendChecks when treasury agenda is active. * Add two tables to the database. Table "treasury" records the balance as of this block and balance changes that occurred in this block which will become active in CoinbaseMaturity blocks. Table "tspend" records all block hashes where a TSpend has been mined this is to detect forks and prevent a Tspend from being mined more than once. * Modify handleBlockchainNotification to communicate if the treasury agenda is active and skip treasurybase transaction when needed. * Add various Treasury parameters to chaincfg params. * Add hardcoded Tspend signatures in dcr_tmux_simnet_setup.sh. * Add notifytspend and stoptspend calls to the RPC server. notifytspend notifies the mempool when a TSpend transaction arrives. * Modify commit filters V2 to recognize TAdd and TSpend transactions. It was possible to modify V2 instead of introducing V3 because nothing changes from the viewpoint of the wallet and treasury opcodes are disallowed prior to agenda activation. * Modify AddMemPoolTransaction to skip TSpend transactions that would throw the fee estimator off. * Add IsTreasuryAgendaActive, OnTSpendReceived and TSpendMinedOnAncestor to mempool.Config in order to reject/accept TSpends in the mempool. * Modify checkPoolDoubleSpend to ignore treasurybase. * Modify mempool.maybeAcceptTransaction to enforce treasury standardness rules. Don't allow TSpend transactions prior to stake validation height. Skip treasurybase and tspend transactions in the orphan test. Ensure a tspend is in a valid window. Ensure not more than 7 TSpends are active in the mempool. Ensure TSpend has a well-known Pi key. Ensure The provided Pi key was used to sign the transaction. Ensure TSpend was not mined in an ancestor block. Notify subscribers that a valid TSpend was received. * Add standardCoinbaseOpReturn and standardTreasurybaseOpReturn to create an OP_RETURN followed by a data push that little endian encodes the height of the block. Then there are a number of random bytes to ensure that the transaction hash is always random. * Modify createCoinbaseTx to create a coinbase that is valid when treasury is enabled or not. Additionally, alter the transaction version if treasury is enabled. * Add createTreasuryBaseTx that creates a standard treasurybase. * Modify maybeInsertStakeTx to recognize treasurybase and TSpend transactions. * Modify handleTooFewVoters to call createTreasuryBaseTx when the treasury agenda is active. Skip copying treasurybase. * Modify NewBlockTemplate to recognize and deal with treasury transactions. Skip TSpend transaction if block is not a TVI. Skip TSpend transaction if it is not in the proper window. Skip TSpend transaction if a TSpend does not have enough yes votes. Skip TSpend transaction if it overspends the treasury account. Skip TAdd if there are more than 20 TAdds in the block. Create treasurybase if required. Insert valid TAdd/TSpend transactions into stake tree. * Add TreasuryBalance and IsTreasuryAgendaActive to rpcserver Chain interface. * Add gettreasurybalance, sendfromtreasury and sendtotreasury calls to RPC server. * Add notifytspend and stopnotifytspend to RPC websocket commands. * Add simnet miner to generate large number of blocks during rpctests without triggering PoW difficulty increases. This is used to verify various treasury and tspend conditions during CI/CT. * Modify RPC voting wallet to also vote on TSpends. * Add json tests to verify all new opcodes and corner cases in the script engine. * Modify isStakeOpcode to recognize treasury opcodes. * Modify countSigOpsV0 to count TSpends. * Modify handleStakeOutSign to deal with TSpends. * Modify SignTxOutput to recognize TSpends. * Add TSpendSignatureScript that signs a TSpend transaction. * Add TreasuryAddTy and TreasurySpendTy types to the standard scripts. * Add isTreasuryAddScript and isTreasurySpendScript functions that recognize a form of TAdd and TSpend transactions. * Modify ExtractPkScriptAddrs to deal with TAdd and TSpend outputs. * Add TxVersionSeqLock = 2 and TxVersionTreasury = 3 to wire. This is used to discriminate between treasury and non-treasury scripts. * Rig up all functions that need the isTreasuryEnabledflag directly or indirectly. * Shuffle various functions around and export them when they were needed to be called from other packages. * Added and modified numerous tests to verify (hopefully) all corner cases that the decentralized treasury agenda has added.
405 lines
15 KiB
Go
405 lines
15 KiB
Go
// Copyright (c) 2014 Conformal Systems LLC.
|
|
// Copyright (c) 2015-2016 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package stake
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// ErrorCode identifies a kind of error.
|
|
type ErrorCode int
|
|
|
|
// These constants are used to identify a specific RuleError.
|
|
const (
|
|
// ErrSStxTooManyInputs indicates that a given SStx contains too many
|
|
// inputs.
|
|
ErrSStxTooManyInputs = iota
|
|
|
|
// ErrSStxTooManyOutputs indicates that a given SStx contains too many
|
|
// outputs.
|
|
ErrSStxTooManyOutputs
|
|
|
|
// ErrSStxNoOutputs indicates that a given SStx has no outputs.
|
|
ErrSStxNoOutputs
|
|
|
|
// ErrSStxInvalidInput indicates that an invalid output has been used as
|
|
// an input for a SStx; only non-SStx tagged outputs may be used to
|
|
// purchase stake tickets.
|
|
// TODO: Add this into validate
|
|
// Ensure that all inputs are not tagged SStx outputs of some sort,
|
|
// along with checks to make sure they exist and are available.
|
|
ErrSStxInvalidInputs
|
|
|
|
// ErrSStxInvalidOutput indicates that the output for an SStx tx is
|
|
// invalid; in particular, either the output was not tagged SStx or the
|
|
// OP_RETURNs were missing or contained invalid addresses.
|
|
ErrSStxInvalidOutputs
|
|
|
|
// ErrSStxInOutProportions indicates the number of inputs in an SStx
|
|
// was not equal to the number of output minus one.
|
|
ErrSStxInOutProportions
|
|
|
|
// ErrSStxBadCommitAmount indicates that a ticket tried to commit 0 or
|
|
// a negative value as the commitment amount.
|
|
ErrSStxBadCommitAmount
|
|
|
|
// ErrSStxBadChangeAmts indicates that the change amount for some SStx
|
|
// was invalid, for instance spending more than its inputs.
|
|
ErrSStxBadChangeAmts
|
|
|
|
// ErrSStxVerifyCalcAmts indicates that passed calculated amounts failed
|
|
// to conform to the amounts found in the ticket.
|
|
ErrSStxVerifyCalcAmts
|
|
|
|
// ErrSSGenWrongNumInputs indicates that a given SSGen tx contains an
|
|
// invalid number of inputs.
|
|
ErrSSGenWrongNumInputs
|
|
|
|
// ErrSSGenTooManyOutputs indicates that a given SSGen tx contains too
|
|
// many outputs.
|
|
ErrSSGenTooManyOutputs
|
|
|
|
// ErrSSGenNoOutputs indicates that a given SSGen has no outputs.
|
|
ErrSSGenNoOutputs
|
|
|
|
// ErrSSGenWrongIndex indicates that a given SSGen sstx input was not
|
|
// using the correct index.
|
|
ErrSSGenWrongIndex
|
|
|
|
// ErrSSGenWrongTxTree indicates that a given SSGen tx input was not found in
|
|
// the stake tx tree.
|
|
ErrSSGenWrongTxTree
|
|
|
|
// ErrSSGenNoStakebase indicates that the SSGen tx did not contain a
|
|
// valid StakeBase in the zeroeth position of inputs.
|
|
ErrSSGenNoStakebase
|
|
|
|
// ErrSSGenNoReference indicates that there is no reference OP_RETURN
|
|
// included as the first output.
|
|
ErrSSGenNoReference
|
|
|
|
// ErrSSGenNoReference indicates that the OP_RETURN included as the
|
|
// first output was corrupted in some way.
|
|
ErrSSGenBadReference
|
|
|
|
// ErrSSGenNoVotePush indicates that there is no vote bits OP_RETURN
|
|
// included as the second output.
|
|
ErrSSGenNoVotePush
|
|
|
|
// ErrSSGenBadVotePush indicates that the OP_RETURN included as the
|
|
// second output was corrupted in some way.
|
|
ErrSSGenBadVotePush
|
|
|
|
// ErrSSGenInvalidDiscriminatorLength indicates that the discriminator
|
|
// length is too short.
|
|
ErrSSGenInvalidDiscriminatorLength
|
|
|
|
// ErrSSGenInvalidNullScript indicates that the passed script is not a
|
|
// valid nullscript.
|
|
ErrSSGenInvalidNullScript
|
|
|
|
// ErrSSGenInvalidTVLength indicates that this is an invalid Treasury
|
|
// Vote length.
|
|
ErrSSGenInvalidTVLength
|
|
|
|
// ErrSSGenInvalidTreasuryVote indicates that this is an invalid
|
|
// treasury vote.
|
|
ErrSSGenInvalidTreasuryVote
|
|
|
|
// ErrSSGenDuplicateTreasuryVote indicates that there is a duplicate
|
|
// treasury vote.
|
|
ErrSSGenDuplicateTreasuryVote
|
|
|
|
// ErrSSGenInvalidTxVersion indicates that this transaction has the
|
|
// wrong version.
|
|
ErrSSGenInvalidTxVersion
|
|
|
|
// ErrSSGenUnknownDiscriminator indicates that the supplied
|
|
// discriminator is unsupported.
|
|
ErrSSGenUnknownDiscriminator
|
|
|
|
// ErrSSGenBadGenOuts indicates that something was wrong with the stake
|
|
// generation outputs that were present after the first two OP_RETURN
|
|
// pushes in an SSGen tx.
|
|
ErrSSGenBadGenOuts
|
|
|
|
// ErrSSRtxWrongNumInputs indicates that a given SSRtx contains an
|
|
// invalid number of inputs.
|
|
ErrSSRtxWrongNumInputs
|
|
|
|
// ErrSSRtxTooManyOutputs indicates that a given SSRtx contains too many
|
|
// outputs.
|
|
ErrSSRtxTooManyOutputs
|
|
|
|
// ErrSSRtxNoOutputs indicates that a given SSRtx has no outputs.
|
|
ErrSSRtxNoOutputs
|
|
|
|
// ErrSSRtxWrongTxTree indicates that a given SSRtx input was not found in
|
|
// the stake tx tree.
|
|
ErrSSRtxWrongTxTree
|
|
|
|
// ErrSSRtxBadGenOuts indicates that there was a non-SSRtx tagged output
|
|
// present in an SSRtx.
|
|
ErrSSRtxBadOuts
|
|
|
|
// ErrVerSStxAmts indicates there was an error verifying the calculated
|
|
// SStx out amounts and the actual SStx out amounts.
|
|
ErrVerSStxAmts
|
|
|
|
// ErrVerifyInput indicates that there was an error in verification
|
|
// function input.
|
|
ErrVerifyInput
|
|
|
|
// ErrVerifyOutType indicates that there was a non-equivalence in the
|
|
// output type.
|
|
ErrVerifyOutType
|
|
|
|
// ErrVerifyTooMuchFees indicates that a transaction's output gave
|
|
// too much in fees after taking into accounts the limits imposed
|
|
// by the SStx output's version field.
|
|
ErrVerifyTooMuchFees
|
|
|
|
// ErrVerifySpendTooMuch indicates that a transaction's output spent more
|
|
// than it was allowed to spend based on the calculated subsidy or return
|
|
// for a vote or revocation.
|
|
ErrVerifySpendTooMuch
|
|
|
|
// ErrVerifyOutputAmt indicates that for a vote/revocation spend output,
|
|
// the rule was given that it must exactly match the calculated maximum,
|
|
// however the amount in the output did not (e.g. it gave fees).
|
|
ErrVerifyOutputAmt
|
|
|
|
// ErrVerifyOutPkhs indicates that the recipient of the P2PKH or P2SH
|
|
// script was different from that indicated in the SStx input.
|
|
ErrVerifyOutPkhs
|
|
|
|
// ErrDatabaseCorrupt indicates a database inconsistency.
|
|
ErrDatabaseCorrupt
|
|
|
|
// ErrMissingDatabaseTx indicates that a node disconnection failed to
|
|
// pass a database transaction when attempted to remove a very old
|
|
// node.
|
|
ErrMissingDatabaseTx
|
|
|
|
// ErrMemoryCorruption indicates that memory has somehow become corrupt,
|
|
// for example invalid block header serialization from an in memory
|
|
// struct.
|
|
ErrMemoryCorruption
|
|
|
|
// ErrFindTicketIdxs indicates a failure to find the selected ticket
|
|
// indexes from the block header.
|
|
ErrFindTicketIdxs
|
|
|
|
// ErrMissingTicket indicates that a ticket was missing in one of the
|
|
// ticket treaps when it was attempted to be fetched.
|
|
ErrMissingTicket
|
|
|
|
// ErrDuplicateTicket indicates that a duplicate ticket was attempted
|
|
// to be inserted into a ticket treap or the database.
|
|
ErrDuplicateTicket
|
|
|
|
// ErrUnknownTicketSpent indicates that an unknown ticket was spent by
|
|
// the block.
|
|
ErrUnknownTicketSpent
|
|
|
|
// ErrTAddInvalidTxVersion indicates that this transaction has the
|
|
// wrong version.
|
|
ErrTAddInvalidTxVersion
|
|
|
|
// ErrTAddInvalidCount indicates that this transaction contains an
|
|
// invalid TADD script count.
|
|
ErrTAddInvalidCount
|
|
|
|
// ErrTAddInvalidVersion indicates that this transaction has an invalid
|
|
// version in an output script.
|
|
ErrTAddInvalidVersion
|
|
|
|
// ErrTAddInvalidScriptLength indicates that this transaction has a zero
|
|
// length output script.
|
|
ErrTAddInvalidScriptLength
|
|
|
|
// ErrTAddInvalidLength indicates that output 0 is not exactly 1 byte.
|
|
ErrTAddInvalidLength
|
|
|
|
// ErrTAddInvalidOpcode indicates that this transaction does not have a
|
|
// TADD opcode.
|
|
ErrTAddInvalidOpcode
|
|
|
|
// ErrTAddInvalidChange indicates that this transaction contains an
|
|
// invalid change script.
|
|
ErrTAddInvalidChange
|
|
|
|
// ErrTSpendInvalidTxVersion indicates that this transaction has
|
|
// the wrong version.
|
|
ErrTSpendInvalidTxVersion
|
|
|
|
// ErrTSpendInvalidLength indicates that this transaction has an
|
|
// invalid number of inputs and/or outputs.
|
|
ErrTSpendInvalidLength
|
|
|
|
// ErrTSpendInvalidVersion indicates that this transaction has an
|
|
// invalid version in an output script.
|
|
ErrTSpendInvalidVersion
|
|
|
|
// ErrTSpendInvalidScriptLength indicates that the TSPEND transaction
|
|
// has outputs that have a zero length script.
|
|
ErrTSpendInvalidScriptLength
|
|
|
|
// ErrTSpendInvalidPubkey indicates that this transaction contains an
|
|
// invalid public key.
|
|
ErrTSpendInvalidPubkey
|
|
|
|
// ErrTSpendInvalidScript indicates that this transaction does not
|
|
// match the required TSPEND transaction signature.
|
|
ErrTSpendInvalidScript
|
|
|
|
// ErrTSpendInvalidTGen indicates that the TSPEND transaction has
|
|
// outputs that are not tagged with OP_TGEN.
|
|
ErrTSpendInvalidTGen
|
|
|
|
// ErrTSpendInvalidTransaction indicates that a TSPEND transaction
|
|
// output 0 does not have an a valid null data script.
|
|
ErrTSpendInvalidTransaction
|
|
|
|
// ErrTSpendInvalidSpendScript indicates that this transaction contains
|
|
// an invalid P2SH or P2PKH script.
|
|
ErrTSpendInvalidSpendScript
|
|
|
|
// ErrTreasuryBaseInvalidTxVersion indicates that this transaction has
|
|
// the wrong version.
|
|
ErrTreasuryBaseInvalidTxVersion
|
|
|
|
// ErrTreasuryBaseInvalidCount indicates that this transaction contains
|
|
// an invalid treasury base script count.
|
|
ErrTreasuryBaseInvalidCount
|
|
|
|
// ErrTreasuryBaseInvalidLength indicates that this transaction contains
|
|
// an invalid treasury base input script length.
|
|
ErrTreasuryBaseInvalidLength
|
|
|
|
// ErrTreasuryBaseInvalidVersion indicates that this transaction has an
|
|
// invalid version in an output script.
|
|
ErrTreasuryBaseInvalidVersion
|
|
|
|
// ErrTreasuryBaseInvalidOpcode0 indicates that this transaction does
|
|
// not have a TADD opcode in TxOut[0].
|
|
ErrTreasuryBaseInvalidOpcode0
|
|
|
|
// ErrTreasuryBaseInvalidOpcode1 indicates that this transaction does
|
|
// not have an OP_RETURN opcode in TxOut[1].
|
|
ErrTreasuryBaseInvalidOpcode1
|
|
|
|
// ErrTreasuryBaseInvalid indicates that this transaction contains
|
|
// invalid treasurybase TxIn constants.
|
|
ErrTreasuryBaseInvalid
|
|
)
|
|
|
|
// Map of ErrorCode values back to their constant names for pretty printing.
|
|
var errorCodeStrings = map[ErrorCode]string{
|
|
ErrSStxTooManyInputs: "ErrSStxTooManyInputs",
|
|
ErrSStxTooManyOutputs: "ErrSStxTooManyOutputs",
|
|
ErrSStxNoOutputs: "ErrSStxNoOutputs",
|
|
ErrSStxInvalidInputs: "ErrSStxInvalidInputs",
|
|
ErrSStxInvalidOutputs: "ErrSStxInvalidOutputs",
|
|
ErrSStxInOutProportions: "ErrSStxInOutProportions",
|
|
ErrSStxBadCommitAmount: "ErrSStxBadCommitAmount",
|
|
ErrSStxBadChangeAmts: "ErrSStxBadChangeAmts",
|
|
ErrSStxVerifyCalcAmts: "ErrSStxVerifyCalcAmts",
|
|
ErrSSGenWrongNumInputs: "ErrSSGenWrongNumInputs",
|
|
ErrSSGenTooManyOutputs: "ErrSSGenTooManyOutputs",
|
|
ErrSSGenNoOutputs: "ErrSSGenNoOutputs",
|
|
ErrSSGenWrongIndex: "ErrSSGenWrongIndex",
|
|
ErrSSGenWrongTxTree: "ErrSSGenWrongTxTree",
|
|
ErrSSGenNoStakebase: "ErrSSGenNoStakebase",
|
|
ErrSSGenNoReference: "ErrSSGenNoReference",
|
|
ErrSSGenBadReference: "ErrSSGenBadReference",
|
|
ErrSSGenNoVotePush: "ErrSSGenNoVotePush",
|
|
ErrSSGenBadVotePush: "ErrSSGenBadVotePush",
|
|
ErrSSGenInvalidDiscriminatorLength: "ErrSSGenInvalidDiscriminatorLength",
|
|
ErrSSGenInvalidNullScript: "ErrSSGenInvalidNullScript",
|
|
ErrSSGenInvalidTVLength: "ErrSSGenInvalidTVLength",
|
|
ErrSSGenInvalidTreasuryVote: "ErrSSGenInvalidTreasuryVote",
|
|
ErrSSGenDuplicateTreasuryVote: "ErrSSGenDuplicateTreasuryVote",
|
|
ErrSSGenInvalidTxVersion: "ErrSSGenInvalidTxVersion",
|
|
ErrSSGenUnknownDiscriminator: "ErrSSGenUnknownDiscriminator",
|
|
ErrSSGenBadGenOuts: "ErrSSGenBadGenOuts",
|
|
ErrSSRtxWrongNumInputs: "ErrSSRtxWrongNumInputs",
|
|
ErrSSRtxTooManyOutputs: "ErrSSRtxTooManyOutputs",
|
|
ErrSSRtxNoOutputs: "ErrSSRtxNoOutputs",
|
|
ErrSSRtxWrongTxTree: "ErrSSRtxWrongTxTree",
|
|
ErrSSRtxBadOuts: "ErrSSRtxBadOuts",
|
|
ErrVerSStxAmts: "ErrVerSStxAmts",
|
|
ErrVerifyInput: "ErrVerifyInput",
|
|
ErrVerifyOutType: "ErrVerifyOutType",
|
|
ErrVerifyTooMuchFees: "ErrVerifyTooMuchFees",
|
|
ErrVerifySpendTooMuch: "ErrVerifySpendTooMuch",
|
|
ErrVerifyOutputAmt: "ErrVerifyOutputAmt",
|
|
ErrVerifyOutPkhs: "ErrVerifyOutPkhs",
|
|
ErrDatabaseCorrupt: "ErrDatabaseCorrupt",
|
|
ErrMissingDatabaseTx: "ErrMissingDatabaseTx",
|
|
ErrMemoryCorruption: "ErrMemoryCorruption",
|
|
ErrFindTicketIdxs: "ErrFindTicketIdxs",
|
|
ErrMissingTicket: "ErrMissingTicket",
|
|
ErrDuplicateTicket: "ErrDuplicateTicket",
|
|
ErrUnknownTicketSpent: "ErrUnknownTicketSpent",
|
|
ErrTAddInvalidTxVersion: "ErrTAddInvalidTxVersion",
|
|
ErrTAddInvalidCount: "ErrTAddInvalidCount",
|
|
ErrTAddInvalidVersion: "ErrTAddInvalidVersion",
|
|
ErrTAddInvalidScriptLength: "ErrTAddInvalidScriptLength",
|
|
ErrTAddInvalidLength: "ErrTAddInvalidLength",
|
|
ErrTAddInvalidOpcode: "ErrTAddInvalidOpcode",
|
|
ErrTAddInvalidChange: "ErrTAddInvalidChange",
|
|
ErrTSpendInvalidTxVersion: "ErrTSpendInvalidTxVersion",
|
|
ErrTSpendInvalidLength: "ErrTSpendInvalidLength",
|
|
ErrTSpendInvalidVersion: "ErrTSpendInvalidVersion",
|
|
ErrTSpendInvalidScriptLength: "ErrTSpendInvalidScriptLength",
|
|
ErrTSpendInvalidPubkey: "ErrTSpendInvalidPubkey",
|
|
ErrTSpendInvalidScript: "ErrTSpendInvalidScript",
|
|
ErrTSpendInvalidTransaction: "ErrTSpendInvalidTransaction",
|
|
ErrTSpendInvalidTGen: "ErrTSpendInvalidTGen",
|
|
ErrTSpendInvalidSpendScript: "ErrTSpendInvalidSpendScript",
|
|
ErrTreasuryBaseInvalidTxVersion: "ErrTreasuryBaseInvalidTxVersion",
|
|
ErrTreasuryBaseInvalidCount: "ErrTreasuryBaseInvalidCount",
|
|
ErrTreasuryBaseInvalidLength: "ErrTreasuryBaseInvalidLength",
|
|
ErrTreasuryBaseInvalidVersion: "ErrTreasuryBaseInvalidVersion",
|
|
ErrTreasuryBaseInvalidOpcode0: "ErrTreasuryBaseInvalidOpcode0",
|
|
ErrTreasuryBaseInvalidOpcode1: "ErrTreasuryBaseInvalidOpcode1",
|
|
ErrTreasuryBaseInvalid: "ErrTreasuryBaseInvalid",
|
|
}
|
|
|
|
// String returns the ErrorCode as a human-readable name.
|
|
func (e ErrorCode) String() string {
|
|
if s := errorCodeStrings[e]; s != "" {
|
|
return s
|
|
}
|
|
return fmt.Sprintf("Unknown ErrorCode (%d)", int(e))
|
|
}
|
|
|
|
// RuleError identifies a rule violation. It is used to indicate that
|
|
// processing of a block or transaction failed due to one of the many validation
|
|
// rules. The caller can use type assertions to determine if a failure was
|
|
// specifically due to a rule violation and access the ErrorCode field to
|
|
// ascertain the specific reason for the rule violation.
|
|
type RuleError struct {
|
|
ErrorCode ErrorCode // Describes the kind of error
|
|
Description string // Human readable description of the issue
|
|
}
|
|
|
|
// Error satisfies the error interface and prints human-readable errors.
|
|
func (e RuleError) Error() string {
|
|
return e.Description
|
|
}
|
|
|
|
// GetCode satisfies the error interface and prints human-readable errors.
|
|
func (e RuleError) GetCode() ErrorCode {
|
|
return e.ErrorCode
|
|
}
|
|
|
|
// stakeRuleError creates a RuleError given a set of arguments.
|
|
func stakeRuleError(c ErrorCode, desc string) RuleError {
|
|
return RuleError{ErrorCode: c, Description: desc}
|
|
}
|