logging requests and shell scripts to curl endpoints

This commit is contained in:
Lars Brünjes 2021-06-09 21:36:09 +02:00
parent 67daacefb5
commit 79e6ab5a33
No known key found for this signature in database
GPG key ID: B488B9045DC1A087
10 changed files with 61 additions and 1 deletions

9
code/week10/add.sh Executable file
View file

@ -0,0 +1,9 @@
#1/bin/sh
symbol=$( cat symbol.json )
body="{\"apAmountA\":$2,\"apAmountB\":$4,\"apCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$5\"}]},\"apCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}"
echo $body
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/add" \
--header 'Content-Type: application/json' \
--data-raw $body

View file

@ -10,7 +10,8 @@ import Control.Concurrent
import Control.Exception import Control.Exception
import Control.Monad (forM_, when) import Control.Monad (forM_, when)
import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.IO.Class (MonadIO (..))
import Data.Aeson (Result (..), ToJSON, decode, fromJSON) import Data.Aeson (Result (..), ToJSON, decode, encode, fromJSON)
import qualified Data.ByteString.Lazy.Char8 as B8
import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy as LB
import Data.Monoid (Last (..)) import Data.Monoid (Last (..))
import Data.Proxy (Proxy (..)) import Data.Proxy (Proxy (..))
@ -212,6 +213,8 @@ getStatus cid = runReq defaultHttpConfig $ do
callEndpoint :: ToJSON a => UUID -> String -> a -> IO () callEndpoint :: ToJSON a => UUID -> String -> a -> IO ()
callEndpoint cid name a = handle h $ runReq defaultHttpConfig $ do callEndpoint cid name a = handle h $ runReq defaultHttpConfig $ do
liftIO $ printf "\npost request to 127.0.1:8080/api/new/contract/instance/%s/endpoint/%s\n" (show cid) name
liftIO $ printf "request body: %s\n\n" $ B8.unpack $ encode a
v <- req v <- req
POST POST
(http "127.0.0.1" /: "api" /: "new" /: "contract" /: "instance" /: pack (show cid) /: "endpoint" /: pack name) (http "127.0.0.1" /: "api" /: "new" /: "contract" /: "instance" /: pack (show cid) /: "endpoint" /: pack name)

9
code/week10/close.sh Executable file
View file

@ -0,0 +1,9 @@
#1/bin/sh
symbol=$( cat symbol.json )
body="{\"clpCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]},\"clpCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$2\"}]}}"
echo $body
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/close" \
--header 'Content-Type: application/json' \
--data-raw $body

9
code/week10/create.sh Executable file
View file

@ -0,0 +1,9 @@
#1/bin/sh
symbol=$( cat symbol.json )
body="{\"cpAmountA\":$2,\"cpAmountB\":$4,\"cpCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$5\"}]},\"cpCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}"
echo $body
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/create" \
--header 'Content-Type: application/json' \
--data-raw $body

4
code/week10/funds.sh Executable file
View file

@ -0,0 +1,4 @@
#1/bin/sh
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/funds" \
--header 'Content-Type: application/json' \
--data-raw '[]'

2
code/week10/logs.sh Executable file
View file

@ -0,0 +1,2 @@
#1/bin/sh
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/status" | jq ".cicCurrentState.logs"

4
code/week10/pools.sh Executable file
View file

@ -0,0 +1,4 @@
#1/bin/sh
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/pools" \
--header 'Content-Type: application/json' \
--data-raw '[]'

9
code/week10/remove.sh Executable file
View file

@ -0,0 +1,9 @@
#1/bin/sh
symbol=$( cat symbol.json )
body="{\"rpCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$4\"}]},\"rpDiff\":$2,\"rpCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}"
echo $body
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/remove" \
--header 'Content-Type: application/json' \
--data-raw $body

2
code/week10/status.sh Executable file
View file

@ -0,0 +1,2 @@
#1/bin/sh
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/status" | jq ".cicCurrentState.observableState"

9
code/week10/swap.sh Executable file
View file

@ -0,0 +1,9 @@
#1/bin/sh
symbol=$( cat symbol.json )
body="{\"spAmountA\":$2,\"spAmountB\":0,\"spCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$4\"}]},\"spCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}"
echo $body
curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/swap" \
--header 'Content-Type: application/json' \
--data-raw $body