Skip to content

Commit

Permalink
fixing schema/json things
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Oct 28, 2021
1 parent c15ccab commit 03ce121
Show file tree
Hide file tree
Showing 9 changed files with 14,250 additions and 13,424 deletions.
30 changes: 26 additions & 4 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3031,26 +3031,48 @@ instance
, DecodeStakeAddress n
) => FromJSON (ApiTxOutputGeneral n)
where
parseJSON = genericParseJSON defaultRecordTypeOptions
parseJSON obj = do
derPathM <-
(withObject "ApiTxOutputGeneral" $
\o -> o .:? "derivation_path" :: Aeson.Parser (Maybe (NonEmpty (ApiT DerivationIndex)))) obj
case derPathM of
Nothing -> do
xs <- parseJSON obj :: Aeson.Parser (AddressAmount (ApiT Address, Proxy n))
pure $ ExternalOutput xs
Just _ -> do
xs <- parseJSON obj :: Aeson.Parser (ApiWalletOutput n)
pure $ WalletOutput xs
instance
( EncodeAddress n
, EncodeStakeAddress n
) => ToJSON (ApiTxOutputGeneral n)
where
toJSON = genericToJSON defaultRecordTypeOptions
toJSON (ExternalOutput content) = toJSON content
toJSON (WalletOutput content) = toJSON content

instance
( DecodeAddress n
, DecodeStakeAddress n
) => FromJSON (ApiTxInputGeneral n)
where
parseJSON = genericParseJSON defaultRecordTypeOptions
parseJSON obj = do
derPathM <-
(withObject "ApiTxInputGeneral" $
\o -> o .:? "derivation_path" :: Aeson.Parser (Maybe (NonEmpty (ApiT DerivationIndex)))) obj
case derPathM of
Nothing -> do
xs <- parseJSON obj :: Aeson.Parser (ApiT TxIn)
pure $ ExternalInput xs
Just _ -> do
xs <- parseJSON obj :: Aeson.Parser (ApiWalletInput n)
pure $ WalletInput xs
instance
( EncodeAddress n
, EncodeStakeAddress n
) => ToJSON (ApiTxInputGeneral n)
where
toJSON = genericToJSON defaultRecordTypeOptions
toJSON (ExternalInput content) = toJSON content
toJSON (WalletInput content) = toJSON content

instance FromJSON (ApiT TxMetadata) where
parseJSON = fmap ApiT
Expand Down
Loading

0 comments on commit 03ce121

Please sign in to comment.