Skip to content

Commit 9ac0dbd

Browse files
committed
Add asType. Generalise address parser for any address
1 parent 204c8c8 commit 9ac0dbd

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ instance IsShelleyBasedEra era => FromJSON (AddressInEra era) where
386386
addressAny <- runParsecParser parseAddressAny txt
387387
pure $ anyAddressInShelleyBasedEra sbe addressAny
388388

389-
parseAddressAny :: Parsec.Parser AddressAny
389+
parseAddressAny :: SerialiseAddress addr => Parsec.Parser addr
390390
parseAddressAny = do
391391
str <- lexPlausibleAddressString
392-
case deserialiseAddress AsAddressAny str of
392+
case deserialiseAddress asType str of
393393
Nothing -> fail $ "invalid address: " <> Text.unpack str
394394
Just addr -> pure addr
395395

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Cardano.Api.Internal.HasTypeProxy
66
( HasTypeProxy (AsType, proxyToAsType)
7+
, asType
78
, Proxy (..)
89
, FromSomeType (..)
910
)
@@ -24,3 +25,7 @@ class Typeable t => HasTypeProxy t where
2425

2526
data FromSomeType (c :: Type -> Constraint) b where
2627
FromSomeType :: c a => AsType a -> (a -> b) -> FromSomeType c b
28+
29+
-- | Provide type proxy from the already existing 'HasTypeProxy' instance
30+
asType :: HasTypeProxy t => AsType t
31+
asType = proxyToAsType Proxy

cardano-api/src/Cardano/Api/Internal/Keys/Read.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ readKeyFile
3232
-> NonEmpty (InputFormat a)
3333
-> FilePath
3434
-> IO (Either (FileError InputDecodeError) a)
35-
readKeyFile asType acceptedFormats path = do
35+
readKeyFile asType' acceptedFormats path = do
3636
eContent <- runExceptT $ fileIOExceptT path readFileBlocking
3737
case eContent of
3838
Left e -> return $ Left e
3939
Right content ->
40-
return . first (FileError path) $ deserialiseInput asType acceptedFormats content
40+
return . first (FileError path) $ deserialiseInput asType' acceptedFormats content
4141

4242
-- | Read a cryptographic key from a file.
4343
--
@@ -47,7 +47,7 @@ readKeyFileTextEnvelope
4747
=> AsType a
4848
-> File content In
4949
-> IO (Either (FileError InputDecodeError) a)
50-
readKeyFileTextEnvelope asType fp =
50+
readKeyFileTextEnvelope _ fp =
5151
first (fmap InputTextEnvelopeError) <$> readFileTextEnvelope asType fp
5252

5353
-- | Read a cryptographic key from a file given that it is one of the provided

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ instance HasTypeProxy lang => HasTypeProxy (PlutusScript lang) where
10391039
-- do any additional transformation on Plutus script bytes.
10401040
instance HasTypeProxy lang => SerialiseAsRawBytes (PlutusScript lang) where
10411041
serialiseToRawBytes = serialiseToCBOR
1042-
deserialiseFromRawBytes asType bs =
1042+
deserialiseFromRawBytes _ bs =
10431043
first (SerialiseAsRawBytesError . show . B.sformat B.build) $
10441044
deserialiseFromCBOR asType bs
10451045

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ deserialiseWitnessLedgerCddl sbe te =
177177
mapLeft textEnvelopeErrorToTextEnvelopeCddlError $
178178
deserialiseFromTextEnvelope asType te
179179
where
180-
asType :: AsType (KeyWitness era)
181-
asType = shelleyBasedEraConstraints sbe $ proxyToAsType Proxy
182-
183-
-- \| This wrapper ensures that we can still decode the key witness
180+
-- This wrapper ensures that we can still decode the key witness
184181
-- that were serialized before we migrated to using 'serialiseToTextEnvelope'
185182
legacyDecoding
186183
:: TextEnvelope

0 commit comments

Comments
 (0)