@@ -16,7 +16,7 @@ module BotPlutusInterface.CardanoCLI (
1616 queryTip ,
1717) where
1818
19- import BotPlutusInterface.Effects (PABEffect , ShellArgs (.. ), callCommand , printLog , uploadDir )
19+ import BotPlutusInterface.Effects (PABEffect , ShellArgs (.. ), callCommand , uploadDir )
2020import BotPlutusInterface.Files (
2121 DummyPrivKey (FromSKey , FromVKey ),
2222 datumJsonFilePath ,
@@ -26,10 +26,11 @@ import BotPlutusInterface.Files (
2626 txFilePath ,
2727 validatorScriptFilePath ,
2828 )
29- import BotPlutusInterface.Types (LogLevel ( Warn ), PABConfig , Tip )
29+ import BotPlutusInterface.Types (PABConfig , Tip )
3030import BotPlutusInterface.UtxoParser qualified as UtxoParser
3131import Cardano.Api.Shelley (NetworkId (Mainnet , Testnet ), NetworkMagic (.. ), serialiseAddress )
3232import Codec.Serialise qualified as Codec
33+ import Control.Monad (join )
3334import Control.Monad.Freer (Eff , Member )
3435import Data.Aeson qualified as JSON
3536import Data.Aeson.Extras (encodeByteString )
@@ -110,7 +111,7 @@ queryTip ::
110111 forall (w :: Type ) (effs :: [Type -> Type ]).
111112 Member (PABEffect w ) effs =>
112113 PABConfig ->
113- Eff effs Tip
114+ Eff effs ( Either Text Tip )
114115queryTip config =
115116 callCommand @ w
116117 ShellArgs
@@ -125,7 +126,7 @@ utxosAt ::
125126 Member (PABEffect w ) effs =>
126127 PABConfig ->
127128 Address ->
128- Eff effs (Map TxOutRef ChainIndexTxOut )
129+ Eff effs (Either Text ( Map TxOutRef ChainIndexTxOut ) )
129130utxosAt pabConf address =
130131 callCommand @ w
131132 ShellArgs
@@ -151,17 +152,18 @@ calculateMinUtxo ::
151152 TxOut ->
152153 Eff effs (Either Text Integer )
153154calculateMinUtxo pabConf datums txOut =
154- callCommand @ w
155- ShellArgs
156- { cmdName = " cardano-cli"
157- , cmdArgs =
158- mconcat
159- [ [" transaction" , " calculate-min-required-utxo" , " --alonzo-era" ]
160- , txOutOpts pabConf datums [txOut]
161- , [" --protocol-params-file" , pabConf. pcProtocolParamsFile]
162- ]
163- , cmdOutParser = mapLeft Text. pack . parseOnly UtxoParser. feeParser . Text. pack
164- }
155+ join
156+ <$> callCommand @ w
157+ ShellArgs
158+ { cmdName = " cardano-cli"
159+ , cmdArgs =
160+ mconcat
161+ [ [" transaction" , " calculate-min-required-utxo" , " --alonzo-era" ]
162+ , txOutOpts pabConf datums [txOut]
163+ , [" --protocol-params-file" , pabConf. pcProtocolParamsFile]
164+ ]
165+ , cmdOutParser = mapLeft Text. pack . parseOnly UtxoParser. feeParser . Text. pack
166+ }
165167
166168-- | Calculating fee for an unbalanced transaction
167169calculateMinFee ::
@@ -171,21 +173,22 @@ calculateMinFee ::
171173 Tx ->
172174 Eff effs (Either Text Integer )
173175calculateMinFee pabConf tx =
174- callCommand @ w
175- ShellArgs
176- { cmdName = " cardano-cli"
177- , cmdArgs =
178- mconcat
179- [ [" transaction" , " calculate-min-fee" ]
180- , [" --tx-body-file" , txFilePath pabConf " raw" tx]
181- , [" --tx-in-count" , showText $ length $ txInputs tx]
182- , [" --tx-out-count" , showText $ length $ txOutputs tx]
183- , [" --witness-count" , showText $ length $ txSignatures tx]
184- , [" --protocol-params-file" , pabConf. pcProtocolParamsFile]
185- , networkOpt pabConf
186- ]
187- , cmdOutParser = mapLeft Text. pack . parseOnly UtxoParser. feeParser . Text. pack
188- }
176+ join
177+ <$> callCommand @ w
178+ ShellArgs
179+ { cmdName = " cardano-cli"
180+ , cmdArgs =
181+ mconcat
182+ [ [" transaction" , " calculate-min-fee" ]
183+ , [" --tx-body-file" , txFilePath pabConf " raw" tx]
184+ , [" --tx-in-count" , showText $ length $ txInputs tx]
185+ , [" --tx-out-count" , showText $ length $ txOutputs tx]
186+ , [" --witness-count" , showText $ length $ txSignatures tx]
187+ , [" --protocol-params-file" , pabConf. pcProtocolParamsFile]
188+ , networkOpt pabConf
189+ ]
190+ , cmdOutParser = mapLeft Text. pack . parseOnly UtxoParser. feeParser . Text. pack
191+ }
189192
190193data BuildMode = BuildRaw Integer | BuildAuto
191194 deriving stock (Show )
@@ -203,7 +206,7 @@ buildTx ::
203206 PubKeyHash ->
204207 BuildMode ->
205208 Tx ->
206- Eff effs ()
209+ Eff effs (Either Text () )
207210buildTx pabConf privKeys ownPkh buildMode tx =
208211 callCommand @ w $ ShellArgs " cardano-cli" opts (const () )
209212 where
@@ -248,25 +251,11 @@ signTx ::
248251 forall (w :: Type ) (effs :: [Type -> Type ]).
249252 Member (PABEffect w ) effs =>
250253 PABConfig ->
251- Map PubKeyHash DummyPrivKey ->
252254 Tx ->
253255 [PubKey ] ->
254256 Eff effs (Either Text () )
255- signTx pabConf privKeys tx pubKeys =
256- let skeys = Map. filter (\ case FromSKey _ -> True ; FromVKey _ -> False ) privKeys
257- in if all ((`Map.member` skeys) . Ledger. pubKeyHash) pubKeys
258- then callCommand @ w $ ShellArgs " cardano-cli" opts (const (Right () ))
259- else do
260- let err =
261- Text. unlines
262- [ " Not all required signatures have signing key files. Please sign and submit the tx manually:"
263- , " Tx file: " <> txFilePath pabConf " raw" tx
264- , " Signatories (pkh): "
265- <> Text. unwords
266- (map (encodeByteString . fromBuiltin . getPubKeyHash . Ledger. pubKeyHash) pubKeys)
267- ]
268- printLog @ w Warn (Text. unpack err)
269- pure $ Left err
257+ signTx pabConf tx pubKeys =
258+ callCommand @ w $ ShellArgs " cardano-cli" opts (const () )
270259 where
271260 signingKeyFiles =
272261 concatMap
@@ -287,7 +276,7 @@ submitTx ::
287276 Member (PABEffect w ) effs =>
288277 PABConfig ->
289278 Tx ->
290- Eff effs (Maybe Text )
279+ Eff effs (Either Text () )
291280submitTx pabConf tx =
292281 callCommand @ w $
293282 ShellArgs
@@ -298,13 +287,7 @@ submitTx pabConf tx =
298287 , networkOpt pabConf
299288 ]
300289 )
301- ( ( \ out ->
302- if " Transaction successfully submitted." `Text.isPrefixOf` out
303- then Nothing
304- else Just out
305- )
306- . Text. pack
307- )
290+ (const () )
308291
309292txInOpts :: PABConfig -> BuildMode -> Set TxIn -> [Text ]
310293txInOpts pabConf buildMode =
0 commit comments