Skip to content
This repository has been archived by the owner on Nov 6, 2021. It is now read-only.

Commit

Permalink
MANTIS-36 reading transactions from any era
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush committed Oct 12, 2021
1 parent 0967228 commit 1cd1212
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 117 deletions.
3 changes: 1 addition & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Main (
) where


import Cardano.Api (AsType(..), ShelleyBasedEra(..))
import Cardano.Api (ShelleyBasedEra(..))
import Paths_mantra (version)

import qualified Mantra.Command as Mantra
Expand All @@ -14,5 +14,4 @@ main :: IO ()
main =
Mantra.main
version
AsAlonzoEra
ShelleyBasedEraAlonzo
17 changes: 8 additions & 9 deletions app/Mantra/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module Mantra.Command (
) where


import Cardano.Api (AsType, IsShelleyBasedEra, ShelleyBasedEra)
import Data.Version (Version, showVersion)
import Cardano.Api (IsShelleyBasedEra, ShelleyBasedEra)
import Data.Version (Version, showVersion)
import Mantra.Command.Types (Mantra(..))
import Mantra.Types (debugMantra, runMantraToIO)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)
import Mantra.Types (debugMantra, runMantraToIO)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)

import qualified Mantra.Command.Bech32 as Bech32
import qualified Mantra.Command.Chain as Chain
Expand All @@ -36,10 +36,9 @@ data Command =

main :: IsShelleyBasedEra era
=> Version
-> AsType era
-> ShelleyBasedEra era
-> IO ()
main version asEra sbe =
main version sbe =
do
let
parser =
Expand Down Expand Up @@ -87,8 +86,8 @@ main version asEra sbe =
Fingerprint{..} -> Fingerprint.main printer policyId assetName
InfoUtxo{..} -> Info.mainUtxo sbe printer configFile addresses
InfoAddress{..} -> Info.mainAddress printer addresses
InfoTxBody{..} -> Info.mainTxBody asEra printer txBodyFiles
InfoTx{..} -> Info.mainTx asEra printer txFiles
InfoTxBody{..} -> Info.mainTxBody printer txBodyFiles
InfoTx{..} -> Info.mainTx printer txFiles
Bech32Decode{..} -> Bech32.mainDecode printer bech32
Bech32Encode{..} -> Bech32.mainEncode printer humanReadablePart dataPart
Chain{..} -> Chain.main printer' configFile outputDirectory continue pointFile
Expand Down
4 changes: 2 additions & 2 deletions app/Mantra/Command/Bech32.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Mantra.Command.Bech32 (


import Control.Monad.IO.Class (MonadIO)
import Mantra.Command.Types (Mantra(Bech32Decode, Bech32Encode))
import Mantra.Types (MantraM, foistMantraEither, foistMantraMaybe, printMantra)
import Mantra.Command.Types (Mantra(Bech32Decode, Bech32Encode))
import Mantra.Types (MantraM, foistMantraEither, foistMantraMaybe, printMantra)

import qualified Codec.Binary.Bech32 as Bech32 (dataPartFromBytes, dataPartToBytes, decodeLenient, encodeLenient, humanReadablePartFromText, humanReadablePartToText)
import qualified Data.ByteString.Base16 as Base16 (decode, encode)
Expand Down
16 changes: 8 additions & 8 deletions app/Mantra/Command/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ module Mantra.Command.Chain (
) where


import Cardano.Api (BlockHeader(..), ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..), PlutusScriptVersion(..), Script(..), ScriptInAnyLang(..), ScriptLanguage(..), serialiseToRawBytesHex, writeFileTextEnvelope)
import Control.Monad (void)
import Control.Monad.Extra (whenJust)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Cardano.Api (BlockHeader(..), ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..), PlutusScriptVersion(..), Script(..), ScriptInAnyLang(..), ScriptLanguage(..), serialiseToRawBytesHex, writeFileTextEnvelope)
import Control.Monad (void)
import Control.Monad.Extra (whenJust)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Aeson.Encode.Pretty (encodePretty)
import Mantra.Chain (extractScripts, loadPoint, savePoint)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Types (MantraM)
import System.FilePath ((</>))
import Mantra.Chain (extractScripts, loadPoint, savePoint)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Types (MantraM)
import System.FilePath ((</>))

import qualified Data.ByteString.Char8 as BS (unpack)
import qualified Data.ByteString.Lazy as LBS (writeFile)
Expand Down
6 changes: 3 additions & 3 deletions app/Mantra/Command/Fingerprint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module Mantra.Command.Fingerprint (


import Control.Monad.IO.Class (MonadIO)
import Mantra.Asset (assetFingerprintString)
import Mantra.Command.Types (Mantra(Fingerprint))
import Mantra.Types (MantraM, printMantra)
import Mantra.Asset (assetFingerprintString)
import Mantra.Command.Types (Mantra(Fingerprint))
import Mantra.Types (MantraM, printMantra)

import qualified Options.Applicative as O
import qualified Data.Text as T (unpack)
Expand Down
66 changes: 39 additions & 27 deletions app/Mantra/Command/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ module Mantra.Command.Info (
) where


import Cardano.Api (AsType(AsTx, AsTxBody), ConsensusModeParams(CardanoModeParams), EpochSlots(..), IsCardanoEra, NetworkId(..), NetworkMagic(..), ShelleyBasedEra, getTxBody, getTxId, readFileTextEnvelope)
import Control.Monad (forM_)
import Cardano.Api (AsType(AsAllegraEra, AsAlonzoEra, AsByronEra, AsMaryEra, AsShelleyEra, AsTx, AsTxBody), ConsensusModeParams(CardanoModeParams), EpochSlots(..), FromSomeType(..), IsCardanoEra, NetworkId(..), NetworkMagic(..), ShelleyBasedEra, getTxBody, getTxId, readFileTextEnvelopeAnyOf)
import Control.Monad (forM_)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Mantra.Command.Types (Configuration(..), Mantra(InfoAddress, InfoTx, InfoTxBody, InfoUtxo))
import Mantra.Query (queryUTxO)
import Mantra.Transaction (printUTxO)
import Mantra.Types (MantraM, foistMantraEitherIO, printMantra)
import Mantra.Wallet (readAddress)
import Mantra.Command.Types (Configuration(..), Mantra(InfoAddress, InfoTx, InfoTxBody, InfoUtxo))
import Mantra.Query (queryUTxO)
import Mantra.Transaction (printUTxO)
import Mantra.Types (MantraM, foistMantraEitherIO, printMantra)
import Mantra.Wallet (readAddress)

import qualified Options.Applicative as O

Expand Down Expand Up @@ -101,39 +101,51 @@ mainAddress _ addresses =
printMantra $ " " ++ show address'


mainTxBody :: IsCardanoEra era
=> MonadIO m
=> AsType era
-> (String -> MantraM m ())
mainTxBody :: MonadIO m
=> (String -> MantraM m ())
-> [FilePath]
-> MantraM m ()
mainTxBody asEra _ txBodyFiles =
mainTxBody _ txBodyFiles =
forM_ txBodyFiles
$ \file ->
do
printMantra ""
printMantra $ "Transaction body file: " ++ file
txBody <-
(txId, txBody) <-
foistMantraEitherIO
$ readFileTextEnvelope (AsTxBody asEra) file
printMantra . show $ getTxId txBody
printMantra $ show txBody


mainTx :: IsCardanoEra era
=> MonadIO m
=> AsType era
-> (String -> MantraM m ())
$ readFileTextEnvelopeAnyOf
[
FromSomeType (AsTxBody AsAlonzoEra ) $ \txBody -> (show $ getTxId txBody, show txBody)
, FromSomeType (AsTxBody AsMaryEra ) $ \txBody -> (show $ getTxId txBody, show txBody)
, FromSomeType (AsTxBody AsAllegraEra) $ \txBody -> (show $ getTxId txBody, show txBody)
, FromSomeType (AsTxBody AsShelleyEra) $ \txBody -> (show $ getTxId txBody, show txBody)
, FromSomeType (AsTxBody AsByronEra ) $ \txBody -> (show $ getTxId txBody, show txBody)
]
file
printMantra txId
printMantra txBody


mainTx :: MonadIO m
=> (String -> MantraM m ())
-> [FilePath]
-> MantraM m ()
mainTx asEra _ txFiles =
mainTx _ txFiles =
forM_ txFiles
$ \file ->
do
printMantra ""
printMantra $ "Transaction file: " ++ file
tx <-
(txId, tx) <-
foistMantraEitherIO
$ readFileTextEnvelope (AsTx asEra) file
printMantra . show . getTxId $ getTxBody tx
printMantra $ show tx
$ readFileTextEnvelopeAnyOf
[
FromSomeType (AsTx AsAlonzoEra ) $ \tx -> (show . getTxId $ getTxBody tx, show tx)
, FromSomeType (AsTx AsMaryEra ) $ \tx -> (show . getTxId $ getTxBody tx, show tx)
, FromSomeType (AsTx AsAllegraEra) $ \tx -> (show . getTxId $ getTxBody tx, show tx)
, FromSomeType (AsTx AsShelleyEra) $ \tx -> (show . getTxId $ getTxBody tx, show tx)
, FromSomeType (AsTx AsByronEra ) $ \tx -> (show . getTxId $ getTxBody tx, show tx)
]
file
printMantra txId
printMantra tx
26 changes: 13 additions & 13 deletions app/Mantra/Command/Mint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ module Mantra.Command.Mint (
) where


import Cardano.Api (ConsensusModeParams(CardanoModeParams), EpochSlots(..), IsShelleyBasedEra, NetworkId(..), NetworkMagic(..), PolicyId(..), ShelleyBasedEra, TxOutDatumHash(..), anyAddressInEra, getTxId, makeTransactionBody, multiAssetSupportedInEra, shelleyBasedToCardanoEra)
import Cardano.Api.Shelley (ShelleyWitnessSigningKey(..), TxOut(..), TxOutValue(..), UTxO(..), makeSignedTransaction, makeShelleyKeyWitness)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Extra (whenJust)
import Data.Aeson (encode)
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Maybe (fromMaybe)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Query (adjustSlot, queryProtocol, queryTip, queryUTxO, submitTransaction)
import Mantra.Script (mintingScript)
import Mantra.Transaction (includeFee, makeTransaction, printUTxO, printValue, readMinting, summarizeValues)
import Mantra.Types (MantraM, SlotRef, foistMantraEither, printMantra)
import Mantra.Wallet (makeVerificationKeyHash, readAddress, readSigningKey, readVerificationKey)
import Cardano.Api (ConsensusModeParams(CardanoModeParams), EpochSlots(..), IsShelleyBasedEra, NetworkId(..), NetworkMagic(..), PolicyId(..), ShelleyBasedEra, TxOutDatumHash(..), anyAddressInEra, getTxId, makeTransactionBody, multiAssetSupportedInEra, shelleyBasedToCardanoEra)
import Cardano.Api.Shelley (ShelleyWitnessSigningKey(..), TxOut(..), TxOutValue(..), UTxO(..), makeSignedTransaction, makeShelleyKeyWitness)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Extra (whenJust)
import Data.Aeson (encode)
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Maybe (fromMaybe)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Query (adjustSlot, queryProtocol, queryTip, queryUTxO, submitTransaction)
import Mantra.Script (mintingScript)
import Mantra.Transaction (includeFee, makeTransaction, printUTxO, printValue, readMinting, summarizeValues)
import Mantra.Types (MantraM, SlotRef, foistMantraEither, printMantra)
import Mantra.Wallet (makeVerificationKeyHash, readAddress, readSigningKey, readVerificationKey)
import Ouroboros.Network.Protocol.LocalTxSubmission.Type (SubmitResult(..))

import qualified Data.ByteString.Lazy.Char8 as LBS (unpack, writeFile)
Expand Down
18 changes: 9 additions & 9 deletions app/Mantra/Command/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ module Mantra.Command.Script (
) where


import Cardano.Api (ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..))
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Extra (whenJust)
import Cardano.Api (ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..))
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Extra (whenJust)
import Data.Aeson.Encode.Pretty (encodePretty)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Query (adjustSlot, queryTip)
import Mantra.Script (mintingScript)
import Mantra.Types (MantraM, SlotRef)
import Mantra.Wallet (makeVerificationKeyHash, readVerificationKey)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Query (adjustSlot, queryTip)
import Mantra.Script (mintingScript)
import Mantra.Types (MantraM, SlotRef)
import Mantra.Wallet (makeVerificationKeyHash, readVerificationKey)

import qualified Data.ByteString.Lazy as LBS (writeFile)
import qualified Data.ByteString.Lazy as LBS (writeFile)
import qualified Options.Applicative as O


Expand Down
24 changes: 12 additions & 12 deletions app/Mantra/Command/Transact.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ module Mantra.Command.Transact (
) where


import Cardano.Api (ConsensusModeParams(CardanoModeParams), EpochSlots(..), IsShelleyBasedEra, NetworkId(..), NetworkMagic(..), ShelleyBasedEra, TxOutDatumHash(..), anyAddressInEra, getTxId, makeTransactionBody, multiAssetSupportedInEra, shelleyBasedToCardanoEra)
import Cardano.Api.Shelley (ShelleyWitnessSigningKey(..), TxOut(..), TxOutValue(..), UTxO(..), makeSignedTransaction, makeShelleyKeyWitness)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Extra (whenJust)
import Data.Aeson (encode)
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Maybe (fromMaybe)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Query (adjustSlot, queryProtocol, queryTip, queryUTxO, submitTransaction)
import Mantra.Transaction (includeFee, makeMinting, makeTransaction, printUTxO, printValue, readMetadata, summarizeValues)
import Mantra.Types (MantraM, SlotRef, foistMantraEither, printMantra)
import Mantra.Wallet (makeVerificationKeyHash, readAddress, readSigningKey, readVerificationKey)
import Cardano.Api (ConsensusModeParams(CardanoModeParams), EpochSlots(..), IsShelleyBasedEra, NetworkId(..), NetworkMagic(..), ShelleyBasedEra, TxOutDatumHash(..), anyAddressInEra, getTxId, makeTransactionBody, multiAssetSupportedInEra, shelleyBasedToCardanoEra)
import Cardano.Api.Shelley (ShelleyWitnessSigningKey(..), TxOut(..), TxOutValue(..), UTxO(..), makeSignedTransaction, makeShelleyKeyWitness)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Extra (whenJust)
import Data.Aeson (encode)
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Maybe (fromMaybe)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Query (adjustSlot, queryProtocol, queryTip, queryUTxO, submitTransaction)
import Mantra.Transaction (includeFee, makeMinting, makeTransaction, printUTxO, printValue, readMetadata, summarizeValues)
import Mantra.Types (MantraM, SlotRef, foistMantraEither, printMantra)
import Mantra.Wallet (makeVerificationKeyHash, readAddress, readSigningKey, readVerificationKey)
import Ouroboros.Network.Protocol.LocalTxSubmission.Type (SubmitResult(..))

import qualified Data.ByteString.Lazy.Char8 as LBS (unpack, writeFile)
Expand Down
2 changes: 1 addition & 1 deletion app/Mantra/Command/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Mantra.Command.Types (
) where


import Data.Word (Word32, Word64)
import Data.Word (Word32, Word64)
import Mantra.Types (SlotRef(..))


Expand Down
14 changes: 7 additions & 7 deletions app/Mantra/Command/Watch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ module Mantra.Command.Watch (
) where


import Cardano.Api (AssetId(..), AsType(AsAssetName, AsPolicyId), BlockHeader(..), BlockNo(..), ChainPoint(..), ChainTip(..), ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..), SlotNo(..), TxOut(..), TxOutValue(..), deserialiseFromRawBytes, deserialiseFromRawBytesHex, selectAsset, valueToList)
import Control.Monad (when)
import Cardano.Api (AssetId(..), AsType(AsAssetName, AsPolicyId), BlockHeader(..), BlockNo(..), ChainPoint(..), ChainTip(..), ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..), SlotNo(..), TxOut(..), TxOutValue(..), deserialiseFromRawBytes, deserialiseFromRawBytesHex, selectAsset, valueToList)
import Control.Monad (when)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Mantra.Chain (Reverter, loadPoint, savePoint, watchTransactions)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Types (MantraM, foistMantraMaybe)
import Mantra.Transaction (printValueIO)
import Mantra.Wallet (readAddress, showAddressInEra)
import Mantra.Chain (Reverter, loadPoint, savePoint, watchTransactions)
import Mantra.Command.Types (Configuration(..), Mantra(..))
import Mantra.Types (MantraM, foistMantraMaybe)
import Mantra.Transaction (printValueIO)
import Mantra.Wallet (readAddress, showAddressInEra)

import qualified Data.ByteString.Char8 as BS (pack)
import qualified Options.Applicative as O
Expand Down
2 changes: 1 addition & 1 deletion mantra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: >= 1.10

name : mantra
description : This tool provides several script-oriented utilities for the Cardano blockchain. In particular, it posts metadata or mints/burns tokens. It can also generate scripts, compute script addresses, compute the fingerprint of a token, and download scripts.
version : 0.5.1.1
version : 0.5.1.2
license : MIT
license-file : LICENSE
author : Brian W Bush
Expand Down
12 changes: 6 additions & 6 deletions src/Mantra/Asset.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ module Mantra.Asset (
) where


import Cardano.Api (AssetId(..), AssetName(..), PolicyId(..), serialiseToRawBytes)
import Codec.Binary.Bech32 (HumanReadablePart, dataPartFromBytes, encodeLenient, humanReadablePartFromText)
import Crypto.Hash (hash)
import Cardano.Api (AssetId(..), AssetName(..), PolicyId(..), serialiseToRawBytes)
import Codec.Binary.Bech32 (HumanReadablePart, dataPartFromBytes, encodeLenient, humanReadablePartFromText)
import Crypto.Hash (hash)
import Crypto.Hash.Algorithms (Blake2b_160)
import Data.ByteArray (convert)
import Data.Text (Text)
import Mantra.Types (MantraM, foistMantraEither, throwMantra)
import Data.ByteArray (convert)
import Data.Text (Text)
import Mantra.Types (MantraM, foistMantraEither, throwMantra)

import qualified Data.ByteString.Char8 as BS (ByteString, pack)
import qualified Data.ByteString.Base16 as Base16 (decode)
Expand Down
8 changes: 4 additions & 4 deletions src/Mantra/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ module Mantra.Query (
) where


import Cardano.Api (AddressAny, CardanoMode, ChainTip(..), ConsensusMode(CardanoMode), ConsensusModeParams, IsCardanoEra(..), IsShelleyBasedEra(..), LocalNodeConnectInfo(..), NetworkId, QueryInEra(QueryInShelleyBasedEra), QueryInMode(..), ShelleyBasedEra, SlotNo(..), Tx, TxInMode(..), TxValidationErrorInMode, getLocalChainTip, queryNodeLocalState, shelleyBasedToCardanoEra, submitTxToNodeLocal, toEraInMode)
import Cardano.Api.Shelley (ProtocolParameters, QueryInShelleyBasedEra(..), QueryUTxOFilter(..), UTxO)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Mantra.Types (MantraM, SlotRef(..), foistMantraEither, foistMantraEitherIO)
import Cardano.Api (AddressAny, CardanoMode, ChainTip(..), ConsensusMode(CardanoMode), ConsensusModeParams, IsCardanoEra(..), IsShelleyBasedEra(..), LocalNodeConnectInfo(..), NetworkId, QueryInEra(QueryInShelleyBasedEra), QueryInMode(..), ShelleyBasedEra, SlotNo(..), Tx, TxInMode(..), TxValidationErrorInMode, getLocalChainTip, queryNodeLocalState, shelleyBasedToCardanoEra, submitTxToNodeLocal, toEraInMode)
import Cardano.Api.Shelley (ProtocolParameters, QueryInShelleyBasedEra(..), QueryUTxOFilter(..), UTxO)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Mantra.Types (MantraM, SlotRef(..), foistMantraEither, foistMantraEitherIO)
import Ouroboros.Network.Protocol.LocalTxSubmission.Type (SubmitResult)

import qualified Data.Set as S (singleton)
Expand Down
Loading

0 comments on commit 1cd1212

Please sign in to comment.