@@ -23,26 +23,33 @@ import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT
23
23
24
24
import Data.Aeson.Encode.Pretty (encodePretty )
25
25
import qualified Data.ByteString.Lazy.Char8 as LBS
26
+ import qualified Data.Map as Map
26
27
import qualified Data.Set as Set
28
+ import qualified Data.Text as Text
29
+ import qualified Data.Text.IO as Text
27
30
28
31
import Ouroboros.Consensus.Cardano (Protocol (.. ), protocolInfo )
29
32
import Ouroboros.Consensus.Config (configCodec )
30
33
import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (.. ))
31
34
import Ouroboros.Consensus.Node.Run (nodeNetworkMagic )
35
+ import Ouroboros.Consensus.Shelley.Protocol.Crypto (TPraosStandardCrypto )
32
36
import Ouroboros.Network.NodeToClient (withIOManager )
33
37
34
38
import Ouroboros.Network.Block (getTipPoint )
35
39
40
+ import Shelley.Spec.Ledger.Coin (Coin (.. ))
36
41
import Shelley.Spec.Ledger.PParams (PParams )
42
+ import Shelley.Spec.Ledger.TxData (TxId (.. ), TxIn (.. ), TxOut (.. ))
43
+ import Shelley.Spec.Ledger.UTxO (UTxO (.. ))
37
44
38
45
39
46
runQueryCmd :: QueryCmd -> ExceptT CliError IO ()
40
47
runQueryCmd cmd =
41
48
case cmd of
42
49
QueryProtocolParameters configFp outFile ->
43
50
runQueryProtocolParameters configFp outFile
44
- QueryFilteredUTxO addr configFp outFile ->
45
- runQueryFilteredUTxO addr configFp outFile
51
+ QueryFilteredUTxO addr configFp ->
52
+ runQueryFilteredUTxO addr configFp
46
53
_ -> liftIO $ putStrLn $ " runQueryCmd: " ++ show cmd
47
54
48
55
runQueryProtocolParameters
@@ -70,9 +77,8 @@ runQueryProtocolParameters configFp (OutputFile outFile) = do
70
77
runQueryFilteredUTxO
71
78
:: Address
72
79
-> ConfigYamlFilePath
73
- -> OutputFile
74
80
-> ExceptT CliError IO ()
75
- runQueryFilteredUTxO addr configFp ( OutputFile _outFile) = do
81
+ runQueryFilteredUTxO addr configFp = do
76
82
nc <- liftIO $ parseNodeConfigurationFP configFp
77
83
SomeConsensusProtocol p <- firstExceptT ProtocolError $ mkConsensusProtocol nc Nothing
78
84
@@ -83,7 +89,7 @@ runQueryFilteredUTxO addr configFp (OutputFile _outFile) = do
83
89
filteredUtxo <- firstExceptT NodeLocalStateQueryError $
84
90
queryFilteredUTxOFromLocalState cfg nm sockPath
85
91
(Set. singleton addr) (getTipPoint tip)
86
- liftIO $ putStrLn $ " Filtered UTxO: " ++ show filteredUtxo
92
+ liftIO $ printFilteredUTxOs filteredUtxo
87
93
where
88
94
cfg = configCodec ptclcfg
89
95
-- FIXME: this works, but we should get the magic properly:
@@ -95,3 +101,29 @@ runQueryFilteredUTxO addr configFp (OutputFile _outFile) = do
95
101
writeProtocolParameters :: FilePath -> PParams -> ExceptT CliError IO ()
96
102
writeProtocolParameters fpath pparams =
97
103
handleIOExceptT (IOError fpath) $ LBS. writeFile fpath (encodePretty pparams)
104
+
105
+
106
+ printFilteredUTxOs :: UTxO TPraosStandardCrypto -> IO ()
107
+ printFilteredUTxOs (UTxO utxo) = do
108
+ Text. putStrLn title
109
+ putStrLn $ replicate (Text. length title + 2 ) ' -'
110
+ mapM_ printUtxo $ Map. toList utxo
111
+ where
112
+ title :: Text
113
+ title =
114
+ " TxHash TxId Lovelace"
115
+
116
+ printUtxo :: (TxIn TPraosStandardCrypto , TxOut TPraosStandardCrypto ) -> IO ()
117
+ printUtxo (TxIn (TxId txhash) txin , TxOut _ (Coin coin)) =
118
+ Text. putStrLn $
119
+ mconcat
120
+ [ Text. pack (show txhash)
121
+ , textShowN 6 txin
122
+ , textShowN 18 coin -- enough to display maxLovelaceVal
123
+ ]
124
+
125
+ textShowN :: Show a => Int -> a -> Text
126
+ textShowN len x =
127
+ let str = show x
128
+ slen = length str
129
+ in Text. pack $ replicate (max 1 (len - slen)) ' ' ++ str
0 commit comments