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

Commit 8ce91dc

Browse files
committed
Merged in dev (pull request #13)
Dev
2 parents 2a2ffaf + 6a9d937 commit 8ce91dc

37 files changed

+2452
-1825
lines changed

ReadMe.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ The configuration file contains the basic network information, along with the fu
8787
Available commands:
8888
bech32-decode Decode a Bech32 string.
8989
bech32-encode Encode a Bech32 string.
90-
chain-scripts Download scripts used as transaction witnesses.
9190
fingerprint Compute the Bech32 fingerprint of a token.
9291
info-address Print information about addresses.
9392
info-tx Print contents of transaction files.
@@ -98,6 +97,7 @@ The configuration file contains the basic network information, along with the fu
9897
transact Submit Cardano metadata or mint Cardano tokens.
9998
watch-address Watch transactions at an address.
10099
watch-coin Watch transactions for a coin.
100+
watch-scripts Download scripts used as transaction witnesses.
101101

102102
* [Mint batches of Cardano non-fungible tokens](man/mint.md)
103103
* `mantis mint`
@@ -106,7 +106,7 @@ The configuration file contains the basic network information, along with the fu
106106
* [Construct a minting script and compute its Policy ID](man/script.md)
107107
* `mantis script`
108108
* [Download information from all blocks and transactions](man/watch.md)
109-
* `mantis chain-scripts`
109+
* `mantis watch-scripts`
110110
* `mantis watch-address`
111111
* `mantis watch-coin`
112112
* [Encoding and decoding Bech32 text](man/bech32.md)

app/Mantis/Command.hs

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Mantis.Command (
77
) where
88

99

10+
import Cardano.Api (AsType(AsAlonzoEra), ShelleyBasedEra(ShelleyBasedEraAlonzo))
1011
import Data.Version (Version, showVersion)
1112
import Mantis.Command.Types (Mantis(..))
1213
import Mantis.Types (debugMantis, runMantisToIO)
@@ -47,13 +48,14 @@ main version =
4748
<$> verboseOption
4849
<*> O.hsubparser (
4950
Bech32.command
50-
<> Chain.command
51+
<> Chain.command'
5152
<> Fingerprint.command
5253
<> Info.command
5354
<> Mint.command
5455
<> Script.command
5556
<> Transact.command
5657
<> Watch.command
58+
<> Chain.command
5759
)
5860
)
5961
)
@@ -73,16 +75,18 @@ main version =
7375
let
7476
printer = if quiet then const $ return () else debugMantis
7577
printer' = if quiet then const $ return () else hPutStrLn stderr
78+
sbe = ShelleyBasedEraAlonzo
79+
asEra = AsAlonzoEra
7680
result <- runMantisToIO
7781
$ case mantis of
78-
Transact{..} -> Transact.main printer configFile tokenName tokenCount tokenSlot outputAddress scriptFile metadataFile
79-
Mint{..} -> Mint.main printer configFile mintingFile tokenSlot outputAddress scriptFile metadataFile
82+
Transact{..} -> Transact.main sbe printer configFile tokenName tokenCount tokenSlot outputAddress scriptFile metadataFile
83+
Mint{..} -> Mint.main sbe printer configFile mintingFile tokenSlot outputAddress scriptFile metadataFile
8084
Script{..} -> Script.main printer configFile tokenSlot scriptFile
81-
Fingerprint{..} -> Fingerprint.main printer policyId assetName
82-
InfoUtxo{..} -> Info.mainUtxo printer configFile addresses
85+
Fingerprint{..} -> Fingerprint.main printer policyId assetName
86+
InfoUtxo{..} -> Info.mainUtxo sbe printer configFile addresses
8387
InfoAddress{..} -> Info.mainAddress printer addresses
84-
InfoTxBody{..} -> Info.mainTxBody printer txBodyFiles
85-
InfoTx{..} -> Info.mainTx printer txFiles
88+
InfoTxBody{..} -> Info.mainTxBody asEra printer txBodyFiles
89+
InfoTx{..} -> Info.mainTx asEra printer txFiles
8690
Bech32Decode{..} -> Bech32.mainDecode printer bech32
8791
Bech32Encode{..} -> Bech32.mainEncode printer humanReadablePart dataPart
8892
Chain{..} -> Chain.main printer' configFile outputDirectory continue

app/Mantis/Command/Chain.hs

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
module Mantis.Command.Chain (
66
command
7+
, command'
78
, main
89
) where
910

1011

11-
import Cardano.Api (BlockHeader(..), ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..), getTxBody, getTxId, serialiseToRawBytesHex)
12+
import Cardano.Api (BlockHeader(..), ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..), serialiseToRawBytesHex)
1213
import Control.Monad.Extra (whenJust)
1314
import Control.Monad.IO.Class (MonadIO, liftIO)
1415
import Data.Aeson.Encode.Pretty (encodePretty)
@@ -24,10 +25,16 @@ import qualified Options.Applicative as O
2425

2526
command :: O.Mod O.CommandFields Mantis
2627
command =
27-
O.command "chain-scripts"
28+
O.command "watch-scripts"
2829
$ O.info options (O.progDesc "Download scripts used as transaction witnesses.")
2930

3031

32+
command' :: O.Mod O.CommandFields Mantis
33+
command' =
34+
O.command "chain-scripts"
35+
$ O.info options (O.progDesc "[Renamed to 'watch-scripts'.]")
36+
37+
3138
options :: O.Parser Mantis
3239
options =
3340
Chain
@@ -54,13 +61,13 @@ main debugIO configFile output continue =
5461
liftIO . debugIO $ "Network: " ++ show network
5562

5663
extractScripts socketPath protocol network (return $ not continue)
57-
$ \(BlockHeader slotNo _ _) tx hash script ->
64+
$ \(BlockHeader slotNo _ _) txId hash script ->
5865
do
5966
let
6067
hash' = BS.unpack $ serialiseToRawBytesHex hash
6168
debugIO ""
6269
debugIO $ show slotNo
63-
debugIO . show . getTxId $ getTxBody tx
70+
debugIO $ show txId
6471
debugIO $ "Hash " ++ hash'
6572
debugIO $ show script
6673
whenJust output

app/Mantis/Command/Info.hs

+19-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Mantis.Command.Info (
1111
) where
1212

1313

14-
import Cardano.Api (AsType(AsTx, AsTxBody, AsMaryEra), ConsensusModeParams(CardanoModeParams), EpochSlots(..), NetworkId(..), NetworkMagic(..), getTxBody, getTxId, readFileTextEnvelope)
14+
import Cardano.Api (AsType(AsTx, AsTxBody), ConsensusModeParams(CardanoModeParams), EpochSlots(..), IsCardanoEra, NetworkId(..), NetworkMagic(..), ShelleyBasedEra, getTxBody, getTxId, readFileTextEnvelope)
1515
import Control.Monad (forM_)
1616
import Control.Monad.IO.Class (MonadIO, liftIO)
1717
import Mantis.Command.Types (Configuration(..), Mantis(InfoAddress, InfoTx, InfoTxBody, InfoUtxo))
@@ -55,13 +55,15 @@ command =
5555
]
5656

5757

58-
mainUtxo :: MonadFail m
58+
mainUtxo :: IsCardanoEra era
59+
=> MonadFail m
5960
=> MonadIO m
60-
=> (String -> MantisM m ())
61+
=> ShelleyBasedEra era
62+
-> (String -> MantisM m ())
6163
-> FilePath
6264
-> [String]
6365
-> MantisM m ()
64-
mainUtxo debugMantis configFile addresses =
66+
mainUtxo sbe debugMantis configFile addresses =
6567
do
6668
Configuration{..} <- liftIO $ read <$> readFile configFile
6769

@@ -80,7 +82,7 @@ mainUtxo debugMantis configFile addresses =
8082
debugMantis $ " " ++ show address
8183
debugMantis $ " " ++ show address'
8284
printMantis "Unspent UTxO:"
83-
utxo <- queryUTxO socketPath protocol address' network
85+
utxo <- queryUTxO sbe socketPath protocol address' network
8486
printUTxO " " utxo
8587

8688

@@ -99,35 +101,39 @@ mainAddress _ addresses =
99101
printMantis $ " " ++ show address'
100102

101103

102-
mainTxBody :: MonadIO m
103-
=> (String -> MantisM m ())
104+
mainTxBody :: IsCardanoEra era
105+
=> MonadIO m
106+
=> AsType era
107+
-> (String -> MantisM m ())
104108
-> [FilePath]
105109
-> MantisM m ()
106-
mainTxBody _ txBodyFiles =
110+
mainTxBody asEra _ txBodyFiles =
107111
forM_ txBodyFiles
108112
$ \file ->
109113
do
110114
printMantis ""
111115
printMantis $ "Transaction body file: " ++ file
112116
txBody <-
113117
foistMantisEitherIO
114-
$ readFileTextEnvelope (AsTxBody AsMaryEra) file
118+
$ readFileTextEnvelope (AsTxBody asEra) file
115119
printMantis . show $ getTxId txBody
116120
printMantis $ show txBody
117121

118122

119-
mainTx :: MonadIO m
120-
=> (String -> MantisM m ())
123+
mainTx :: IsCardanoEra era
124+
=> MonadIO m
125+
=> AsType era
126+
-> (String -> MantisM m ())
121127
-> [FilePath]
122128
-> MantisM m ()
123-
mainTx _ txFiles =
129+
mainTx asEra _ txFiles =
124130
forM_ txFiles
125131
$ \file ->
126132
do
127133
printMantis ""
128134
printMantis $ "Transaction file: " ++ file
129135
tx <-
130136
foistMantisEitherIO
131-
$ readFileTextEnvelope (AsTx AsMaryEra) file
137+
$ readFileTextEnvelope (AsTx asEra) file
132138
printMantis . show . getTxId $ getTxBody tx
133139
printMantis $ show tx

app/Mantis/Command/Mint.hs

+19-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module Mantis.Command.Mint (
88
) where
99

1010

11-
import Cardano.Api (ConsensusModeParams(CardanoModeParams), CardanoEra(MaryEra), EpochSlots(..), NetworkId(..), NetworkMagic(..), PolicyId(..), anyAddressInEra, getTxId, makeTransactionBody)
12-
import Cardano.Api.Shelley (ShelleyWitnessSigningKey(..), TxOut(..), TxOutValue(..), UTxO(..), makeScriptWitness, makeSignedTransaction, makeShelleyKeyWitness)
11+
import Cardano.Api (ConsensusModeParams(CardanoModeParams), EpochSlots(..), IsShelleyBasedEra, NetworkId(..), NetworkMagic(..), PolicyId(..), ShelleyBasedEra, TxOutDatumHash(..), anyAddressInEra, getTxId, makeTransactionBody, multiAssetSupportedInEra, shelleyBasedToCardanoEra)
12+
import Cardano.Api.Shelley (ShelleyWitnessSigningKey(..), TxOut(..), TxOutValue(..), UTxO(..), makeSignedTransaction, makeShelleyKeyWitness)
1313
import Control.Monad.IO.Class (MonadIO, liftIO)
1414
import Control.Monad.Extra (whenJust)
1515
import Data.Aeson (encode)
@@ -18,7 +18,7 @@ import Data.Maybe (fromMaybe)
1818
import Mantis.Command.Types (Configuration(..), Mantis(..))
1919
import Mantis.Query (adjustSlot, queryProtocol, queryTip, queryUTxO, submitTransaction)
2020
import Mantis.Script (mintingScript)
21-
import Mantis.Transaction (includeFee, makeTransaction, printUTxO, printValue, readMinting, summarizeValues, supportedMultiAsset)
21+
import Mantis.Transaction (includeFee, makeTransaction, printUTxO, printValue, readMinting, summarizeValues)
2222
import Mantis.Types (MantisM, SlotRef, foistMantisEither, printMantis)
2323
import Mantis.Wallet (makeVerificationKeyHash, readAddress, readSigningKey, readVerificationKey)
2424
import Ouroboros.Network.Protocol.LocalTxSubmission.Type (SubmitResult(..))
@@ -45,21 +45,24 @@ options =
4545
<*> O.optional (O.strOption $ O.long "metadata" <> O.metavar "METADATA_FILE" <> O.help "Path to output metadata JSON file." )
4646

4747

48-
main :: MonadFail m
48+
main :: IsShelleyBasedEra era
49+
=> MonadFail m
4950
=> MonadIO m
50-
=> (String -> MantisM m ())
51+
=> ShelleyBasedEra era
52+
-> (String -> MantisM m ())
5153
-> FilePath
5254
-> FilePath
5355
-> Maybe SlotRef
5456
-> Maybe String
5557
-> Maybe FilePath
5658
-> Maybe FilePath
5759
-> MantisM m ()
58-
main debugMantis configFile mintingFile tokenSlot outputAddress scriptFile metadataFile =
60+
main sbe debugMantis configFile mintingFile tokenSlot outputAddress scriptFile metadataFile =
5961
do
6062
Configuration{..} <- liftIO $ read <$> readFile configFile
6163

6264
let
65+
era = shelleyBasedToCardanoEra sbe
6366
protocol = CardanoModeParams $ EpochSlots epochSlots
6467
network = maybe Mainnet (Testnet . NetworkMagic) magic
6568
debugMantis ""
@@ -71,7 +74,7 @@ main debugMantis configFile mintingFile tokenSlot outputAddress scriptFile metad
7174
let
7275
before = (`adjustSlot` tip) <$> tokenSlot
7376

74-
pparams <- queryProtocol socketPath protocol network
77+
pparams <- queryProtocol sbe socketPath protocol network
7578
debugMantis ""
7679
debugMantis $ "Protocol parameters: " ++ LBS.unpack (encode pparams)
7780

@@ -91,7 +94,7 @@ main debugMantis configFile mintingFile tokenSlot outputAddress scriptFile metad
9194

9295
debugMantis ""
9396
debugMantis "Unspect UTxO:"
94-
utxo@(UTxO utxo') <- queryUTxO socketPath protocol address network
97+
utxo@(UTxO utxo') <- queryUTxO sbe socketPath protocol address network
9598
printUTxO " " utxo
9699

97100
let
@@ -121,25 +124,24 @@ main debugMantis configFile mintingFile tokenSlot outputAddress scriptFile metad
121124
debugMantis $ "Minting: " ++ show minting
122125

123126
let
124-
Just address'' = anyAddressInEra MaryEra address'
127+
Just address'' = anyAddressInEra era address'
128+
Right supportedMultiAsset = multiAssetSupportedInEra era
125129
txBody <- includeFee network pparams nIn 1 1 0
126-
$ makeTransaction
130+
$ makeTransaction
127131
(M.keys utxo')
128-
[TxOut address'' (TxOutValue supportedMultiAsset value')]
132+
[TxOut address'' (TxOutValue supportedMultiAsset value') TxOutDatumHashNone]
129133
before
130134
(Just metadata)
131-
Nothing
132-
(Just minting)
135+
(Just (PolicyId scriptHash, script, minting))
133136
txRaw <- foistMantisEither $ makeTransactionBody txBody
134137
debugMantis ""
135138
debugMantis $ "Transaction: " ++ show txRaw
136139

137140
let
138141
witness = makeShelleyKeyWitness txRaw
139-
$ WitnessPaymentExtendedKey signingKey
140-
witness' = makeScriptWitness script
141-
txSigned = makeSignedTransaction [witness, witness'] txRaw
142-
result <- submitTransaction socketPath protocol network txSigned
142+
$ either WitnessPaymentKey WitnessPaymentExtendedKey signingKey
143+
txSigned = makeSignedTransaction [witness] txRaw
144+
result <- submitTransaction sbe socketPath protocol network txSigned
143145
printMantis ""
144146
case result of
145147
SubmitSuccess -> printMantis $ "Success: " ++ show (getTxId txRaw)

0 commit comments

Comments
 (0)