-
Notifications
You must be signed in to change notification settings - Fork 463
/
Validation.purs
28 lines (22 loc) · 1.14 KB
/
Validation.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Action.Validation (actionIsValid) where
import Data.Array as Array
import Data.Lens (view)
import Playground.Types (ContractCall(..), SimulatorWallet)
import Prelude ((==), (&&), (<<<))
import Schema.Types (FormArgument)
import Validation (isValid)
import Wallet.Emulator.Wallet (Wallet)
import Wallet.Lenses (_simulatorWalletWallet, _walletId)
actionIsValid :: Array SimulatorWallet -> ContractCall FormArgument -> Boolean
actionIsValid simulatorWallets simulatorAction = actionWalletsExist simulatorAction && isValid simulatorAction
where
walletExists :: Wallet -> Boolean
walletExists wallet =
Array.any
(\simulatorWallet -> view _walletId wallet == view (_simulatorWalletWallet <<< _walletId) simulatorWallet)
simulatorWallets
actionWalletsExist :: ContractCall FormArgument -> Boolean
actionWalletsExist (AddBlocks _) = true -- because there is no wallet to check for in the first place
actionWalletsExist (AddBlocksUntil _) = true -- ditto
actionWalletsExist (CallEndpoint a@{ caller }) = walletExists caller
actionWalletsExist (PayToWallet a@{ sender, recipient }) = walletExists sender && walletExists recipient