-
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
7 changed files
with
92 additions
and
53 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
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,27 +1,62 @@ | ||
module Spammer.Query.Wallet where | ||
module Spammer.Query.Wallet (getWallet', updateWalletBalanceDb) where | ||
|
||
import Contract.Prelude | ||
|
||
import Contract.Monad (Contract, liftContractAffM) | ||
import Contract.Wallet (KeyWallet, PrivatePaymentKey(..), privateKeysToKeyWallet) | ||
import Contract.Wallet.Key (keyWalletPrivatePaymentKey) | ||
import Control.Monad.Error.Class (liftMaybe) | ||
import Data.Argonaut (decodeJson) | ||
import Data.Array (head) | ||
import Effect.Exception (error) | ||
import Spammer.Db (executeQuery) | ||
import Spammer.Keys (getPrivateKeyFromHex) | ||
import Spammer.Utils (liftJsonDecodeError) | ||
import Spammer.Keys (genPrivateKey, getPrivateKeyFromHex, getPrivateKeyHex, getPubKeyHex) | ||
import Spammer.Utils (liftJsonDecodeError, quotes) | ||
|
||
type Result = Array | ||
type PrivKeyQueryResult = Array | ||
{ pkey :: String | ||
} | ||
|
||
getWallet' :: Aff KeyWallet | ||
getWallet' = do | ||
json <- executeQuery "SELECT pkey FROM pkeys LIMIT 1;" | ||
result :: Result <- liftEffect $ liftJsonDecodeError (decodeJson json) | ||
getWallet' :: Maybe KeyWallet -> Contract KeyWallet | ||
getWallet' previousWalletWithError = liftContractAffM "cannot get keyWallet" do | ||
query' <- query previousWalletWithError | ||
json <- executeQuery query' | ||
result :: PrivKeyQueryResult <- liftEffect $ liftJsonDecodeError (decodeJson json) | ||
res <- liftMaybe (error "empty array in getWallet'") $ head result | ||
let | ||
pkey = PrivatePaymentKey (getPrivateKeyFromHex res.pkey) | ||
keyWallet = privateKeysToKeyWallet pkey Nothing | ||
pure keyWallet | ||
pure <<< pure $ keyWallet | ||
|
||
query :: Maybe KeyWallet -> Aff String | ||
query previousWalletWithError = liftEffect do | ||
case previousWalletWithError of | ||
Just keyWallet -> do | ||
newPrivKey <- genPrivateKey | ||
let | ||
newPrivKeyHex = getPrivateKeyHex newPrivKey | ||
newPubKeyHex = getPubKeyHex newPrivKey | ||
prevPrivateKey = unwrap $ keyWalletPrivatePaymentKey keyWallet | ||
prevPrivateKeyHex = getPrivateKeyHex prevPrivateKey | ||
|
||
insertNewKeyDb = "INSERT INTO pkeys (pkey, pubkey, balance) VALUES " | ||
<> "( " | ||
<> quotes newPrivKeyHex | ||
<> "," | ||
<> quotes newPubKeyHex | ||
<> ",0); " | ||
|
||
selectKey = "SELECT pkey FROM pkeys " | ||
<> " WHERE pkey != " | ||
<> | ||
quotes prevPrivateKeyHex | ||
<> | ||
" ORDER BY balance DESC LIMIT 1;" | ||
|
||
pure $ insertNewKeyDb <> selectKey | ||
|
||
Nothing -> pure $ "SELECT pkey FROM pkeys ORDER BY balance DESC LIMIT 1;" | ||
|
||
updateWalletBalanceDb :: KeyWallet -> Contract Unit | ||
updateWalletBalanceDb keyWallet = do | ||
pure unit |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
nix run .#runnet start | ||
sleep 1 | ||
nix run .#first-transaction | ||
ogmios --host 0.0.0.0 --node-socket cardano-conf/sockets/node-relay-1-socket/node.socket --node-config cardano-conf/configuration.yaml | ||
|
||
|