diff --git a/ChangeLog.md b/ChangeLog.md index b12b46f..20172c3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # Changelog for smash +## Next version + +### Story + +- [CAD-2169] - Expose API types in a separate package + ## 1.2.0 ### Story diff --git a/cabal.project b/cabal.project index e98f157..617bd34 100644 --- a/cabal.project +++ b/cabal.project @@ -1,7 +1,8 @@ index-state: 2020-07-15T00:00:00Z packages: - ./ + ./smash + ./smash-servant-types -- ----------------------------------------------------------------------------- -- Disable all tests by defauly and yhen enable specific tests in this repo @@ -11,6 +12,9 @@ tests: False package smash tests: True +package smash-servant-types + tests: True + test-show-details: direct -- ----------------------------------------------------------------------------- diff --git a/default.nix b/default.nix index 25d231a..0be5d1c 100644 --- a/default.nix +++ b/default.nix @@ -28,7 +28,7 @@ let }; packages = { - inherit haskellPackages scripts smash-exe; + inherit haskellPackages scripts smash-exe smash-exe-testing; inherit (haskellPackages.smash.identifier) version; # `tests` are the test suites which have been built. @@ -36,7 +36,9 @@ let libs = collectComponents' "library" haskellPackages; - exes = collectComponents' "exes" haskellPackages; + exes = lib.recursiveUpdate (collectComponents' "exes" haskellPackages) { + smash = { inherit smash-exe-testing; }; + }; checks = recurseIntoAttrs { # `checks.tests` collect results of executing the tests: diff --git a/doc/getting-started/how-to-run-smash.md b/doc/getting-started/how-to-run-smash.md index 9e6291d..698dac7 100644 --- a/doc/getting-started/how-to-run-smash.md +++ b/doc/getting-started/how-to-run-smash.md @@ -104,6 +104,18 @@ SMASHPGPASSFILE=config/pgpass ./smash-local run-app-with-db-sync --config config After this, the SMASH application should start syncing blocks and picking up pools. +## Running tests + +You can run tests using Stack: +``` +stack test --fast -j`nproc` --flag 'smash:testing-mode' --flag 'smash-servant-types:testing-mode' +``` + +Or Cabal: +``` +cabal test all -f testing-mode +``` + ## Checking if it works For example, after seeing that a pool has be registered, you can try to get it's info by running it's poolid and hash (the example of the hash here is `93b13334b5edf623fd4c7a716f3cf47be5baf7fb3a431c16ee07aab8ff074873`): diff --git a/nix/haskell.nix b/nix/haskell.nix index a911b42..5045552 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -7,26 +7,24 @@ , buildPackages , config ? {} # GHC attribute name -, compiler ? config.haskellNix.compiler or "ghc865" +, compiler +# Source root directory +, src # Enable profiling , profiling ? config.haskellNix.profiling or false +, projectPackagesNames +# Disable basic auth by default: +, flags ? [ "disable-basic-auth" ] }: let - src = haskell-nix.haskellLib.cleanGit { - name = "smash-src"; - src = ../.; - }; - - projectPackages = lib.attrNames (haskell-nix.haskellLib.selectProjectPackages - (haskell-nix.cabalProject { inherit src; })); - # This creates the Haskell package set. # https://input-output-hk.github.io/haskell.nix/user-guide/projects/ pkgSet = haskell-nix.cabalProject { inherit src; compiler-nix-name = compiler; modules = [ + # Allow reinstallation of Win32 { nonReinstallablePkgs = [ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base" @@ -44,12 +42,14 @@ let ]; } { - # Disable basic auth: - packages.smash.flags.disable-basic-auth = true; + # Set flags + packages = lib.genAttrs projectPackagesNames (_: { + flags = lib.genAttrs flags (_: true); + }); } # TODO: Compile all local packages with -Werror: #{ - # packages = lib.genAttrs projectPackages + # packages = lib.genAttrs projectPackagesNames # (name: { configureFlags = [ "--ghc-option=-Werror" ]; }); #} ]; diff --git a/nix/pkgs.nix b/nix/pkgs.nix index 285b8a9..6e0ea00 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -2,13 +2,30 @@ pkgs: _: with pkgs; let compiler = config.haskellNix.compiler or "ghc865"; + src = haskell-nix.haskellLib.cleanGit { + name = "smash-src"; + src = ../.; + }; + projectPackagesNames = lib.attrNames (haskell-nix.haskellLib.selectProjectPackages + (haskell-nix.cabalProject { inherit src; compiler-nix-name = compiler; })); in { + + inherit projectPackagesNames; + + smashHaskellPackages = callPackage ./haskell.nix { - inherit compiler; + inherit compiler src projectPackagesNames; + }; + + smashTestingHaskellPackages = callPackage ./haskell.nix { + inherit compiler src projectPackagesNames; + flags = [ "testing-mode" ]; }; # Grab the executable component of our package. inherit (smashHaskellPackages.smash.components.exes) smash-exe; + smash-exe-testing = smashTestingHaskellPackages.smash.components.exes.smash-exe; + } diff --git a/shell.nix b/shell.nix index fe231b0..d69bd0e 100644 --- a/shell.nix +++ b/shell.nix @@ -13,7 +13,7 @@ let shell = smashHaskellPackages.shellFor { name = "cabal-dev-shell"; - packages = ps: lib.attrValues (haskell-nix.haskellLib.selectProjectPackages ps); + packages = ps: lib.attrValues (lib.getAttrs projectPackagesNames ps); # These programs will be available inside the nix-shell. buildInputs = with haskellPackages; [ diff --git a/LICENSE b/smash-servant-types/LICENSE similarity index 100% rename from LICENSE rename to smash-servant-types/LICENSE diff --git a/Setup.hs b/smash-servant-types/Setup.hs similarity index 100% rename from Setup.hs rename to smash-servant-types/Setup.hs diff --git a/smash-servant-types/smash-servant-types.cabal b/smash-servant-types/smash-servant-types.cabal new file mode 100644 index 0000000..1ab6652 --- /dev/null +++ b/smash-servant-types/smash-servant-types.cabal @@ -0,0 +1,63 @@ +cabal-version: 1.12 +name: smash-servant-types +version: 1.2.0 +description: + Shared servant API types for SMASH + +homepage: https://github.com/input-output-hk/smash#readme +bug-reports: https://github.com/input-output-hk/smash/issues +author: IOHK +maintainer: operations@iohk.io +license: Apache-2.0 +license-file: LICENSE +build-type: Simple + +source-repository head + type: git + location: https://github.com/input-output-hk/smash + +flag disable-basic-auth + description: Disable basic authentication scheme for other authentication mechanisms. + default: False + +flag testing-mode + description: A flag for allowing operations that promote easy testing. + default: False + +library + if flag(disable-basic-auth) + cpp-options: -DDISABLE_BASIC_AUTH + + if flag(testing-mode) + cpp-options: -DTESTING_MODE + + exposed-modules: + Cardano.SMASH.API + Cardano.SMASH.Types + Cardano.SMASH.DBSync.Db.Error + Cardano.SMASH.DBSync.Db.Types + + hs-source-dirs: src + build-depends: + aeson + , base >=4.7 && <5 + , bytestring + , cardano-prelude + , persistent + , servant + , servant-server + , servant-swagger + , swagger2 + , text + , time + + default-language: Haskell2010 + default-extensions: + NoImplicitPrelude + OverloadedStrings + + ghc-options: + -Wall -Wcompat -Wincomplete-record-updates + -Wincomplete-uni-patterns -Wredundant-constraints -Wpartial-fields + -fno-warn-orphans + diff --git a/src/Cardano/SMASH/API.hs b/smash-servant-types/src/Cardano/SMASH/API.hs similarity index 98% rename from src/Cardano/SMASH/API.hs rename to smash-servant-types/src/Cardano/SMASH/API.hs index 5b3b6dc..48e5a2a 100644 --- a/src/Cardano/SMASH/API.hs +++ b/smash-servant-types/src/Cardano/SMASH/API.hs @@ -22,7 +22,7 @@ import Servant (BasicAuth, Capture, Get, Header, Headers, import Servant.Swagger (HasSwagger (..)) -import Cardano.SMASH.DB (DBFail) +import Cardano.SMASH.DBSync.Db.Error (DBFail) import Cardano.SMASH.Types (ApiResult, HealthStatus, PoolFetchError, PoolId, PoolMetadataHash, PoolMetadataWrapped, TimeStringFormat, diff --git a/src/Cardano/SMASH/DBSync/Db/Error.hs b/smash-servant-types/src/Cardano/SMASH/DBSync/Db/Error.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Error.hs rename to smash-servant-types/src/Cardano/SMASH/DBSync/Db/Error.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Types.hs b/smash-servant-types/src/Cardano/SMASH/DBSync/Db/Types.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Types.hs rename to smash-servant-types/src/Cardano/SMASH/DBSync/Db/Types.hs diff --git a/src/Cardano/SMASH/Types.hs b/smash-servant-types/src/Cardano/SMASH/Types.hs similarity index 97% rename from src/Cardano/SMASH/Types.hs rename to smash-servant-types/src/Cardano/SMASH/Types.hs index dde4e3f..b2e5f41 100644 --- a/src/Cardano/SMASH/Types.hs +++ b/smash-servant-types/src/Cardano/SMASH/Types.hs @@ -44,7 +44,7 @@ import Cardano.Prelude import Control.Monad.Fail (fail) import Data.Aeson (FromJSON (..), ToJSON (..), - object, pairs, withObject, (.:), (.=)) + object, withObject, (.:), (.=)) import qualified Data.Aeson as Aeson import Data.Aeson.Encoding (unsafeToEncoding) import qualified Data.Aeson.Types as Aeson @@ -58,13 +58,14 @@ import Data.Swagger (NamedSchema (..), ToSchema (..)) import Data.Text.Encoding (encodeUtf8Builder) -import Servant (FromHttpApiData (..), MimeUnrender (..), OctetStream) +import Servant (FromHttpApiData (..), + MimeUnrender (..), OctetStream) import Cardano.SMASH.DBSync.Db.Error import Cardano.SMASH.DBSync.Db.Types -import qualified Data.Text.Encoding as E -import qualified Data.ByteString.Lazy as BL +import qualified Data.ByteString.Lazy as BL +import qualified Data.Text.Encoding as E -- | The basic @Configuration@. data Configuration = Configuration diff --git a/smash/LICENSE b/smash/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/smash/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/smash/Setup.hs b/smash/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/smash/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/app/Main.hs b/smash/app/Main.hs similarity index 98% rename from app/Main.hs rename to smash/app/Main.hs index 595fb84..5a85461 100644 --- a/app/Main.hs +++ b/smash/app/Main.hs @@ -18,14 +18,12 @@ import Options.Applicative (Parser, ParserInfo, ParserPrefs) import qualified Options.Applicative as Opt -#ifndef STUB_MODE import Cardano.Slotting.Slot (SlotNo (..)) import Cardano.SMASH.DBSyncPlugin (poolMetadataDbSyncNodePlugin) import Cardano.SMASH.DBSync.SmashDbSync (ConfigFile (..), SmashDbSyncNodeParams (..), SocketPath (..), runDbSyncNode) -#endif main :: IO () @@ -50,10 +48,8 @@ data Command #ifdef TESTING_MODE | RunStubApplication #endif -#ifndef STUB_MODE | RunApplicationWithDbSync SmashDbSyncNodeParams | InsertPool FilePath PoolId PoolMetadataHash -#endif | ReserveTickerName Text PoolMetadataHash runCommand :: Command -> IO () @@ -65,7 +61,6 @@ runCommand cmd = #ifdef TESTING_MODE RunStubApplication -> runAppStubbed defaultConfiguration #endif -#ifndef STUB_MODE RunApplicationWithDbSync dbSyncNodeParams -> race_ (runDbSyncNode poolMetadataDbSyncNodePlugin dbSyncNodeParams) @@ -78,7 +73,6 @@ runCommand cmd = (\err -> putTextLn $ "Error occured. " <> renderLookupFail err) (\_ -> putTextLn "Insertion completed!") result -#endif ReserveTickerName tickerName poolHash -> do putTextLn "Reserving ticker name!" result <- runTickerNameInsertion tickerName poolHash @@ -96,7 +90,6 @@ doCreateMigration mdir = do ------------------------------------------------------------------------------- -#ifndef STUB_MODE pCommandLine :: Parser SmashDbSyncNodeParams pCommandLine = SmashDbSyncNodeParams @@ -139,7 +132,6 @@ pSlotNo = <> Opt.help "Force a rollback to the specified slot (mainly for testing and debugging)." <> Opt.metavar "WORD" ) -#endif pVersion :: Parser (a -> a) pVersion = @@ -170,7 +162,6 @@ pCommand = $ Opt.progDesc "Run the stub application that just serves the pool info." ) #endif -#ifndef STUB_MODE <> Opt.command "run-app-with-db-sync" ( Opt.info pRunAppWithDbSync $ Opt.progDesc "Run the application that syncs up the pool info and serves it." @@ -179,7 +170,6 @@ pCommand = ( Opt.info pInsertPool $ Opt.progDesc "Inserts the pool into the database (utility)." ) -#endif <> Opt.command "reserve-ticker-name" ( Opt.info pReserveTickerName $ Opt.progDesc "Inserts the ticker name into the database (utility)." @@ -205,7 +195,6 @@ pCommand = pure RunStubApplication #endif -#ifndef STUB_MODE -- Empty right now but we might add some params over time. Like ports and stuff? pRunAppWithDbSync :: Parser Command pRunAppWithDbSync = @@ -215,7 +204,6 @@ pCommand = pInsertPool :: Parser Command pInsertPool = InsertPool <$> pFilePath <*> pPoolId <*> pPoolHash -#endif -- For inserting ticker names. pReserveTickerName :: Parser Command diff --git a/smash.cabal b/smash/smash.cabal similarity index 85% rename from smash.cabal rename to smash/smash.cabal index 84ec5c4..b24913c 100644 --- a/smash.cabal +++ b/smash/smash.cabal @@ -11,28 +11,19 @@ maintainer: operations@iohk.io license: Apache-2.0 license-file: LICENSE build-type: Simple -extra-source-files: - README.rst - ChangeLog.md source-repository head type: git location: https://github.com/input-output-hk/smash flag disable-basic-auth - description: - Disable basic authentication scheme for other authentication mechanisms. - + description: Disable basic authentication scheme for other authentication mechanisms. default: False flag testing-mode description: A flag for allowing operations that promote easy testing. default: False -flag stub-mode - description: Only enable the stub server, disable cardano-db-sync - default: False - library if flag(disable-basic-auth) cpp-options: -DDISABLE_BASIC_AUTH @@ -40,21 +31,10 @@ library if flag(testing-mode) cpp-options: -DTESTING_MODE - if flag(stub-mode) - cpp-options: -DSTUB_MODE - else - build-depends: - cardano-db-sync - exposed-modules: - Cardano.SMASH.DBSyncPlugin - Cardano.SMASH.DBSync.SmashDbSync - Cardano.SMASH.DBSync.Db.Database - exposed-modules: - Cardano.SMASH.API Cardano.SMASH.DB + Cardano.SMASH.DBSync.Db.Database Cardano.SMASH.DBSync.Db.Delete - Cardano.SMASH.DBSync.Db.Error Cardano.SMASH.DBSync.Db.Insert Cardano.SMASH.DBSync.Db.Migration Cardano.SMASH.DBSync.Db.Migration.Haskell @@ -63,13 +43,13 @@ library Cardano.SMASH.DBSync.Db.Query Cardano.SMASH.DBSync.Db.Run Cardano.SMASH.DBSync.Db.Schema - Cardano.SMASH.DBSync.Db.Types Cardano.SMASH.DBSync.Metrics + Cardano.SMASH.DBSync.SmashDbSync + Cardano.SMASH.DBSyncPlugin Cardano.SMASH.FetchQueue Cardano.SMASH.FetchQueue.Retry Cardano.SMASH.Lib Cardano.SMASH.Offline - Cardano.SMASH.Types other-modules: Paths_smash hs-source-dirs: src @@ -84,6 +64,7 @@ library , cardano-crypto , cardano-crypto-class , cardano-crypto-wrapper + , cardano-db-sync , cardano-ledger , cardano-prelude , cardano-slotting @@ -121,6 +102,7 @@ library , servant-server , servant-swagger , shelley-spec-ledger + , smash-servant-types , swagger2 , template-haskell , text @@ -142,6 +124,10 @@ library -Wincomplete-uni-patterns -Wredundant-constraints -Wpartial-fields executable smash-exe + + if flag(testing-mode) + cpp-options: -DTESTING_MODE + main-is: Main.hs other-modules: Paths_smash hs-source-dirs: app @@ -149,9 +135,11 @@ executable smash-exe build-depends: base >=4.7 && <5 , cardano-prelude + , cardano-db-sync , cardano-slotting , optparse-applicative , smash + , smash-servant-types default-language: Haskell2010 default-extensions: @@ -162,16 +150,11 @@ executable smash-exe -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wpartial-fields +test-suite smash-test + if flag(testing-mode) cpp-options: -DTESTING_MODE - if flag(stub-mode) - cpp-options: -DSTUB_MODE - else - build-depends: - cardano-db-sync - -test-suite smash-test type: exitcode-stdio-1.0 main-is: Spec.hs other-modules: @@ -190,6 +173,7 @@ test-suite smash-test , QuickCheck , quickcheck-state-machine >=0.6 , smash + , smash-servant-types , tree-diff default-language: Haskell2010 @@ -200,3 +184,4 @@ test-suite smash-test ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wpartial-fields + diff --git a/src/Cardano/SMASH/DB.hs b/smash/src/Cardano/SMASH/DB.hs similarity index 100% rename from src/Cardano/SMASH/DB.hs rename to smash/src/Cardano/SMASH/DB.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Database.hs b/smash/src/Cardano/SMASH/DBSync/Db/Database.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Database.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Database.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Delete.hs b/smash/src/Cardano/SMASH/DBSync/Db/Delete.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Delete.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Delete.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Insert.hs b/smash/src/Cardano/SMASH/DBSync/Db/Insert.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Insert.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Insert.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Migration.hs b/smash/src/Cardano/SMASH/DBSync/Db/Migration.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Migration.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Migration.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Migration/Haskell.hs b/smash/src/Cardano/SMASH/DBSync/Db/Migration/Haskell.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Migration/Haskell.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Migration/Haskell.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Migration/Version.hs b/smash/src/Cardano/SMASH/DBSync/Db/Migration/Version.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Migration/Version.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Migration/Version.hs diff --git a/src/Cardano/SMASH/DBSync/Db/PGConfig.hs b/smash/src/Cardano/SMASH/DBSync/Db/PGConfig.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/PGConfig.hs rename to smash/src/Cardano/SMASH/DBSync/Db/PGConfig.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Query.hs b/smash/src/Cardano/SMASH/DBSync/Db/Query.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Query.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Query.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Run.hs b/smash/src/Cardano/SMASH/DBSync/Db/Run.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Run.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Run.hs diff --git a/src/Cardano/SMASH/DBSync/Db/Schema.hs b/smash/src/Cardano/SMASH/DBSync/Db/Schema.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Db/Schema.hs rename to smash/src/Cardano/SMASH/DBSync/Db/Schema.hs diff --git a/src/Cardano/SMASH/DBSync/Metrics.hs b/smash/src/Cardano/SMASH/DBSync/Metrics.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/Metrics.hs rename to smash/src/Cardano/SMASH/DBSync/Metrics.hs diff --git a/src/Cardano/SMASH/DBSync/SmashDbSync.hs b/smash/src/Cardano/SMASH/DBSync/SmashDbSync.hs similarity index 100% rename from src/Cardano/SMASH/DBSync/SmashDbSync.hs rename to smash/src/Cardano/SMASH/DBSync/SmashDbSync.hs diff --git a/src/Cardano/SMASH/DBSyncPlugin.hs b/smash/src/Cardano/SMASH/DBSyncPlugin.hs similarity index 100% rename from src/Cardano/SMASH/DBSyncPlugin.hs rename to smash/src/Cardano/SMASH/DBSyncPlugin.hs diff --git a/src/Cardano/SMASH/FetchQueue.hs b/smash/src/Cardano/SMASH/FetchQueue.hs similarity index 100% rename from src/Cardano/SMASH/FetchQueue.hs rename to smash/src/Cardano/SMASH/FetchQueue.hs diff --git a/src/Cardano/SMASH/FetchQueue/Retry.hs b/smash/src/Cardano/SMASH/FetchQueue/Retry.hs similarity index 100% rename from src/Cardano/SMASH/FetchQueue/Retry.hs rename to smash/src/Cardano/SMASH/FetchQueue/Retry.hs diff --git a/src/Cardano/SMASH/Lib.hs b/smash/src/Cardano/SMASH/Lib.hs similarity index 97% rename from src/Cardano/SMASH/Lib.hs rename to smash/src/Cardano/SMASH/Lib.hs index b8567cb..ca59e49 100644 --- a/src/Cardano/SMASH/Lib.hs +++ b/smash/src/Cardano/SMASH/Lib.hs @@ -49,7 +49,7 @@ import Cardano.SMASH.Types (ApiResult (..), ApplicationUsers (..), Configuration (..), HealthStatus (..), PoolFetchError, - PoolId, PoolMetadataHash, + PoolId (..), PoolMetadataHash, PoolMetadataWrapped (..), TimeStringFormat (..), User, UserValidity (..), @@ -333,10 +333,12 @@ retirePool dataLayer poolId = convertIOToHandler $ do return . ApiResult $ retiredPoolId addPool :: DataLayer -> PoolId -> PoolMetadataHash -> PoolMetadataWrapped -> Handler (ApiResult DBFail PoolId) -addPool dataLayer poolId poolHash (PoolMetadataWrapped poolMetadataJson) = - fmap ApiResult - $ convertIOToHandler - $ (fmap . second) (const poolId) - $ runPoolInsertion dataLayer poolMetadataJson poolId poolHash +addPool dataLayer poolId poolHash (PoolMetadataWrapped poolMetadataJson) = convertIOToHandler $ do + + poolMetadataE <- runPoolInsertion dataLayer poolMetadataJson poolId poolHash + + case poolMetadataE of + Left dbFail -> return . ApiResult . Left $ dbFail + Right poolMetadata -> return . ApiResult . Right $ poolId #endif diff --git a/src/Cardano/SMASH/Offline.hs b/smash/src/Cardano/SMASH/Offline.hs similarity index 100% rename from src/Cardano/SMASH/Offline.hs rename to smash/src/Cardano/SMASH/Offline.hs diff --git a/test/SmashSpec.hs b/smash/test/SmashSpec.hs similarity index 100% rename from test/SmashSpec.hs rename to smash/test/SmashSpec.hs diff --git a/test/SmashSpecSM.hs b/smash/test/SmashSpecSM.hs similarity index 100% rename from test/SmashSpecSM.hs rename to smash/test/SmashSpecSM.hs diff --git a/test/Spec.hs b/smash/test/Spec.hs similarity index 100% rename from test/Spec.hs rename to smash/test/Spec.hs diff --git a/stack.yaml b/stack.yaml index 4e41bfb..1a08f95 100644 --- a/stack.yaml +++ b/stack.yaml @@ -13,7 +13,8 @@ compiler: ghc-8.6.5 # - auto-update # - wai packages: -- . +- smash +- smash-servant-types flags: # Bundle VRF crypto in libsodium and do not rely on an external fork to have it.