Skip to content

Commit

Permalink
fixes and adding missing bits to swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jul 9, 2024
1 parent 6e48fdf commit 189df67
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@ fromMetadataEncrypted apiEncrypt metadata =
k == cip83EncryptMethodKey && v == cip83EncryptPayloadValue
presentPair _ = False
in case value of
Cardano.TxMetaMap list -> null $ filter presentPair list
Cardano.TxMetaMap list -> not (any presentPair list)
_ -> True
getEncryptedPayload value =
let presentPair (Cardano.TxMetaText k, Cardano.TxMetaList _) =
Expand All @@ -3328,11 +3328,11 @@ fromMetadataEncrypted apiEncrypt metadata =
when (checkPresenceOfMethod validValue) $
Left ErrDecodeTxMissingEncryptionMethod
let payloads = getEncryptedPayload validValue
if length payloads == 0 then
if null payloads then
Left ErrDecodeTxMissingValidEncryptionPayload
else do
let extracted = extractPayload <$> payloads
when (any (==T.empty) extracted) $
when (elem T.empty extracted) $
Left ErrDecodeTxMissingValidEncryptionPayload
Right extracted

Expand Down
20 changes: 10 additions & 10 deletions lib/api/src/Cardano/Wallet/Api/Types/SchemaMetadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import Cardano.Wallet.Primitive.Types.Tx
import Control.Applicative
( (<|>)
)
import Control.DeepSeq
( NFData
)
import Control.Monad
( guard
, when
)
import Control.DeepSeq
( NFData
)
import Data.Aeson
( FromJSON (parseJSON)
, ToJSON (toJSON)
Expand Down Expand Up @@ -71,8 +71,8 @@ import qualified Data.Aeson.Key as Aeson
import qualified Data.Aeson.KeyMap as Aeson
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as BS16
import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Base16 as B16
import qualified Data.ByteString.Char8 as B8
import qualified Data.List as L
import qualified Data.Scientific as Scientific
import qualified Data.Text as T
Expand Down Expand Up @@ -161,8 +161,8 @@ metadataValueFromJsonNoSchema = conv
conv (Aeson.String s)
| Just s' <- T.stripPrefix bytesPrefix s
, let bs' = T.encodeUtf8 s'
, Right bs <- BS16.decode bs'
, not (BS8.any (\c -> c >= 'A' && c <= 'F') bs')
, Right bs <- B16.decode bs'
, not (B8.any (\c -> c >= 'A' && c <= 'F') bs')
= Right (TxMetaBytes bs)

conv (Aeson.String s) = Right (TxMetaText s)
Expand Down Expand Up @@ -200,7 +200,7 @@ pUnsigned :: Atto.Parser Integer
pUnsigned = do
bs <- Atto.takeWhile1 Atto.isDigit
-- no redundant leading 0s allowed, or we cannot round-trip properly
guard (not (BS.length bs > 1 && BS8.head bs == '0'))
guard (not (BS.length bs > 1 && B8.head bs == '0'))
return $! BS.foldl' step 0 bs
where
step a w = a * 10 + fromIntegral (w - 48)
Expand All @@ -212,8 +212,8 @@ pBytes :: Atto.Parser ByteString
pBytes = do
_ <- Atto.string "0x"
remaining <- Atto.takeByteString
when (BS8.any hexUpper remaining) $ fail ("Unexpected uppercase hex characters in " <> show remaining)
case BS16.decode remaining of
when (B8.any hexUpper remaining) $ fail ("Unexpected uppercase hex characters in " <> show remaining)
case B16.decode remaining of
Right bs -> return bs
_ -> fail ("Expecting base16 encoded string, found: " <> show remaining)
where
Expand Down
20 changes: 20 additions & 0 deletions specifications/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4757,6 +4757,19 @@ x-errInvalidMetadataEncryption: &errInvalidMetadataEncryption
type: string
enum: ['invalid_metadata_encryption']

x-errInvalidMetadataDecryption: &errInvalidMetadataDecryption
<<: *responsesErr
title: invalid_metadata_decryption
properties:
message:
type: string
description: |
The supplied encrypted metadata object is not compatible with standard
specified by CIP-83 (https://cips.cardano.org/cip/CIP-83).
code:
type: string
enum: ['invalid_metadata_decryption']

x-errInputsDepleted: &errInputsDepleted
<<: *responsesErr
title: inputs_depleted
Expand Down Expand Up @@ -6232,6 +6245,13 @@ x-responsesDecodedTransaction: &responsesDecodedTransaction
<<: *responsesErr404WalletNotInitialized
<<: *responsesErr406
<<: *responsesErr415UnsupportedMediaType
403:
description: Forbidden
content:
application/json:
schema:
oneOf:
- <<: *errInvalidMetadataDecryption
202:
description: Accepted
content:
Expand Down

0 comments on commit 189df67

Please sign in to comment.