@@ -54,40 +54,7 @@ import VVA.API.Utils
54
54
import VVA.Config
55
55
import qualified VVA.Proposal as Proposal
56
56
import VVA.Types (AppError (ValidationError ))
57
-
58
- newtype HexText
59
- = HexText { unHexText :: Text }
60
- deriving newtype (Eq , Show )
61
-
62
- instance FromJSON HexText where
63
- parseJSON (Aeson. String t) = do
64
- if Text. length t `mod` 2 == 1 || Text. any (not . isHexDigit) t
65
- then mzero
66
- else pure $ HexText t
67
-
68
- instance ToJSON HexText where
69
- toJSON (HexText t) = Aeson. String t
70
-
71
- -- To use it in routes, we need to be able to parse it from Text:
72
- instance FromHttpApiData HexText where
73
- parseUrlPiece txt
74
- | Text. all isHexDigit txt && even (Text. length txt) = Right (HexText txt)
75
- | otherwise = Left " Not a valid hex value"
76
-
77
-
78
- instance ToParamSchema HexText where
79
- toParamSchema _ = mempty
80
- & type_ ?~ OpenApiString
81
- & format ?~ " hex"
82
-
83
- instance ToSchema HexText where
84
- declareNamedSchema _ = do
85
- textSchema <- declareNamedSchema (Proxy :: Proxy Text )
86
- return $ textSchema
87
- & name ?~ " HexText"
88
- & schema . type_ ?~ OpenApiString
89
- & schema . format ?~ " hex"
90
- & schema . example ?~ toJSON (HexText " a1b2c3" )
57
+ import VVA.Common.Types
91
58
92
59
newtype AnyValue
93
60
= AnyValue { unAnyValue :: Maybe Value }
@@ -201,37 +168,6 @@ instance ToParamSchema GovernanceActionType where
201
168
& type_ ?~ OpenApiString
202
169
& enum_ ?~ map toJSON (enumFromTo minBound maxBound :: [GovernanceActionType ])
203
170
204
-
205
- data DRepSortMode = Random | VotingPower | RegistrationDate | Status deriving (Bounded , Enum , Eq , Generic , Read , Show )
206
-
207
- instance FromJSON DRepSortMode where
208
- parseJSON (Aeson. String dRepSortMode) = pure $ fromJust $ readMaybe (Text. unpack dRepSortMode)
209
- parseJSON _ = fail " "
210
-
211
- instance ToJSON DRepSortMode where
212
- toJSON x = Aeson. String $ Text. pack $ show x
213
-
214
- instance ToSchema DRepSortMode where
215
- declareNamedSchema proxy = do
216
- NamedSchema name_ schema_ <- genericDeclareNamedSchema (fromAesonOptions defaultOptions) proxy
217
- return $
218
- NamedSchema name_ $
219
- schema_
220
- & description ?~ " DRep Sort Mode"
221
- & example ?~ toJSON VotingPower
222
-
223
- instance FromHttpApiData DRepSortMode where
224
- parseQueryParam t = case readMaybe $ Text. unpack t of
225
- Just x -> Right x
226
- Nothing -> Left (" incorrect DRep sort mode: " <> t)
227
-
228
- instance ToParamSchema DRepSortMode where
229
- toParamSchema _ =
230
- mempty
231
- & type_ ?~ OpenApiString
232
- & enum_ ?~ map toJSON (enumFromTo minBound maxBound :: [DRepSortMode ])
233
-
234
-
235
171
data GovernanceActionSortMode = SoonestToExpire | NewestCreated | MostYesVotes deriving
236
172
( Bounded
237
173
, Enum
@@ -670,115 +606,6 @@ instance ToSchema GetTransactionStatusResponse where
670
606
& example
671
607
?~ toJSON exampleGetTransactionStatusResponse
672
608
673
- newtype DRepHash
674
- = DRepHash Text
675
- deriving (Generic , Show )
676
-
677
- instance FromJSON DRepHash where
678
- parseJSON (Aeson. String s) = pure $ DRepHash s
679
- parseJSON x = fail (" expected DRepHash to be a string but got: " <> Char8. unpack (encode x))
680
-
681
- instance ToJSON DRepHash where
682
- toJSON (DRepHash raw) = toJSON raw
683
-
684
-
685
- exampleDrepHash :: Text
686
- exampleDrepHash = " b4e4184bfedf920fec53cdc327de4da661ae427784c0ccca9e3c2f50"
687
-
688
- instance ToSchema DRepHash where
689
- declareNamedSchema _ = pure $ NamedSchema (Just " DRepHash" ) $ mempty
690
- & type_ ?~ OpenApiObject
691
- & description ?~ " Hash of a DRep"
692
- & example
693
- ?~ toJSON exampleDrepHash
694
-
695
-
696
- data DRepStatus = Active | Inactive | Retired deriving (Bounded , Enum , Eq , Generic , Ord , Read , Show )
697
-
698
- -- ToJSON instance for DRepStatus
699
- instance ToJSON DRepStatus where
700
- toJSON Retired = " Retired"
701
- toJSON Active = " Active"
702
- toJSON Inactive = " Inactive"
703
-
704
- -- FromJSON instance for DRepStatus
705
- instance FromJSON DRepStatus where
706
- parseJSON = withText " DRepStatus" $ \ case
707
- " Retired" -> pure Retired
708
- " Active" -> pure Active
709
- " Inactive" -> pure Inactive
710
- _ -> fail " Invalid DRepStatus"
711
-
712
- -- ToSchema instance for DRepStatus
713
- instance ToSchema DRepStatus where
714
- declareNamedSchema _ = pure $ NamedSchema (Just " DRepStatus" ) $ mempty
715
- & type_ ?~ OpenApiString
716
- & description ?~ " DRep Status"
717
- & enum_ ?~ map toJSON [Retired , Active , Inactive ]
718
-
719
- instance FromHttpApiData DRepStatus where
720
- parseQueryParam t = case readMaybe $ Text. unpack t of
721
- Just x -> Right x
722
- Nothing -> Left (" incorrect DRep status " <> t)
723
-
724
- instance ToParamSchema DRepStatus where
725
- toParamSchema _ =
726
- mempty
727
- & type_ ?~ OpenApiString
728
- & enum_ ?~ map toJSON (enumFromTo minBound maxBound :: [DRepStatus ])
729
-
730
- data DRepType = NormalDRep | SoleVoter
731
-
732
- instance Show DRepType where
733
- show NormalDRep = " DRep"
734
- show SoleVoter = " SoleVoter"
735
-
736
- -- ToJSON instance for DRepType
737
- instance ToJSON DRepType where
738
- toJSON NormalDRep = " DRep"
739
- toJSON SoleVoter = " SoleVoter"
740
-
741
- -- FromJSON instance for DRepType
742
- instance FromJSON DRepType where
743
- parseJSON = withText " DRepType" $ \ case
744
- " DRep" -> pure NormalDRep
745
- " SoleVoter" -> pure SoleVoter
746
- _ -> fail " Invalid DRepType"
747
-
748
- -- ToSchema instance for DRepType
749
- instance ToSchema DRepType where
750
- declareNamedSchema _ = pure $ NamedSchema (Just " DRepType" ) $ mempty
751
- & type_ ?~ OpenApiString
752
- & description ?~ " DRep Type"
753
- & enum_ ?~ map toJSON [NormalDRep , SoleVoter ]
754
-
755
- data DRep
756
- = DRep
757
- { dRepIsScriptBased :: Bool
758
- , dRepDrepId :: DRepHash
759
- , dRepView :: Text
760
- , dRepUrl :: Maybe Text
761
- , dRepMetadataHash :: Maybe Text
762
- , dRepDeposit :: Integer
763
- , dRepVotingPower :: Maybe Integer
764
- , dRepStatus :: DRepStatus
765
- , dRepType :: DRepType
766
- , dRepLatestTxHash :: Maybe HexText
767
- , dRepLatestRegistrationDate :: UTCTime
768
- , dRepMetadataError :: Maybe Text
769
- , dRepPaymentAddress :: Maybe Text
770
- , dRepGivenName :: Maybe Text
771
- , dRepObjectives :: Maybe Text
772
- , dRepMotivations :: Maybe Text
773
- , dRepQualifications :: Maybe Text
774
- , dRepImageUrl :: Maybe Text
775
- , dRepImageHash :: Maybe HexText
776
- }
777
- deriving (Generic , Show )
778
-
779
-
780
- deriveJSON (jsonOptions " dRep" ) ''DRep
781
-
782
609
exampleDrep :: Text
783
610
exampleDrep =
784
611
" {\" drepId\" : \" d3a62ffe9c214e1a6a9809f7ab2a104c117f85e1f171f8f839d94be5\" ,"
@@ -800,21 +627,6 @@ exampleDrep =
800
627
<> " \" imageUrl\" : \" https://image.url\" ,"
801
628
<> " \" imageHash\" : \" 9198b1b204273ba5c67a13310b5a806034160f6a063768297e161d9b759cad61\" }"
802
629
803
- -- ToSchema instance for DRep
804
- instance ToSchema DRep where
805
- declareNamedSchema proxy = do
806
- NamedSchema name_ schema_ <-
807
- genericDeclareNamedSchema
808
- ( fromAesonOptions $ jsonOptions " dRep" )
809
- proxy
810
- return $
811
- NamedSchema name_ $
812
- schema_
813
- & description ?~ " DRep"
814
- & example
815
- ?~ toJSON exampleDrep
816
-
817
-
818
630
exampleListDRepsResponse :: Text
819
631
exampleListDRepsResponse =
820
632
" { \" page\" : 0,"
0 commit comments