Skip to content

Commit ee5af3f

Browse files
authored
Merge pull request #906 from IntersectMBO/mgalazyn/feature/add-utxorpc-protocol-parameters-query-pp-reverse
cardano-rpc | UTxO RPC: add reverse conversion from UTxO RPC protocol params, to ledger ones
2 parents 2729847 + 88632e6 commit ee5af3f

File tree

15 files changed

+495
-128
lines changed

15 files changed

+495
-128
lines changed

cardano-api/src/Cardano/Api/Address.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ where
9292
import Cardano.Api.Byron.Internal.Key
9393
import Cardano.Api.Era
9494
import Cardano.Api.HasTypeProxy
95-
import Cardano.Api.Internal.Utils
9695
import Cardano.Api.Key.Internal
96+
import Cardano.Api.Monad.Error
9797
import Cardano.Api.Network.Internal.NetworkId
9898
import Cardano.Api.Parser.Text qualified as P
9999
import Cardano.Api.Plutus.Internal.Script

cardano-api/src/Cardano/Api/Experimental/Era.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Cardano.Api.Experimental.Era
2121
, IsEra (..)
2222
, Some (..)
2323
, Inject (..)
24+
, Convert (..)
2425
, LedgerEra
2526
, DeprecatedEra (..)
2627
, EraCommonConstraints

cardano-api/src/Cardano/Api/Internal/Utils.hs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,13 @@
55

66
-- | Internal utils for the other Api modules
77
module Cardano.Api.Internal.Utils
8-
( (?!)
9-
, (?!.)
10-
, (<<$>>)
8+
( (<<$>>)
119
, (<<<$>>>)
1210
, noInlineMaybeToStrictMaybe
1311
)
1412
where
1513

1614
import Cardano.Ledger.BaseTypes
17-
import Cardano.Ledger.Shelley ()
18-
19-
(?!) :: Maybe a -> e -> Either e a
20-
Nothing ?! e = Left e
21-
Just x ?! _ = Right x
22-
23-
(?!.) :: Either e a -> (e -> e') -> Either e' a
24-
Left e ?!. f = Left (f e)
25-
Right x ?!. _ = Right x
2615

2716
infixl 4 <<$>>
2817

cardano-api/src/Cardano/Api/Monad/Error.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module Cardano.Api.Monad.Error
1515
, liftMaybe
1616
, failEither
1717
, failEitherWith
18+
, (?!)
19+
, (?!&)
1820
, module Control.Monad.Except
1921
, module Control.Monad.IO.Class
2022
, module Control.Monad.Trans.Class
@@ -118,6 +120,18 @@ liftMaybe
118120
-> m a
119121
liftMaybe e = maybe (throwError e) pure
120122

123+
-- | Infix 'liftMaybe', with arguments flipped
124+
(?!) :: MonadError e m => Maybe a -> e -> m a
125+
(?!) = flip liftMaybe
126+
127+
infixl 8 ?!
128+
129+
-- | Map over the 'Left' value of 'Either e a'. Infix 'first' with its arguments flipped.
130+
(?!&) :: Either e a -> (e -> e') -> Either e' a
131+
(?!&) = flip first
132+
133+
infixl 8 ?!&
134+
121135
-- | Lift 'Either' to `MonadFail`
122136
failEither
123137
:: MonadFail m

cardano-api/src/Cardano/Api/Serialise/Bech32.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ where
1818
import Cardano.Api.Error
1919
import Cardano.Api.HasTypeProxy
2020
import Cardano.Api.Internal.Orphans.Misc ()
21-
import Cardano.Api.Internal.Utils
21+
import Cardano.Api.Monad.Error
2222
import Cardano.Api.Pretty
2323
import Cardano.Api.Serialise.Raw
2424

@@ -52,7 +52,7 @@ deserialiseFromBech32
5252
deserialiseFromBech32 bech32Str = do
5353
(prefix, dataPart) <-
5454
Bech32.decodeLenient bech32Str
55-
?!. Bech32DecodingError
55+
?!& Bech32DecodingError
5656

5757
let actualPrefix = Bech32.humanReadablePartToText prefix
5858
permittedPrefixes = bech32PrefixesPermitted (asType @a)
@@ -83,7 +83,7 @@ deserialiseAnyOfFromBech32
8383
deserialiseAnyOfFromBech32 types bech32Str = do
8484
(prefix, dataPart) <-
8585
Bech32.decodeLenient bech32Str
86-
?!. Bech32DecodingError
86+
?!& Bech32DecodingError
8787

8888
let actualPrefix = Bech32.humanReadablePartToText prefix
8989

cardano-api/src/Cardano/Api/Serialise/Cip129.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020
import Cardano.Api.Governance.Internal.Action.ProposalProcedure
2121
import Cardano.Api.HasTypeProxy
2222
import Cardano.Api.Internal.Orphans (AsType (..))
23-
import Cardano.Api.Internal.Utils
23+
import Cardano.Api.Monad.Error
2424
import Cardano.Api.Serialise.Bech32
2525
import Cardano.Api.Serialise.Raw
2626
import Cardano.Api.Tx.Internal.TxIn
@@ -98,7 +98,7 @@ deserialiseFromBech32Cip129
9898
deserialiseFromBech32Cip129 bech32Str = do
9999
(prefix, dataPart) <-
100100
Bech32.decodeLenient bech32Str
101-
?!. Bech32DecodingError
101+
?!& Bech32DecodingError
102102

103103
let actualPrefix = Bech32.humanReadablePartToText prefix
104104
permittedPrefixes = cip129Bech32PrefixesPermitted (asType @a)
@@ -160,7 +160,7 @@ deserialiseGovActionIdFromBech32Cip129 bech32Str = do
160160
let permittedPrefixes = ["gov_action"]
161161
(prefix, dataPart) <-
162162
Bech32.decodeLenient bech32Str
163-
?!. Bech32DecodingError
163+
?!& Bech32DecodingError
164164
let actualPrefix = Bech32.humanReadablePartToText prefix
165165
guard (actualPrefix `elem` permittedPrefixes)
166166
?! Bech32UnexpectedPrefix actualPrefix (fromList permittedPrefixes)

cardano-api/src/Cardano/Api/Tx/Internal/Body.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ import Cardano.Api.Experimental.Plutus.Internal.Shim.LegacyScripts
248248
import Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements
249249
import Cardano.Api.Governance.Internal.Action.ProposalProcedure
250250
import Cardano.Api.Governance.Internal.Action.VotingProcedure
251-
import Cardano.Api.Internal.Utils
252251
import Cardano.Api.Key.Internal
253252
import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
253+
import Cardano.Api.Monad.Error
254254
import Cardano.Api.Network.Internal.NetworkId
255255
import Cardano.Api.Plutus.Internal.Script
256256
import Cardano.Api.Plutus.Internal.ScriptData

cardano-api/src/Cardano/Api/Tx/Internal/Output.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ import Cardano.Api.Era.Internal.Eon.Convert
6363
import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
6464
import Cardano.Api.Error (Error (..), displayError)
6565
import Cardano.Api.Hash
66-
import Cardano.Api.Internal.Utils
6766
import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
67+
import Cardano.Api.Monad.Error
6868
import Cardano.Api.Parser.Text qualified as P
6969
import Cardano.Api.Plutus.Internal.Script
7070
import Cardano.Api.Plutus.Internal.ScriptData

cardano-rpc/cardano-rpc.cabal

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ library
6161
Cardano.Rpc.Server.Internal.Error
6262
Cardano.Rpc.Server.Internal.Monad
6363
Cardano.Rpc.Server.Internal.UtxoRpc.Query
64+
Cardano.Rpc.Server.Internal.UtxoRpc.Type
6465
Proto.Cardano.Rpc.Node
6566
Proto.Cardano.Rpc.Node_Fields
6667
Proto.Utxorpc.V1alpha.Cardano.Cardano
@@ -91,6 +92,7 @@ library
9192
cardano-ledger-core,
9293
containers,
9394
contra-tracer,
95+
data-default,
9496
filepath,
9597
generic-data,
9698
grapesy,
@@ -100,3 +102,30 @@ library
100102
proto-lens-runtime,
101103
rio,
102104
text,
105+
106+
test-suite cardano-rpc-test
107+
import: project-config
108+
hs-source-dirs: test/cardano-rpc-test
109+
main-is: cardano-rpc-test.hs
110+
type: exitcode-stdio-1.0
111+
build-depends:
112+
cardano-api,
113+
cardano-api:gen,
114+
cardano-ledger-api,
115+
cardano-ledger-conway,
116+
cardano-ledger-core,
117+
cardano-rpc,
118+
containers,
119+
hedgehog >=1.1,
120+
rio,
121+
tasty,
122+
tasty-hedgehog,
123+
124+
ghc-options:
125+
-threaded
126+
-rtsopts
127+
"-with-rtsopts=-N -T"
128+
129+
build-tool-depends: tasty-discover:tasty-discover
130+
other-modules:
131+
Test.Cardano.Rpc.ProtocolParameters

cardano-rpc/proto/utxorpc/v1alpha/cardano/cardano.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ message Script {
4444
}
4545

4646
// Represents a rational number as a fraction.
47+
// TODO u5c increased precision to 64 bits
4748
message RationalNumber {
48-
int32 numerator = 1;
49-
uint32 denominator = 2;
49+
int64 numerator = 1;
50+
uint64 denominator = 2;
5051
}
5152

5253
// PARAMS

0 commit comments

Comments
 (0)