Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-manole committed Feb 6, 2023
1 parent 4617be9 commit 3cf31c1
Show file tree
Hide file tree
Showing 4 changed files with 349 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ docker/
Makefile
*.sqlite
react-web/node_modules/
*.ignore.*
1 change: 1 addition & 0 deletions plutus-certification.cabal
Expand Up @@ -66,6 +66,7 @@ library
Plutus.Certification.API.Routes
Plutus.Certification.API.Swagger
Plutus.Certification.Web3StorageClient
Plutus.Certification.WalletClient.Transaction
autogen-modules: Paths_plutus_certification
default-language: Haskell2010

Expand Down
42 changes: 29 additions & 13 deletions src/Plutus/Certification/WalletClient.hs
Expand Up @@ -13,8 +13,10 @@ module Plutus.Certification.WalletClient
, Amount(..)
, WalletArgs(..)
, broadcastTransaction
,CertificationMetadata(..)
,WalletAddress
, getTransactionList
, CertificationMetadata(..)
, WalletAddress
, WalletTransaction(..)
) where

import Data.UUID
Expand All @@ -29,6 +31,7 @@ import Data.Text
import Data.Aeson.QQ
import Control.Monad.IO.Class
import IOHK.Certification.Persistence
import Plutus.Certification.WalletClient.Transaction

data TxBody = forall a . (ToJSON a) => TxBody
{ passphrase :: !Text
Expand Down Expand Up @@ -78,8 +81,9 @@ instance ToJSON TxResponse where
type API = "v2" :> "wallets"
:> Capture "wallet-id" Text
:> "transactions"
:> ReqBody '[JSON] TxBody
:> Verb 'POST 202 '[JSON] TxResponse
:>( ReqBody '[JSON] TxBody :> Verb 'POST 202 '[JSON] TxResponse
:<|> Get '[JSON] [WalletTransaction]
)

type WalletAddress = Text
data WalletArgs = WalletArgs
Expand All @@ -104,7 +108,7 @@ splitString :: Int -> Text -> Value
splitString maxChars = toValue . chunksOf maxChars
where
toValue [] = toJSON ("" :: Text)
toValue (x:[]) = toJSON x
toValue [x] = toJSON x
toValue xs = toJSON xs

split64 :: Text -> Value
Expand All @@ -117,19 +121,31 @@ instance ToJSON CertificationMetadata where
, "projectName" .= split64 crtmProjectName
, "contractLink" .= split64 (pack $ show crtmContractLink)
, "version" .= split64 crtmVersion
] ++ (maybe [] (\x -> [ "twitter" .= split64 x]) crtmTwitter)
++ (maybe [] (\x -> [ "link" .= (split64 . pack . showBaseUrl $ x )]) crtmLink)
] ++ maybe [] (\x -> [ "twitter" .= split64 x]) crtmTwitter
++ maybe [] (\x -> [ "link" .= (split64 . pack . showBaseUrl $ x )]) crtmLink

mkClient :: Text -> (TxBody -> ClientM TxResponse) :<|> ClientM [WalletTransaction]
mkClient = client (Proxy :: Proxy API)

mkSettings :: MonadIO m => BaseUrl -> m ClientEnv
mkSettings walletAPIAddress = liftIO $ do
manager' <- newManager (if baseUrlScheme walletAPIAddress == Https then tlsManagerSettings else defaultManagerSettings)
pure (mkClientEnv manager' walletAPIAddress)

broadcastTransaction :: (MonadIO m, ToJSON metadata)
=> WalletArgs
-> metadata
-> m (Either ClientError TxResponse)
broadcastTransaction WalletArgs{..} metadata = liftIO $ do
manager' <- newManager (if baseUrlScheme walletAPIAddress == Https then tlsManagerSettings else defaultManagerSettings)
let settings = (mkClientEnv manager' walletAPIAddress)
let broadcastTx = client (Proxy :: Proxy API)
settings <- mkSettings walletAPIAddress
let broadcastTx :<|> _ = mkClient walletId
let body = TxBody walletPassphrase walletAddress [aesonQQ| { "0": #{ metadata }} |]

runClientM (broadcastTx walletId body ) settings

runClientM (broadcastTx body ) settings

getTransactionList :: (MonadIO m)
=> WalletArgs
-> m (Either ClientError [WalletTransaction])
getTransactionList WalletArgs{..} = liftIO $ do
settings <- mkSettings walletAPIAddress
let _ :<|> getList = mkClient walletId
runClientM getList settings

0 comments on commit 3cf31c1

Please sign in to comment.