From 098c17d201a980eaa9fc942d581eb7b5310a46da Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Tue, 1 Nov 2022 13:21:54 -0400 Subject: [PATCH] Remove Cardano.Api.TxSubmit.ErrorRender/Types as it was not being used --- cardano-api/cardano-api.cabal | 2 - .../src/Cardano/Api/TxSubmit/ErrorRender.hs | 67 ------------------- cardano-api/src/Cardano/Api/TxSubmit/Types.hs | 65 ------------------ 3 files changed, 134 deletions(-) delete mode 100644 cardano-api/src/Cardano/Api/TxSubmit/ErrorRender.hs delete mode 100644 cardano-api/src/Cardano/Api/TxSubmit/Types.hs diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index 3a8478b4848..c2ad3c833c0 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -97,8 +97,6 @@ library Cardano.Api.TxBody Cardano.Api.TxIn Cardano.Api.TxMetadata - Cardano.Api.TxSubmit.ErrorRender - Cardano.Api.TxSubmit.Types Cardano.Api.Utils Cardano.Api.Value Cardano.Api.ValueParser diff --git a/cardano-api/src/Cardano/Api/TxSubmit/ErrorRender.hs b/cardano-api/src/Cardano/Api/TxSubmit/ErrorRender.hs deleted file mode 100644 index 1afbfd92013..00000000000 --- a/cardano-api/src/Cardano/Api/TxSubmit/ErrorRender.hs +++ /dev/null @@ -1,67 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module Cardano.Api.TxSubmit.ErrorRender - ( renderApplyMempoolPayloadErr - ) where - --- This file contains error renders. They should have been defined at a lower level, with the error --- type definitions, but for some reason have not been. --- They will be defined here for now and then moved where they are supposed to be once they --- are working. - -import Cardano.Api.Utils (textShow) - -import Cardano.Chain.Byron.API (ApplyMempoolPayloadErr (..)) -import Cardano.Chain.UTxO.UTxO (UTxOError (..)) -import Cardano.Chain.UTxO.Validation (TxValidationError (..), UTxOValidationError (..)) - -import Cardano.Prelude hiding ((%)) - -import Formatting (build, sformat, stext, (%)) - -renderApplyMempoolPayloadErr :: ApplyMempoolPayloadErr -> Text -renderApplyMempoolPayloadErr err = - case err of - MempoolTxErr ve -> renderValidationError ve - MempoolDlgErr {} -> "Delegation error" - MempoolUpdateProposalErr {} -> "Update proposal error" - MempoolUpdateVoteErr {} -> "Update vote error" - - -renderValidationError :: UTxOValidationError -> Text -renderValidationError ve = - case ve of - UTxOValidationTxValidationError tve -> renderTxValidationError tve - UTxOValidationUTxOError ue -> renderUTxOError ue - - -renderTxValidationError :: TxValidationError -> Text -renderTxValidationError tve = - "Tx Validation: " <> - case tve of - TxValidationLovelaceError txt e -> - sformat ("Lovelace error " % stext % ": " % build) txt e - TxValidationFeeTooSmall tx expected actual -> - sformat ("Tx " % build % " fee " % build % "too low, expected " % build) tx actual expected - TxValidationWitnessWrongSignature wit pmid sig -> - sformat ("Bad witness " % build % " for signature " % stext % " protocol magic id " % stext) wit (textShow sig) (textShow pmid) - TxValidationWitnessWrongKey wit addr -> - sformat ("Bad witness " % build % " for address " % build) wit addr - TxValidationMissingInput tx -> - sformat ("Validation cannot find input tx " % build) tx - -- Fields are - TxValidationNetworkMagicMismatch expected actual -> - mconcat [ "Bad network magic ", textShow actual, ", expected ", textShow expected ] - TxValidationTxTooLarge expected actual -> - mconcat [ "Tx is ", textShow actual, " bytes, but expected < ", textShow expected, " bytes" ] - TxValidationUnknownAddressAttributes -> - "Unknown address attributes" - TxValidationUnknownAttributes -> - "Unknown attributes" - -renderUTxOError :: UTxOError -> Text -renderUTxOError ue = - "UTxOError: " <> - case ue of - UTxOMissingInput tx -> sformat ("Lookup of tx " % build % " failed") tx - UTxOOverlappingUnion -> "Union or two overlapping UTxO sets" - diff --git a/cardano-api/src/Cardano/Api/TxSubmit/Types.hs b/cardano-api/src/Cardano/Api/TxSubmit/Types.hs deleted file mode 100644 index 821ad85fa66..00000000000 --- a/cardano-api/src/Cardano/Api/TxSubmit/Types.hs +++ /dev/null @@ -1,65 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module Cardano.Api.TxSubmit.Types - ( NodeApiEnv (..) - , SocketPath (..) - , TxSubmitStatus (..) - , ApplyMempoolPayloadErr(..) - , renderTxSubmitStatus - ) where - -import Cardano.Binary (DecoderError) -import Cardano.Chain.Byron.API (ApplyMempoolPayloadErr (..)) -import qualified Cardano.Chain.Genesis as Genesis -import qualified Cardano.Chain.UTxO as Utxo - -import Cardano.Prelude hiding ((%)) - -import Data.Aeson (ToJSON (..), Value (..)) -import qualified Data.Aeson as Aeson - -import Formatting (build, sformat, (%)) - -import Cardano.Api.Environment -import Cardano.Api.TxSubmit.ErrorRender - -data NodeApiEnv = NodeApiEnv - { naeConfig :: Genesis.Config - , naeSocket :: SocketPath - } - - -data TxSubmitStatus - = TxSubmitOk Utxo.TxId - | TxSubmitDecodeHex - | TxSubmitEmpty - | TxSubmitDecodeFail DecoderError - | TxSubmitBadTx Text - | TxSubmitFail ApplyMempoolPayloadErr - deriving Eq - -instance ToJSON TxSubmitStatus where - toJSON = convertJson - -convertJson :: TxSubmitStatus -> Value -convertJson st = - Aeson.object - [ ( "status", String statusMsg ) - , ( "message", String (renderTxSubmitStatus st) ) - ] - where - statusMsg :: Text - statusMsg = - case st of - TxSubmitOk{} -> "success" - _other -> "fail" - -renderTxSubmitStatus :: TxSubmitStatus -> Text -renderTxSubmitStatus st = - case st of - TxSubmitOk tx -> sformat ("Tx " % build % " submitted successfully") tx - TxSubmitDecodeHex -> "Provided data was hex encoded and this webapi expects raw binary" - TxSubmitEmpty -> "Provided transaction has zero length" - TxSubmitDecodeFail err -> sformat build err - TxSubmitBadTx tt -> mconcat ["Transactions of type '", tt, "' not supported"] - TxSubmitFail err -> renderApplyMempoolPayloadErr err -