-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nameservice interact #168
Nameservice interact #168
Changes from all commits
243d621
2b4f8f2
f66e856
2a6b3c3
5eca207
b1e7680
ffa8c9a
7c00708
12d2319
e17127d
05bfd1d
e04471e
74b2788
776d1ed
04270a7
298656f
eba7e74
77192d7
a8c3dca
bff75c4
9aee76f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
module Interact | ||
( genNames | ||
, genVals | ||
, createNames | ||
, buyNames | ||
, setNames | ||
, deleteNames | ||
, faucetAccount | ||
, user1 | ||
, user2 | ||
) where | ||
|
||
import Data.String (fromString) | ||
import Data.String.Conversions (cs) | ||
import Data.Text (Text) | ||
import qualified Faker.Lorem as Lorem | ||
import qualified Faker.Name as Name | ||
import Nameservice.Modules.Nameservice (BuyName (..), | ||
DeleteName (..), Name (..), | ||
SetName (..)) | ||
import Nameservice.Modules.Token (Amount (..), | ||
FaucetAccount (..)) | ||
import Nameservice.Modules.TypedMessage (TypedMessage (..)) | ||
import Tendermint.SDK.Codec (HasCodec (..)) | ||
import Tendermint.Utils.Request (runTransaction_) | ||
import Tendermint.Utils.User (User (..), makeUser, mkSignedRawTransactionWithRoute) | ||
-------------------------------------------------------------------------------- | ||
-- Users | ||
-------------------------------------------------------------------------------- | ||
|
||
user1 :: User | ||
user1 = makeUser "f65255094d7773ed8dd417badc9fc045c1f80fdc5b2d25172b031ce6933e039a" | ||
|
||
user2 :: User | ||
user2 = makeUser "f65242094d7773ed8dd417badc9fc045c1f80fdc5b2d25172b031ce6933e039a" | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Actions | ||
-------------------------------------------------------------------------------- | ||
|
||
genNames :: Int -> IO [Name] | ||
genNames 0 = return [] | ||
genNames x = do | ||
genName <- Name.name | ||
let aName = fromString genName | ||
names <- genNames (x - 1) | ||
return (aName:names) | ||
|
||
genVals :: Int -> IO [Text] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. genVals = replicateM (fmap cs Lorem.word) |
||
genVals 0 = return [] | ||
genVals x = do | ||
genVal <- Lorem.word | ||
vals <- genVals (x - 1) | ||
return (cs genVal:vals) | ||
|
||
createName :: User -> Name -> Text -> IO () | ||
createName user name val = buyName user name val 0 | ||
|
||
createNames :: User -> [(Name, Text)] -> IO () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createNames user = mapM_ (uncurry . createName user) |
||
createNames _ [] = return () | ||
createNames user ((name, val):rst) = do | ||
createName user name val | ||
createNames user rst | ||
|
||
buyName :: User -> Name -> Text -> Amount -> IO () | ||
buyName User{userAddress, userPrivKey} name newVal amount = | ||
let msg = TypedMessage "BuyName" (encode $ BuyName amount name newVal userAddress) | ||
rawTx = mkSignedRawTransactionWithRoute "nameservice" userPrivKey msg | ||
in runTransaction_ rawTx | ||
|
||
buyNames :: User -> [(Name, Text, Amount)] -> IO () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. buyNames user = mapM_ (uncurry . buyName user) |
||
buyNames _ [] = return () | ||
buyNames user ((name, val, amt):rst) = do | ||
buyName user name val amt | ||
buyNames user rst | ||
|
||
deleteName :: User -> Name -> IO () | ||
deleteName User{userAddress, userPrivKey} name = | ||
let msg = TypedMessage "DeleteName" (encode $ DeleteName userAddress name) | ||
rawTx = mkSignedRawTransactionWithRoute "nameservice" userPrivKey msg | ||
in runTransaction_ rawTx | ||
|
||
deleteNames :: User -> [Name] -> IO () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createNames user = mapM_ (uncurry . deleteName user) |
||
deleteNames _ [] = return () | ||
deleteNames user (name:names) = do | ||
deleteName user name | ||
deleteNames user names | ||
|
||
setName :: User -> Name -> Text -> IO () | ||
setName User{userAddress, userPrivKey} name val = | ||
let msg = TypedMessage "SetName" (encode $ SetName name userAddress val) | ||
rawTx = mkSignedRawTransactionWithRoute "nameservice" userPrivKey msg | ||
in runTransaction_ rawTx | ||
|
||
setNames :: User -> [(Name, Text)] -> IO () | ||
setNames _ [] = return () | ||
setNames user ((name, val):rst) = do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createNames user = mapM_ (uncurry . setName user) |
||
setName user name val | ||
setNames user rst | ||
|
||
faucetAccount :: User -> Amount -> IO () | ||
faucetAccount User{userAddress, userPrivKey} amount = | ||
let msg = TypedMessage "FaucetAccount" (encode $ FaucetAccount userAddress amount) | ||
rawTx = mkSignedRawTransactionWithRoute "token" userPrivKey msg | ||
in runTransaction_ rawTx |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Main where | ||
|
||
import Control.Monad (forever) | ||
import Data.Maybe (maybe) | ||
import Interact | ||
import System.Environment (lookupEnv) | ||
import Text.Read (read) | ||
|
||
main :: IO () | ||
main = do | ||
mConc <- lookupEnv "TX_COUNT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is mConc? use a variable name that's more transparent |
||
let conc = maybe 1 read mConc | ||
putStrLn $ "Running nameservice interaction w/ TX_COUNT: " <> show conc | ||
faucetAccount user1 10000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should faucet inside the loop |
||
faucetAccount user2 10000 | ||
forever $ do | ||
names <- genNames conc | ||
vals <- genVals conc | ||
buyVals <- genVals conc | ||
let buyAmts = replicate conc 10 | ||
setVals <- genVals conc | ||
createNames user1 (zip names vals) | ||
buyNames user2 (zip3 names buyVals buyAmts) | ||
setNames user2 (zip names setVals) | ||
deleteNames user2 names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
genNames = replicateM (fmap fromString genName)