github.com/decred/dcrd/blockchain@v1.2.1/error.go (about) 1 // Copyright (c) 2014-2016 The btcsuite developers 2 // Copyright (c) 2015-2019 The Decred developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package blockchain 7 8 import ( 9 "fmt" 10 ) 11 12 // VoteVersionError identifies an error that indicates a vote version was 13 // specified that does not exist. 14 type VoteVersionError uint32 15 16 // Error returns the assertion error as a human-readable string and satisfies 17 // the error interface. 18 func (e VoteVersionError) Error() string { 19 return fmt.Sprintf("stake version %v does not exist", uint32(e)) 20 } 21 22 // HashError identifies an error that indicates a hash was specified that does 23 // not exist. 24 type HashError string 25 26 // Error returns the error as a human-readable string and satisfies the error 27 // interface. 28 func (e HashError) Error() string { 29 return fmt.Sprintf("hash %v does not exist", string(e)) 30 } 31 32 // DeploymentError identifies an error that indicates a deployment ID was 33 // specified that does not exist. 34 type DeploymentError string 35 36 // Error returns the assertion error as a human-readable string and satisfies 37 // the error interface. 38 func (e DeploymentError) Error() string { 39 return fmt.Sprintf("deployment ID %v does not exist", string(e)) 40 } 41 42 // DuplicateDeploymentError identifies an error that indicates a duplicate 43 // deployment ID was specified in the network parameter deployment definitions. 44 type DuplicateDeploymentError string 45 46 // Error returns the assertion error as a human-readable string and satisfies 47 // the error interface. 48 func (e DuplicateDeploymentError) Error() string { 49 return fmt.Sprintf("deployment ID %v exists in more than one deployment", 50 string(e)) 51 } 52 53 // AssertError identifies an error that indicates an internal code consistency 54 // issue and should be treated as a critical and unrecoverable error. 55 type AssertError string 56 57 // Error returns the assertion error as a huma-readable string and satisfies 58 // the error interface. 59 func (e AssertError) Error() string { 60 return "assertion failed: " + string(e) 61 } 62 63 // ErrorCode identifies a kind of error. 64 type ErrorCode int 65 66 // These constants are used to identify a specific RuleError. 67 const ( 68 // ErrDuplicateBlock indicates a block with the same hash already 69 // exists. 70 ErrDuplicateBlock ErrorCode = iota 71 72 // ErrMissingParent indicates that the block was an orphan. 73 ErrMissingParent 74 75 // ErrBlockTooBig indicates the serialized block size exceeds the 76 // maximum allowed size. 77 ErrBlockTooBig 78 79 // ErrWrongBlockSize indicates that the block size in the header is not 80 // the actual serialized size of the block. 81 ErrWrongBlockSize 82 83 // ErrBlockVersionTooOld indicates the block version is too old and is 84 // no longer accepted since the majority of the network has upgraded 85 // to a newer version. 86 ErrBlockVersionTooOld 87 88 // ErrBadStakeVersionindicates the block version is too old and is no 89 // longer accepted since the majority of the network has upgraded to a 90 // newer version. 91 ErrBadStakeVersion 92 93 // ErrInvalidTime indicates the time in the passed block has a precision 94 // that is more than one second. The chain consensus rules require 95 // timestamps to have a maximum precision of one second. 96 ErrInvalidTime 97 98 // ErrTimeTooOld indicates the time is either before the median time of 99 // the last several blocks per the chain consensus rules or prior to the 100 // most recent checkpoint. 101 ErrTimeTooOld 102 103 // ErrTimeTooNew indicates the time is too far in the future as compared 104 // the current time. 105 ErrTimeTooNew 106 107 // ErrDifficultyTooLow indicates the difficulty for the block is lower 108 // than the difficulty required by the most recent checkpoint. 109 ErrDifficultyTooLow 110 111 // ErrUnexpectedDifficulty indicates specified bits do not align with 112 // the expected value either because it doesn't match the calculated 113 // valued based on difficulty regarted rules or it is out of the valid 114 // range. 115 ErrUnexpectedDifficulty 116 117 // ErrHighHash indicates the block does not hash to a value which is 118 // lower than the required target difficultly. 119 ErrHighHash 120 121 // ErrBadMerkleRoot indicates the calculated merkle root does not match 122 // the expected value. 123 ErrBadMerkleRoot 124 125 // ErrBadCheckpoint indicates a block that is expected to be at a 126 // checkpoint height does not match the expected one. 127 ErrBadCheckpoint 128 129 // ErrForkTooOld indicates a block is attempting to fork the block chain 130 // before the most recent checkpoint. 131 ErrForkTooOld 132 133 // ErrCheckpointTimeTooOld indicates a block has a timestamp before the 134 // most recent checkpoint. 135 ErrCheckpointTimeTooOld 136 137 // ErrNoTransactions indicates the block does not have a least one 138 // transaction. A valid block must have at least the coinbase 139 // transaction. 140 ErrNoTransactions 141 142 // ErrTooManyTransactions indicates the block has more transactions than 143 // are allowed. 144 ErrTooManyTransactions 145 146 // ErrNoTxInputs indicates a transaction does not have any inputs. A 147 // valid transaction must have at least one input. 148 ErrNoTxInputs 149 150 // ErrNoTxOutputs indicates a transaction does not have any outputs. A 151 // valid transaction must have at least one output. 152 ErrNoTxOutputs 153 154 // ErrTxTooBig indicates a transaction exceeds the maximum allowed size 155 // when serialized. 156 ErrTxTooBig 157 158 // ErrBadTxOutValue indicates an output value for a transaction is 159 // invalid in some way such as being out of range. 160 ErrBadTxOutValue 161 162 // ErrDuplicateTxInputs indicates a transaction references the same 163 // input more than once. 164 ErrDuplicateTxInputs 165 166 // ErrBadTxInput indicates a transaction input is invalid in some way 167 // such as referencing a previous transaction outpoint which is out of 168 // range or not referencing one at all. 169 ErrBadTxInput 170 171 // ErrMissingTxOut indicates a transaction output referenced by an input 172 // either does not exist or has already been spent. 173 ErrMissingTxOut 174 175 // ErrUnfinalizedTx indicates a transaction has not been finalized. 176 // A valid block may only contain finalized transactions. 177 ErrUnfinalizedTx 178 179 // ErrDuplicateTx indicates a block contains an identical transaction 180 // (or at least two transactions which hash to the same value). A 181 // valid block may only contain unique transactions. 182 ErrDuplicateTx 183 184 // ErrOverwriteTx indicates a block contains a transaction that has 185 // the same hash as a previous transaction which has not been fully 186 // spent. 187 ErrOverwriteTx 188 189 // ErrImmatureSpend indicates a transaction is attempting to spend a 190 // coinbase that has not yet reached the required maturity. 191 ErrImmatureSpend 192 193 // ErrSpendTooHigh indicates a transaction is attempting to spend more 194 // value than the sum of all of its inputs. 195 ErrSpendTooHigh 196 197 // ErrBadFees indicates the total fees for a block are invalid due to 198 // exceeding the maximum possible value. 199 ErrBadFees 200 201 // ErrTooManySigOps indicates the total number of signature operations 202 // for a transaction or block exceed the maximum allowed limits. 203 ErrTooManySigOps 204 205 // ErrFirstTxNotCoinbase indicates the first transaction in a block 206 // is not a coinbase transaction. 207 ErrFirstTxNotCoinbase 208 209 // ErrCoinbaseHeight indicates that the encoded height in the coinbase 210 // is incorrect. 211 ErrCoinbaseHeight 212 213 // ErrMultipleCoinbases indicates a block contains more than one 214 // coinbase transaction. 215 ErrMultipleCoinbases 216 217 // ErrStakeTxInRegularTree indicates a stake transaction was found in 218 // the regular transaction tree. 219 ErrStakeTxInRegularTree 220 221 // ErrRegTxInStakeTree indicates that a regular transaction was found in 222 // the stake transaction tree. 223 ErrRegTxInStakeTree 224 225 // ErrBadCoinbaseScriptLen indicates the length of the signature script 226 // for a coinbase transaction is not within the valid range. 227 ErrBadCoinbaseScriptLen 228 229 // ErrBadCoinbaseValue indicates the amount of a coinbase value does 230 // not match the expected value of the subsidy plus the sum of all fees. 231 ErrBadCoinbaseValue 232 233 // ErrBadCoinbaseOutpoint indicates that the outpoint used by a coinbase 234 // as input was non-null. 235 ErrBadCoinbaseOutpoint 236 237 // ErrBadCoinbaseFraudProof indicates that the fraud proof for a coinbase 238 // input was non-null. 239 ErrBadCoinbaseFraudProof 240 241 // ErrBadCoinbaseAmountIn indicates that the AmountIn (=subsidy) for a 242 // coinbase input was incorrect. 243 ErrBadCoinbaseAmountIn 244 245 // ErrBadStakebaseAmountIn indicates that the AmountIn (=subsidy) for a 246 // stakebase input was incorrect. 247 ErrBadStakebaseAmountIn 248 249 // ErrBadStakebaseScriptLen indicates the length of the signature script 250 // for a stakebase transaction is not within the valid range. 251 ErrBadStakebaseScriptLen 252 253 // ErrBadStakebaseScrVal indicates the signature script for a stakebase 254 // transaction was not set to the network consensus value. 255 ErrBadStakebaseScrVal 256 257 // ErrScriptMalformed indicates a transaction script is malformed in 258 // some way. For example, it might be longer than the maximum allowed 259 // length or fail to parse. 260 ErrScriptMalformed 261 262 // ErrScriptValidation indicates the result of executing transaction 263 // script failed. The error covers any failure when executing scripts 264 // such signature verification failures and execution past the end of 265 // the stack. 266 ErrScriptValidation 267 268 // ErrNotEnoughStake indicates that there was for some SStx in a given block, 269 // the given SStx did not have enough stake to meet the network target. 270 ErrNotEnoughStake 271 272 // ErrStakeBelowMinimum indicates that for some SStx in a given block, 273 // the given SStx had an amount of stake below the minimum network target. 274 ErrStakeBelowMinimum 275 276 // ErrNonstandardStakeTx indicates that a block contained a stake tx that 277 // was not one of the allowed types of a stake transactions. 278 ErrNonstandardStakeTx 279 280 // ErrNotEnoughVotes indicates that a block contained less than a majority 281 // of voters. 282 ErrNotEnoughVotes 283 284 // ErrTooManyVotes indicates that a block contained more than the maximum 285 // allowable number of votes. 286 ErrTooManyVotes 287 288 // ErrFreshStakeMismatch indicates that a block's header contained a different 289 // number of SStx as compared to what was found in the block. 290 ErrFreshStakeMismatch 291 292 // ErrTooManySStxs indicates that more than the allowed number of SStx was 293 // found in a block. 294 ErrTooManySStxs 295 296 // ErrInvalidEarlyStakeTx indicates that a tx type other than SStx was found 297 // in the stake tx tree before the period when stake validation begins, or 298 // before the stake tx type could possibly be included in the block. 299 ErrInvalidEarlyStakeTx 300 301 // ErrTicketUnavailable indicates that a vote in the block spent a ticket 302 // that could not be found. 303 ErrTicketUnavailable 304 305 // ErrVotesOnWrongBlock indicates that an SSGen voted on a block not the 306 // block's parent, and so was ineligible for inclusion into that block. 307 ErrVotesOnWrongBlock 308 309 // ErrVotesMismatch indicates that the number of SSGen in the block was not 310 // equivalent to the number of votes provided in the block header. 311 ErrVotesMismatch 312 313 // ErrIncongruentVotebit indicates that the first votebit in votebits was not 314 // the same as that determined by the majority of voters in the SSGen tx 315 // included in the block. 316 ErrIncongruentVotebit 317 318 // ErrInvalidSSRtx indicates than an SSRtx in a block could not be found to 319 // have a valid missed sstx input as per the stake ticket database. 320 ErrInvalidSSRtx 321 322 // ErrInvalidRevNum indicates that the number of revocations from the 323 // header was not the same as the number of SSRtx included in the block. 324 ErrRevocationsMismatch 325 326 // ErrTooManyRevocations indicates more revocations were found in a block 327 // than were allowed. 328 ErrTooManyRevocations 329 330 // ErrTicketCommitment indicates that a ticket commitment contains an amount 331 // that does not coincide with the associated ticket input amount. 332 ErrTicketCommitment 333 334 // ErrInvalidVoteInput indicates that an input to a vote transaction is 335 // either not a stake ticket submission or is not a supported version. 336 ErrInvalidVoteInput 337 338 // ErrBadNumPayees indicates that either a vote or revocation transaction 339 // does not make the correct number of payments per the associated ticket 340 // commitments. 341 ErrBadNumPayees 342 343 // ErrBadPayeeScriptVersion indicates that either a vote or revocation 344 // transaction output that corresponds to a ticket commitment does not use 345 // a supported script version. 346 ErrBadPayeeScriptVersion 347 348 // ErrBadPayeeScriptType indicates that either a vote or revocation 349 // transaction output that corresponds to a ticket commitment does not pay 350 // to the same script type required by the commitment. 351 ErrBadPayeeScriptType 352 353 // ErrBadPayeeScriptType indicates that either a vote or revocation 354 // transaction output that corresponds to a ticket commitment does not pay 355 // to the hash required by the commitment. 356 ErrMismatchedPayeeHash 357 358 // ErrBadPayeeValue indicates that either a vote or revocation transaction 359 // output that corresponds to a ticket commitment does not pay the expected 360 // amount required by the commitment. 361 ErrBadPayeeValue 362 363 // ErrSSGenSubsidy indicates that there was an error in the amount of subsidy 364 // generated in the vote. 365 ErrSSGenSubsidy 366 367 // ErrImmatureTicketSpend indicates that a vote or revocation is attempting 368 // to spend a ticket submission output that has not yet reached the required 369 // maturity. 370 ErrImmatureTicketSpend 371 372 // ErrTicketInputScript indicates that a ticket input is not one of the 373 // supported script forms or versions. 374 ErrTicketInputScript 375 376 // ErrInvalidRevokeInput indicates that an input to a revocation transaction 377 // is either not a stake ticket submission or is not a supported version. 378 ErrInvalidRevokeInput 379 380 // ErrSSRtxPayees indicates that the SSRtx failed to pay out to the committed 381 // addresses or amounts from the originating SStx. 382 ErrSSRtxPayees 383 384 // ErrTxSStxOutSpend indicates that a non SSGen or SSRtx tx attempted to spend 385 // an OP_SSTX tagged output from an SStx. 386 ErrTxSStxOutSpend 387 388 // ErrRegTxCreateStakeOut indicates that a regular tx attempted to create 389 // a stake tagged output. 390 ErrRegTxCreateStakeOut 391 392 // ErrInvalidFinalState indicates that the final state of the PRNG included 393 // in the the block differed from the calculated final state. 394 ErrInvalidFinalState 395 396 // ErrPoolSize indicates an error in the ticket pool size for this block. 397 ErrPoolSize 398 399 // ErrForceReorgWrongChain indicates that a reroganization was attempted 400 // to be forced, but the chain indicated was not mirrored by b.bestChain. 401 ErrForceReorgWrongChain 402 403 // ErrForceReorgMissingChild indicates that a reroganization was attempted 404 // to be forced, but the child node to reorganize to could not be found. 405 ErrForceReorgMissingChild 406 407 // ErrBadStakebaseValue indicates that a block's stake tx tree has spent 408 // more than it is allowed. 409 ErrBadStakebaseValue 410 411 // ErrDiscordantTxTree specifies that a given origin tx's content 412 // indicated that it should exist in a different tx tree than the 413 // one given in the TxIn outpoint. 414 ErrDiscordantTxTree 415 416 // ErrStakeFees indicates an error with the fees found in the stake 417 // transaction tree. 418 ErrStakeFees 419 420 // ErrNoStakeTx indicates there were no stake transactions found in a 421 // block after stake validation height. 422 ErrNoStakeTx 423 424 // ErrBadBlockHeight indicates that a block header's embedded block height 425 // was different from where it was actually embedded in the block chain. 426 ErrBadBlockHeight 427 428 // ErrBlockOneTx indicates that block height 1 failed to correct generate 429 // the block one premine transaction. 430 ErrBlockOneTx 431 432 // ErrBlockOneTx indicates that block height 1 coinbase transaction in 433 // zero was incorrect in some way. 434 ErrBlockOneInputs 435 436 // ErrBlockOneOutputs indicates that block height 1 failed to incorporate 437 // the ledger addresses correctly into the transaction's outputs. 438 ErrBlockOneOutputs 439 440 // ErrNoTax indicates that there was no tax present in the coinbase of a 441 // block after height 1. 442 ErrNoTax 443 444 // ErrExpiredTx indicates that the transaction is currently expired. 445 ErrExpiredTx 446 447 // ErrExpiryTxSpentEarly indicates that an output from a transaction 448 // that included an expiry field was spent before coinbase maturity 449 // many blocks had passed in the blockchain. 450 ErrExpiryTxSpentEarly 451 452 // ErrFraudAmountIn indicates the witness amount given was fraudulent. 453 ErrFraudAmountIn 454 455 // ErrFraudBlockHeight indicates the witness block height given was 456 // fraudulent. 457 ErrFraudBlockHeight 458 459 // ErrFraudBlockIndex indicates the witness block index given was 460 // fraudulent. 461 ErrFraudBlockIndex 462 463 // ErrZeroValueOutputSpend indicates that a transaction attempted to spend a 464 // zero value output. 465 ErrZeroValueOutputSpend 466 467 // ErrInvalidEarlyVoteBits indicates that a block before stake validation 468 // height had an unallowed vote bits value. 469 ErrInvalidEarlyVoteBits 470 471 // ErrInvalidEarlyFinalState indicates that a block before stake validation 472 // height had a non-zero final state. 473 ErrInvalidEarlyFinalState 474 475 // ErrKnownInvalidBlock indicates that this block has previously failed 476 // validation. 477 ErrKnownInvalidBlock 478 479 // ErrInvalidAncestorBlock indicates that an ancestor of this block has 480 // failed validation. 481 ErrInvalidAncestorBlock 482 483 // ErrInvalidTemplateParent indicates that a block template builds on a 484 // block that is either not the current best chain tip or its parent. 485 ErrInvalidTemplateParent 486 487 // numErrorCodes is the maximum error code number used in tests. 488 numErrorCodes 489 ) 490 491 // Map of ErrorCode values back to their constant names for pretty printing. 492 var errorCodeStrings = map[ErrorCode]string{ 493 ErrDuplicateBlock: "ErrDuplicateBlock", 494 ErrMissingParent: "ErrMissingParent", 495 ErrBlockTooBig: "ErrBlockTooBig", 496 ErrWrongBlockSize: "ErrWrongBlockSize", 497 ErrBlockVersionTooOld: "ErrBlockVersionTooOld", 498 ErrBadStakeVersion: "ErrBadStakeVersion", 499 ErrInvalidTime: "ErrInvalidTime", 500 ErrTimeTooOld: "ErrTimeTooOld", 501 ErrTimeTooNew: "ErrTimeTooNew", 502 ErrDifficultyTooLow: "ErrDifficultyTooLow", 503 ErrUnexpectedDifficulty: "ErrUnexpectedDifficulty", 504 ErrHighHash: "ErrHighHash", 505 ErrBadMerkleRoot: "ErrBadMerkleRoot", 506 ErrBadCheckpoint: "ErrBadCheckpoint", 507 ErrForkTooOld: "ErrForkTooOld", 508 ErrCheckpointTimeTooOld: "ErrCheckpointTimeTooOld", 509 ErrNoTransactions: "ErrNoTransactions", 510 ErrTooManyTransactions: "ErrTooManyTransactions", 511 ErrNoTxInputs: "ErrNoTxInputs", 512 ErrNoTxOutputs: "ErrNoTxOutputs", 513 ErrTxTooBig: "ErrTxTooBig", 514 ErrBadTxOutValue: "ErrBadTxOutValue", 515 ErrDuplicateTxInputs: "ErrDuplicateTxInputs", 516 ErrBadTxInput: "ErrBadTxInput", 517 ErrMissingTxOut: "ErrMissingTxOut", 518 ErrUnfinalizedTx: "ErrUnfinalizedTx", 519 ErrDuplicateTx: "ErrDuplicateTx", 520 ErrOverwriteTx: "ErrOverwriteTx", 521 ErrImmatureSpend: "ErrImmatureSpend", 522 ErrSpendTooHigh: "ErrSpendTooHigh", 523 ErrBadFees: "ErrBadFees", 524 ErrTooManySigOps: "ErrTooManySigOps", 525 ErrFirstTxNotCoinbase: "ErrFirstTxNotCoinbase", 526 ErrCoinbaseHeight: "ErrCoinbaseHeight", 527 ErrMultipleCoinbases: "ErrMultipleCoinbases", 528 ErrStakeTxInRegularTree: "ErrStakeTxInRegularTree", 529 ErrRegTxInStakeTree: "ErrRegTxInStakeTree", 530 ErrBadCoinbaseScriptLen: "ErrBadCoinbaseScriptLen", 531 ErrBadCoinbaseValue: "ErrBadCoinbaseValue", 532 ErrBadCoinbaseOutpoint: "ErrBadCoinbaseOutpoint", 533 ErrBadCoinbaseFraudProof: "ErrBadCoinbaseFraudProof", 534 ErrBadCoinbaseAmountIn: "ErrBadCoinbaseAmountIn", 535 ErrBadStakebaseAmountIn: "ErrBadStakebaseAmountIn", 536 ErrBadStakebaseScriptLen: "ErrBadStakebaseScriptLen", 537 ErrBadStakebaseScrVal: "ErrBadStakebaseScrVal", 538 ErrScriptMalformed: "ErrScriptMalformed", 539 ErrScriptValidation: "ErrScriptValidation", 540 ErrNotEnoughStake: "ErrNotEnoughStake", 541 ErrStakeBelowMinimum: "ErrStakeBelowMinimum", 542 ErrNonstandardStakeTx: "ErrNonstandardStakeTx", 543 ErrNotEnoughVotes: "ErrNotEnoughVotes", 544 ErrTooManyVotes: "ErrTooManyVotes", 545 ErrFreshStakeMismatch: "ErrFreshStakeMismatch", 546 ErrTooManySStxs: "ErrTooManySStxs", 547 ErrInvalidEarlyStakeTx: "ErrInvalidEarlyStakeTx", 548 ErrTicketUnavailable: "ErrTicketUnavailable", 549 ErrVotesOnWrongBlock: "ErrVotesOnWrongBlock", 550 ErrVotesMismatch: "ErrVotesMismatch", 551 ErrIncongruentVotebit: "ErrIncongruentVotebit", 552 ErrInvalidSSRtx: "ErrInvalidSSRtx", 553 ErrRevocationsMismatch: "ErrRevocationsMismatch", 554 ErrTooManyRevocations: "ErrTooManyRevocations", 555 ErrTicketCommitment: "ErrTicketCommitment", 556 ErrInvalidVoteInput: "ErrInvalidVoteInput", 557 ErrBadNumPayees: "ErrBadNumPayees", 558 ErrBadPayeeScriptVersion: "ErrBadPayeeScriptVersion", 559 ErrBadPayeeScriptType: "ErrBadPayeeScriptType", 560 ErrMismatchedPayeeHash: "ErrMismatchedPayeeHash", 561 ErrBadPayeeValue: "ErrBadPayeeValue", 562 ErrSSGenSubsidy: "ErrSSGenSubsidy", 563 ErrImmatureTicketSpend: "ErrImmatureTicketSpend", 564 ErrTicketInputScript: "ErrTicketInputScript", 565 ErrInvalidRevokeInput: "ErrInvalidRevokeInput", 566 ErrSSRtxPayees: "ErrSSRtxPayees", 567 ErrTxSStxOutSpend: "ErrTxSStxOutSpend", 568 ErrRegTxCreateStakeOut: "ErrRegTxCreateStakeOut", 569 ErrInvalidFinalState: "ErrInvalidFinalState", 570 ErrPoolSize: "ErrPoolSize", 571 ErrForceReorgWrongChain: "ErrForceReorgWrongChain", 572 ErrForceReorgMissingChild: "ErrForceReorgMissingChild", 573 ErrBadStakebaseValue: "ErrBadStakebaseValue", 574 ErrDiscordantTxTree: "ErrDiscordantTxTree", 575 ErrStakeFees: "ErrStakeFees", 576 ErrNoStakeTx: "ErrNoStakeTx", 577 ErrBadBlockHeight: "ErrBadBlockHeight", 578 ErrBlockOneTx: "ErrBlockOneTx", 579 ErrBlockOneInputs: "ErrBlockOneInputs", 580 ErrBlockOneOutputs: "ErrBlockOneOutputs", 581 ErrNoTax: "ErrNoTax", 582 ErrExpiredTx: "ErrExpiredTx", 583 ErrExpiryTxSpentEarly: "ErrExpiryTxSpentEarly", 584 ErrFraudAmountIn: "ErrFraudAmountIn", 585 ErrFraudBlockHeight: "ErrFraudBlockHeight", 586 ErrFraudBlockIndex: "ErrFraudBlockIndex", 587 ErrZeroValueOutputSpend: "ErrZeroValueOutputSpend", 588 ErrInvalidEarlyVoteBits: "ErrInvalidEarlyVoteBits", 589 ErrInvalidEarlyFinalState: "ErrInvalidEarlyFinalState", 590 ErrKnownInvalidBlock: "ErrKnownInvalidBlock", 591 ErrInvalidAncestorBlock: "ErrInvalidAncestorBlock", 592 ErrInvalidTemplateParent: "ErrInvalidTemplateParent", 593 } 594 595 // String returns the ErrorCode as a human-readable name. 596 func (e ErrorCode) String() string { 597 if s := errorCodeStrings[e]; s != "" { 598 return s 599 } 600 return fmt.Sprintf("Unknown ErrorCode (%d)", int(e)) 601 } 602 603 // RuleError identifies a rule violation. It is used to indicate that 604 // processing of a block or transaction failed due to one of the many validation 605 // rules. The caller can use type assertions to determine if a failure was 606 // specifically due to a rule violation and access the ErrorCode field to 607 // ascertain the specific reason for the rule violation. 608 type RuleError struct { 609 ErrorCode ErrorCode // Describes the kind of error 610 Description string // Human readable description of the issue 611 } 612 613 // Error satisfies the error interface and prints human-readable errors. 614 func (e RuleError) Error() string { 615 return e.Description 616 } 617 618 // ruleError creates an RuleError given a set of arguments. 619 func ruleError(c ErrorCode, desc string) RuleError { 620 return RuleError{ErrorCode: c, Description: desc} 621 }