diff --git a/cabal.project b/cabal.project index 1864d105fa..a13062d665 100644 --- a/cabal.project +++ b/cabal.project @@ -19,6 +19,13 @@ index-state: packages: cardano-cli +source-repository-package + type: git + location: https://github.com/IntersectMBO/cardano-api + subdir: cardano-api + tag: 72a82e2806465d3ba07b6f23f5b7d21686c59669 + --sha256: sha256-Win07OoMIDbcvHXagZ8kpyNdarJ8sAfRIljVWuXKYOg= + program-options ghc-options: -Werror diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index 8c95c4bf3f..79ee28246e 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -43,6 +43,7 @@ where import Cardano.Api as Api import Cardano.Api.Byron (KeyWitness (ByronKeyWitness)) import Cardano.Api.Ledger (ExUnits (..), extractHash, strictMaybeToMaybe) +import qualified Cardano.Api.Ledger as Alonzo import qualified Cardano.Api.Ledger as L import qualified Cardano.Api.Ledger as Ledger import Cardano.Api.Shelley (Hash (..), @@ -60,6 +61,7 @@ import Data.Aeson (Value (..), object, toJSON, (.=)) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Encode.Pretty as Aeson import qualified Data.Aeson.Key as Aeson +import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.Aeson.Types as Aeson import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BSC @@ -249,7 +251,7 @@ friendlyTxBodyImpl ] ++ ( monoidForEraInEon @AlonzoEraOnwards era - (`getRedeemerDetails` tb) + (`getScriptWitnessDetails` tb) ) ++ ( monoidForEraInEon @ConwayEraOnwards era @@ -304,11 +306,14 @@ data EraIndependentPlutusScriptPurpose | Voting | Proposing -getRedeemerDetails +getScriptWitnessDetails :: forall era. AlonzoEraOnwards era -> TxBody era -> [Aeson.Pair] -getRedeemerDetails aeo tb = +getScriptWitnessDetails aeo tb = let ShelleyTx _ ledgerTx = makeSignedTransaction [] tb - in ["redeemers" .= friendlyRedeemers ledgerTx] + in [ "redeemers" .= friendlyRedeemers ledgerTx + , "scripts" .= friendlyScriptData ledgerTx + , "datums" .= friendlyDats ledgerTx + ] where friendlyRedeemers :: Ledger.Tx (ShelleyLedgerEra era) @@ -385,6 +390,64 @@ getRedeemerDetails aeo tb = addLabelToPurpose Voting vp = Aeson.object ["voting using script protected voter credentials" .= vp] addLabelToPurpose Proposing pp = Aeson.object ["submitting a proposal following proposal policy" .= pp] + friendlyScriptData :: Ledger.Tx (ShelleyLedgerEra era) -> Aeson.Value + friendlyScriptData tx = + alonzoEraOnwardsConstraints aeo $ do + Aeson.Array $ + Vector.fromList $ + [ Aeson.Object $ + KeyMap.fromList + [ "script hash" .= scriptHash + , "script data" .= friendlyScript scriptData + ] + | (scriptHash, scriptData) <- Map.toList $ tx ^. Ledger.witsTxL . Ledger.scriptTxWitsL + ] + + friendlyDats :: Ledger.Tx (ShelleyLedgerEra era) -> Aeson.Value + friendlyDats tx = + alonzoEraOnwardsConstraints aeo $ + let Ledger.TxDats dats = tx ^. Ledger.witsTxL . Ledger.datsTxWitsL + in Aeson.Array $ + Vector.fromList $ + [ Aeson.Object $ + KeyMap.fromList + [ "datum hash" .= datHash + , "datum" .= friendlyDatum dat + ] + | (datHash, dat) <- Map.toList dats + ] + +-- | Create a friendly JSON out of a script +friendlyScript + :: AlonzoEraOnwardsConstraints era => Ledger.Script (ShelleyLedgerEra era) -> Aeson.Value +friendlyScript script = Aeson.Object $ + KeyMap.fromList $ + case Ledger.getNativeScript script of + Just nativeScript -> + [ ("type", "native") + , ("script", Aeson.String $ T.pack $ Ledger.showTimelock nativeScript) + ] + Nothing -> + ( case Ledger.toPlutusScript script of + Just plutusScript -> + Ledger.withPlutusScript plutusScript $ + friendlyPlutusScript $ + Ledger.plutusScriptLanguage plutusScript + Nothing -> [("error", Aeson.String "Unsupported script type")] + ) + where + friendlyPlutusScript :: Ledger.Language -> Ledger.Plutus l -> [(KeyMap.Key, Aeson.Value)] + friendlyPlutusScript language plutusScript = + [ ("type", "plutus") + , ("plutus version", Aeson.String $ Ledger.languageToText language) + , ("script", Aeson.String $ Ledger.serializeAsHexText $ Ledger.plutusBinary plutusScript) + ] + +-- | Create a friendly JSON out of a datum +friendlyDatum + :: AlonzoEraOnwardsConstraints era => Alonzo.Data (ShelleyLedgerEra era) -> Aeson.Value +friendlyDatum (Alonzo.Data datum) = Aeson.String (T.pack $ show datum) + friendlyTotalCollateral :: TxTotalCollateral era -> Aeson.Value friendlyTotalCollateral TxTotalCollateralNone = Aeson.Null friendlyTotalCollateral (TxTotalCollateral _ coll) = toJSON coll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/signed-transaction-view.out b/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/signed-transaction-view.out index 62a6d1fd59..e6f1a37059 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/signed-transaction-view.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/signed-transaction-view.out @@ -2,6 +2,7 @@ auxiliary scripts: null certificates: null collateral inputs: - c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256 +datums: [] era: Alonzo fee: 213 Lovelace inputs: @@ -15,6 +16,7 @@ required signers (payment key hashes needed for scripts): - 98717eaba8105a50a2a71831267552e337dfdc893bef5e40b8676d27 - fafaaac8681b5050a8987f95bce4a7f99362f189879258fdbf733fa4 return collateral: null +scripts: [] total collateral: null update proposal: null validity range: diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/transaction-view.out b/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/transaction-view.out index 1ef8d0560f..8c812c11fc 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/transaction-view.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/alonzo/transaction-view.out @@ -2,6 +2,7 @@ auxiliary scripts: null certificates: null collateral inputs: - c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256 +datums: [] era: Alonzo fee: 213 Lovelace inputs: @@ -15,6 +16,7 @@ required signers (payment key hashes needed for scripts): - 98717eaba8105a50a2a71831267552e337dfdc893bef5e40b8676d27 - fafaaac8681b5050a8987f95bce4a7f99362f189879258fdbf733fa4 return collateral: null +scripts: [] total collateral: null update proposal: epoch: 190 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-detailedschema.out b/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-detailedschema.out index 427cf0a5bb..be78001b74 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-detailedschema.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-detailedschema.out @@ -1,6 +1,7 @@ auxiliary scripts: null certificates: null collateral inputs: [] +datums: [] era: Babbage fee: 21300 Lovelace inputs: @@ -33,6 +34,7 @@ redeemers: [] reference inputs: [] required signers (payment key hashes needed for scripts): null return collateral: null +scripts: [] total collateral: null update proposal: null validity range: diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-noschema.out b/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-noschema.out index 63cb905c45..cf8e9d0264 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-noschema.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-metadata-noschema.out @@ -1,6 +1,7 @@ auxiliary scripts: null certificates: null collateral inputs: [] +datums: [] era: Babbage fee: 21300 Lovelace inputs: @@ -66,6 +67,7 @@ redeemers: [] reference inputs: [] required signers (payment key hashes needed for scripts): null return collateral: null +scripts: [] total collateral: null update proposal: null validity range: diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-redeemer.out b/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-redeemer.out index 7242ec0211..90b60cb81b 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-redeemer.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-redeemer.out @@ -2,6 +2,9 @@ auxiliary scripts: null certificates: null collateral inputs: - c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256 +datums: +- datum: I 6666 + datum hash: 9e478573ab81ea7a8e31891ce0648b81229f408d596a3483e6f4f9b92d3cf710 era: Babbage fee: 213 Lovelace inputs: @@ -20,6 +23,12 @@ redeemers: reference inputs: [] required signers (payment key hashes needed for scripts): null return collateral: null +scripts: +- script data: + plutus version: PlutusV1 + script: 4e4d01000033222220051200120011 + type: plutus + script hash: 67f33146617a5e61936081db3b2117cbf59bd2123748f58ac9678656 total collateral: null update proposal: null validity range: diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-proposal.out.json b/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-proposal.out.json index b8e34d66ee..b5655243b9 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-proposal.out.json +++ b/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-proposal.out.json @@ -3,6 +3,7 @@ "certificates": null, "collateral inputs": [], "currentTreasuryValue": null, + "datums": [], "era": "Conway", "fee": "181517 Lovelace", "governance actions": [ @@ -54,6 +55,7 @@ "reference inputs": [], "required signers (payment key hashes needed for scripts)": null, "return collateral": null, + "scripts": [], "total collateral": null, "treasuryDonation": 0, "update proposal": null, diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-three-votes-view.out.json b/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-three-votes-view.out.json index f2c5bb9920..72c1f0ac7d 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-three-votes-view.out.json +++ b/cardano-cli/test/cardano-cli-golden/files/golden/conway/tx-three-votes-view.out.json @@ -3,6 +3,7 @@ "certificates": null, "collateral inputs": [], "currentTreasuryValue": null, + "datums": [], "era": "Conway", "fee": "185433 Lovelace", "governance actions": [], @@ -30,6 +31,7 @@ "reference inputs": [], "required signers (payment key hashes needed for scripts)": null, "return collateral": null, + "scripts": [], "total collateral": null, "treasuryDonation": 0, "update proposal": null,