-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
87 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
module Spammer.Db (executeQuery, KeysRow) where | ||
module Spammer.Db (executeQuery) where | ||
|
||
import Contract.Prelude | ||
|
||
import Control.Promise (Promise, toAffE) | ||
import Data.Argonaut (Json) | ||
import Effect (Effect) | ||
import Effect.Aff (Aff) | ||
import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff) | ||
|
||
type KeysRow = {pkey :: String, pubkey :: String} | ||
type Query = String | ||
|
||
foreign import _executeQuery :: String -> EffectFnAff (Array KeysRow) | ||
foreign import _executeQuery :: Query -> EffectFnAff Json | ||
|
||
executeQuery :: String -> Aff (Array KeysRow) | ||
executeQuery :: Query -> Aff Json | ||
executeQuery = fromEffectFnAff <<< _executeQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Spammer.Start (startSpammer) where | ||
|
||
import Contract.Prelude | ||
|
||
import Aeson (JsonDecodeError) | ||
import Contract.Monad (launchAff_) | ||
import Data.Argonaut (class DecodeJson, decodeJson, parseJson, printJsonDecodeError) | ||
import Data.String (drop) | ||
import Effect.Exception (throw) | ||
import Node.Encoding (Encoding(..)) | ||
import Node.FS.Sync (readTextFile) | ||
import Spammer.Db (executeQuery) | ||
import Spammer.Types (KeyFile, CborHex) | ||
|
||
|
||
|
||
startSpammer :: Effect Unit | ||
startSpammer = do | ||
loadGenesisUtxoKeysDb | ||
|
||
loadGenesisUtxoKeysDb :: Effect Unit | ||
loadGenesisUtxoKeysDb = do | ||
let | ||
dir = "/home/maxim/work/projects/congested-testnet/cardano-conf/utxo-keys/" | ||
utxo1_skey_file<- readTextFile UTF8 (dir <> "utxo1.skey") | ||
utxo1_pkey_file <- readTextFile UTF8 (dir <> "utxo1.vkey") | ||
utxo2_skey_file <- readTextFile UTF8 (dir <> "utxo2.skey") | ||
utxo2_pkey_file <- readTextFile UTF8 (dir <> "utxo2.vkey") | ||
utxo1_skey_hex <- liftJsonDecodeError (parseKeyFromJsonString utxo1_skey_file) | ||
utxo1_pkey_hex <- liftJsonDecodeError (parseKeyFromJsonString utxo1_pkey_file) | ||
utxo2_skey_hex <- liftJsonDecodeError (parseKeyFromJsonString utxo2_skey_file) | ||
utxo2_pkey_hex <- liftJsonDecodeError (parseKeyFromJsonString utxo2_pkey_file) | ||
let | ||
query = "INSERT INTO pkeys (pkey, pubkey) VALUES " <> | ||
"('" <> utxo1_skey_hex <> "', '" <> utxo1_pkey_hex <> "'), " <> | ||
"('" <> utxo2_skey_hex <> "', '" <> utxo2_pkey_hex <> "') " <> | ||
"ON CONFLICT (pkey) DO NOTHING;" | ||
launchAff_ do | ||
executeQuery query | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
parseKeyFromJsonString :: String -> Either JsonDecodeError CborHex | ||
parseKeyFromJsonString jsonString = do | ||
keyFile :: KeyFile <- parseJson jsonString >>= decodeJson | ||
let | ||
cborHex = keyFile.cborHex | ||
cborHexWithoutHeader = drop 4 cborHex | ||
pure cborHexWithoutHeader | ||
|
||
|
||
liftJsonDecodeError :: forall a. DecodeJson a => Either JsonDecodeError a -> Effect a | ||
liftJsonDecodeError eitherErrA = do | ||
case eitherErrA of | ||
Left e -> throw $ printJsonDecodeError e | ||
Right x -> pure x | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Spammer.Types where | ||
|
||
-- | Typical key file format | ||
type KeyFile = { | ||
type :: String, | ||
description :: String, | ||
cborHex :: String | ||
} | ||
|
||
type CborHex = String |