Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datums and scripts to friendlyTxImpl #977

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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: 07cfd58f4ffabc96391bba53d2f464b859be0a6a
--sha256: sha256-3Hdp3g/F1py8Lnev2Dk+eMBukPmmjsz1bnupkuYMgjA=

program-options
ghc-options: -Werror

Expand Down
36 changes: 31 additions & 5 deletions cardano-cli/src/Cardano/CLI/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ import Data.Maybe
import Data.Ratio (numerator)
import qualified Data.Text as T
import qualified Data.Text as Text
import qualified Data.Vector as Vector
import Data.Yaml (array)
import Data.Yaml.Pretty (setConfCompare)
import qualified Data.Yaml.Pretty as Yaml
import GHC.Exts (IsList (..))
import GHC.Real (denominator)
import GHC.Unicode (isAlphaNum)
import Lens.Micro ((^.))
import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.Vector as Vector

data FriendlyFormat = FriendlyJson | FriendlyYaml

Expand Down Expand Up @@ -249,7 +250,7 @@ friendlyTxBodyImpl
]
++ ( monoidForEraInEon @AlonzoEraOnwards
era
(`getRedeemerDetails` tb)
(`getAlonzoSpecificDetails` tb)
)
++ ( monoidForEraInEon @ConwayEraOnwards
era
Expand Down Expand Up @@ -304,11 +305,14 @@ data EraIndependentPlutusScriptPurpose
| Voting
| Proposing

getRedeemerDetails
getAlonzoSpecificDetails
:: forall era. AlonzoEraOnwards era -> TxBody era -> [Aeson.Pair]
getRedeemerDetails aeo tb =
getAlonzoSpecificDetails aeo tb =
palas marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -385,6 +389,28 @@ 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" .= Api.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" .= Api.friendlyDatum dat
]
| (datHash, dat) <- Map.toList dats
]

friendlyTotalCollateral :: TxTotalCollateral era -> Aeson.Value
friendlyTotalCollateral TxTotalCollateralNone = Aeson.Null
friendlyTotalCollateral (TxTotalCollateral _ coll) = toJSON coll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ auxiliary scripts: null
certificates: null
collateral inputs:
- c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256
datums: []
era: Alonzo
fee: 213 Lovelace
inputs:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ auxiliary scripts: null
certificates: null
collateral inputs:
- c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256
datums: []
era: Alonzo
fee: 213 Lovelace
inputs:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
auxiliary scripts: null
certificates: null
collateral inputs: []
datums: []
era: Babbage
fee: 21300 Lovelace
inputs:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
auxiliary scripts: null
certificates: null
collateral inputs: []
datums: []
era: Babbage
fee: 21300 Lovelace
inputs:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ auxiliary scripts: null
certificates: null
collateral inputs:
- c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256
datums:
palas marked this conversation as resolved.
Show resolved Hide resolved
- datum: I 6666
datum hash: 9e478573ab81ea7a8e31891ce0648b81229f408d596a3483e6f4f9b92d3cf710
era: Babbage
fee: 213 Lovelace
inputs:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"certificates": null,
"collateral inputs": [],
"currentTreasuryValue": null,
"datums": [],
"era": "Conway",
"fee": "181517 Lovelace",
"governance actions": [
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"certificates": null,
"collateral inputs": [],
"currentTreasuryValue": null,
"datums": [],
"era": "Conway",
"fee": "185433 Lovelace",
"governance actions": [],
Expand Down Expand Up @@ -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,
Expand Down
Loading