Skip to content

Commit

Permalink
add mutual bet server
Browse files Browse the repository at this point in the history
  • Loading branch information
volodyaeleks committed Sep 24, 2021
1 parent 67b6a7a commit 2a479ee
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 18 deletions.
15 changes: 15 additions & 0 deletions eleks/oracle/README.md
Expand Up @@ -26,6 +26,21 @@ curl -v -X PUT -H "Content-Type: application/json" \
-d '{"ugpSatus": "FT", "ugpWinnerTeamId": 55}' \
http://localhost:8081/games/1

## Mutual bet rest server

1. Build the game rest server:
```
cabal build mutualbetserver
```
2. Run the Games server:
```
cabal exec -- mutualbetserver
```

### game server API

1. Wallet info
curl -s http://localhost:8082/wallet/1

## The Plutus Application Backend (PAB) example
We have provided an example PAB application in `./pab`. With the PAB we can serve and interact
Expand Down
20 changes: 10 additions & 10 deletions eleks/oracle/gameserver/Server.hs
Expand Up @@ -5,17 +5,17 @@

module Main(main) where

import Data.Aeson
import Data.Text
import Data.String (fromString)
import Control.Monad.Except
import Control.Monad.Reader
import GHC.Generics (Generic)
import Servant
import Service as GamesService
import Data.Aeson
import Data.Text
import Data.String (fromString)
import Control.Monad.Except
import Control.Monad.Reader
import GHC.Generics (Generic)
import Servant
import Service as GamesService
import qualified Data.ByteString.Char8 as B
import Network.Wai.Handler.Warp
import Types.Game
import Network.Wai.Handler.Warp
import Types.Game

type GamesAPI = "games" :> Get '[JSON] [Game]
:<|> "games" :> Capture "id" GameId :> Get '[JSON] Game
Expand Down
38 changes: 30 additions & 8 deletions eleks/oracle/mutual-bet.cabal
Expand Up @@ -114,7 +114,7 @@ executable bet-pab
lens -any,
plutus-contract -any,
plutus-pab -any,
mutual-bet -any,
mutual-bet,
aeson -any,
freer-simple -any,
prettyprinter -any,
Expand All @@ -133,7 +133,7 @@ executable gs
base >= 4.9 && < 5,
cardano-api,
cardano-ledger-alonzo,
mutual-bet -any,
mutual-bet,
plutus-contract,
plutus-ledger,
plutus-ledger-api,
Expand All @@ -155,20 +155,42 @@ executable gameserver
either,
lens,
mtl,
mutual-bet -any,
mutual-bet,
servant-server -any,
text -any,
utf8-string,
warp,
warp

executable gamesclient
main-is: GameClient.hs
-- executable gamesclient
-- main-is: GameClient.hs
-- hs-source-dirs: pab
-- ghc-options: -threaded
-- build-depends:
-- aeson,
-- base >= 4.9 && < 5,
-- bytestring,
-- mutual-bet,
-- text -any,
-- req

executable mutualbetserver
main-is: MutualBetServer.hs
hs-source-dirs: pab
ghc-options: -threaded
build-depends:
aeson,
aeson-pretty,
base >= 4.9 && < 5,
bytestring,
mutual-bet -any,
data-default -any,
either,
lens,
mtl,
mutual-bet,
servant-server -any,
plutus-contract,
plutus-ledger,
plutus-tx,
text -any,
req
utf8-string,
warp,
55 changes: 55 additions & 0 deletions eleks/oracle/pab/MutualBetServer.hs
@@ -0,0 +1,55 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}

module Main(main) where

import Data.Aeson
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Extras as Aeson
import Data.Text
import Data.String (fromString)
import Control.Monad.Except
import Control.Monad.Reader
import GHC.Generics (Generic)
import Servant
import qualified Data.ByteString.Char8 as B
import Ledger (pubKeyHash, getPubKeyHash, pubKeyAddress, PubKey, Address, PubKeyHash)
import Network.Wai.Handler.Warp
import Types.Game
import Wallet.Emulator (walletPubKey, Wallet (..))
import qualified PlutusTx.Prelude as PlutusTx

type GamesAPI = "wallet" :> Capture "id" Integer :> Get '[JSON] WalletData

data WalletData = WalletData
{ walletDataPubKey :: PubKey
, walletDataPubKeyHash :: PubKeyHash
, walletDataPubKeyHashStr :: Text
, walletDataAddress :: !Address
} deriving Generic
instance FromJSON WalletData
instance ToJSON WalletData

mutualBetAPI :: Proxy GamesAPI
mutualBetAPI = Proxy

mutualBetServer :: Server GamesAPI
mutualBetServer = wallet
where
wallet:: Integer -> Handler WalletData
wallet walletId = do
let pubKey = walletPubKey . Wallet $ walletId
return WalletData { walletDataPubKey = pubKey
, walletDataPubKeyHash = pubKeyHash pubKey
, walletDataPubKeyHashStr = Aeson.encodeByteString $ PlutusTx.fromBuiltin $ getPubKeyHash $ pubKeyHash pubKey
, walletDataAddress = pubKeyAddress pubKey
}

mutualBetApp :: Application
mutualBetApp = serve mutualBetAPI mutualBetServer

main :: IO ()
main = do
run 8082 mutualBetApp

0 comments on commit 2a479ee

Please sign in to comment.