1
{-# LANGUAGE NamedFieldPuns #-}
2
{-# LANGUAGE OverloadedStrings #-}
4
module Cardano.TxSubmit.ErrorRender
5
( renderApplyMempoolPayloadErr
9
-- This file contains error renders. They should have been defined at a lower level, with the error
10
-- type definitions, but for some reason have not been.
11
-- They will be defined here for now and then moved where they are supposed to be once they
14
import Cardano.Chain.Byron.API (ApplyMempoolPayloadErr (..))
15
import Cardano.Chain.UTxO.UTxO (UTxOError (..))
16
import Cardano.Chain.UTxO.Validation (TxValidationError (..), UTxOValidationError (..))
17
import Data.Function ((.))
18
import Data.Monoid (Monoid (mconcat), (<>))
19
import Data.Text (Text)
20
import Formatting (build, sformat, stext, (%))
21
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))
22
import Text.Show (Show (show))
24
import qualified Data.Text as T
26
renderApplyMempoolPayloadErr :: ApplyMempoolPayloadErr -> Text
27
renderApplyMempoolPayloadErr err =
29
MempoolTxErr ve -> renderValidationError ve
30
MempoolDlgErr {} -> "Delegation error"
31
MempoolUpdateProposalErr {} -> "Update proposal error"
32
MempoolUpdateVoteErr {} -> "Update vote error"
34
renderValidationError :: UTxOValidationError -> Text
35
renderValidationError ve =
37
UTxOValidationTxValidationError tve -> renderTxValidationError tve
38
UTxOValidationUTxOError ue -> renderUTxOError ue
40
renderTxValidationError :: TxValidationError -> Text
41
renderTxValidationError tve =
44
TxValidationLovelaceError txt e ->
45
sformat ("Lovelace error "% stext %": "% build) txt e
46
TxValidationFeeTooSmall tx expected actual ->
47
sformat ("Tx "% build %" fee "% build %"too low, expected "% build) tx actual expected
48
TxValidationWitnessWrongSignature wit pmid sig ->
49
sformat ("Bad witness "% build %" for signature "% stext %" protocol magic id "% stext) wit (textShow sig) (textShow pmid)
50
TxValidationWitnessWrongKey wit addr ->
51
sformat ("Bad witness "% build %" for address "% build) wit addr
52
TxValidationMissingInput tx ->
53
sformat ("Validation cannot find input tx "% build) tx
54
-- Fields are <expected> <actual>
55
TxValidationNetworkMagicMismatch expected actual ->
56
mconcat [ "Bad network magic ", textShow actual, ", expected ", textShow expected ]
57
TxValidationTxTooLarge expected actual ->
58
mconcat [ "Tx is ", textShow actual, " bytes, but expected < ", textShow expected, " bytes" ]
59
TxValidationUnknownAddressAttributes ->
60
"Unknown address attributes"
61
TxValidationUnknownAttributes ->
64
renderUTxOError :: UTxOError -> Text
68
UTxOMissingInput tx -> sformat ("Lookup of tx "% build %" failed") tx
69
UTxOOverlappingUnion -> "Union or two overlapping UTxO sets"
71
renderEraMismatch :: EraMismatch -> Text
72
renderEraMismatch EraMismatch{ledgerEraName, otherEraName} =
73
"The era of the node and the tx do not match. " <>
74
"The node is running in the " <> ledgerEraName <>
75
" era, but the transaction is for the " <> otherEraName <> " era."
77
textShow :: Show a => a -> Text
78
textShow = T.pack . show