2020-10-02 18:10:32 +03:00
|
|
|
{-# LANGUAGE StrictData #-}
|
|
|
|
|
2020-10-27 15:04:31 +03:00
|
|
|
-- This is required due to the use of 'Void' in a constructor slot in
|
|
|
|
-- combination with 'deriveNoun' which generates an unreachable pattern.
|
|
|
|
{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
|
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
|
|
|
Event Types and Noun Conversion
|
|
|
|
-}
|
2020-01-24 08:28:38 +03:00
|
|
|
module Urbit.Arvo.Event where
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2020-12-19 04:00:56 +03:00
|
|
|
import Urbit.Prelude
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2020-10-27 15:22:33 +03:00
|
|
|
import Control.Monad.Fail (fail)
|
2020-12-03 21:41:03 +03:00
|
|
|
import Urbit.Arvo.Common (KingId(..), ServId(..), Vere(..))
|
2020-01-24 08:28:38 +03:00
|
|
|
import Urbit.Arvo.Common (Desk, Mime)
|
|
|
|
import Urbit.Arvo.Common (Header(..), HttpEvent)
|
|
|
|
import Urbit.Arvo.Common (AmesDest, Ipv4, Ipv6, Port, Turf)
|
|
|
|
import Urbit.Arvo.Common (ReOrg(..), reorgThroughNoun)
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
import qualified Crypto.Sign.Ed25519 as Ed
|
2019-09-25 03:15:00 +03:00
|
|
|
import qualified Data.ByteString as BS
|
2021-04-02 14:58:13 +03:00
|
|
|
import qualified Data.Char as C
|
2019-09-25 00:01:39 +03:00
|
|
|
import qualified Data.ByteString.Char8 as C
|
2019-08-02 09:56:42 +03:00
|
|
|
import qualified Network.HTTP.Types.Method as H
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
-- Misc Types ------------------------------------------------------------------
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-09-20 01:40:23 +03:00
|
|
|
type Rift = Atom -- Continuity number
|
2019-07-24 04:34:16 +03:00
|
|
|
type Life = Word -- Number of Azimoth key revs.
|
|
|
|
type Bloq = Atom -- TODO
|
2019-07-21 07:13:21 +03:00
|
|
|
type Oath = Atom -- Signature
|
|
|
|
|
2020-04-28 21:40:43 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
-- Parsed URLs -----------------------------------------------------------------
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-12-10 05:45:19 +03:00
|
|
|
type Host = Each Turf Ipv4
|
2019-07-21 07:36:25 +03:00
|
|
|
type Hart = (Bool, Maybe Atom, Host)
|
2019-07-22 21:10:27 +03:00
|
|
|
type Pork = (Maybe Knot, [Cord])
|
|
|
|
type Quay = [(Cord, Cord)]
|
2019-07-21 07:36:25 +03:00
|
|
|
|
2019-07-23 00:26:40 +03:00
|
|
|
data PUrl = PUrl Hart Pork Quay
|
2019-07-21 07:36:25 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''PUrl
|
|
|
|
|
|
|
|
|
|
|
|
-- Dawn Records ----------------------------------------------------------------
|
|
|
|
|
2019-09-25 03:15:00 +03:00
|
|
|
padByteString :: BS.ByteString -> Int -> BS.ByteString
|
|
|
|
padByteString bs length | remaining > 0 = bs <> (BS.replicate remaining 0)
|
|
|
|
| otherwise = bs
|
|
|
|
where remaining = (length - (BS.length bs))
|
|
|
|
|
2019-09-25 00:01:39 +03:00
|
|
|
-- A Pass is the Atom concatenation of 'b', the public encryption key, and the
|
|
|
|
-- public authentication key. (see +pass-from-eth.)
|
2019-09-26 00:26:51 +03:00
|
|
|
data Pass = Pass { passSign :: Ed.PublicKey, passCrypt :: Ed.PublicKey }
|
2019-07-21 07:13:21 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-10-09 23:39:11 +03:00
|
|
|
passToBS :: Pass -> BS.ByteString
|
|
|
|
passToBS Pass{..} = C.singleton 'b' <>
|
2019-10-10 00:58:27 +03:00
|
|
|
(Ed.unPublicKey passSign) <>
|
|
|
|
(Ed.unPublicKey passCrypt)
|
2019-10-09 23:39:11 +03:00
|
|
|
|
2019-09-25 00:01:39 +03:00
|
|
|
instance ToNoun Pass where
|
2020-01-23 12:22:30 +03:00
|
|
|
toNoun = Atom . bytesAtom . passToBS
|
2019-09-25 00:01:39 +03:00
|
|
|
|
|
|
|
instance FromNoun Pass where
|
|
|
|
parseNoun n = named "Pass" $ do
|
2019-09-25 03:15:00 +03:00
|
|
|
MkBytes unpadded <- parseNoun n
|
|
|
|
let bs = padByteString unpadded 65
|
|
|
|
when ((C.head bs) /= 'b') $ do
|
|
|
|
fail "Expecting 'b' prefix in public key structure"
|
2019-09-25 00:01:39 +03:00
|
|
|
let removedPrefix = C.tail bs
|
2019-09-26 00:26:51 +03:00
|
|
|
let passSign = Ed.PublicKey (take 32 removedPrefix)
|
|
|
|
let passCrypt = Ed.PublicKey (drop 32 removedPrefix)
|
2019-10-10 00:58:27 +03:00
|
|
|
unless ((length $ Ed.unPublicKey passSign) == 32) $
|
|
|
|
error "Sign pubkey not 32 bytes"
|
|
|
|
unless ((length $ Ed.unPublicKey passCrypt) == 32) $
|
|
|
|
error "Crypt pubkey not 32 bytes"
|
2019-09-25 03:15:00 +03:00
|
|
|
pure $ Pass{..}
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
-- A Ring isn't the secret keys: it's the ByteString input which generates both
|
|
|
|
-- the public key and the secret key. A Ring is the concatenation of 'B', the
|
|
|
|
-- encryption key derivation seed, and the authentication key derivation
|
|
|
|
-- seed. These aren't actually private keys, but public/private keypairs which
|
|
|
|
-- can be derived from these seeds.
|
2019-10-09 23:39:11 +03:00
|
|
|
data Ring = Ring { ringSign :: BS.ByteString, ringCrypt :: BS.ByteString }
|
2019-09-26 01:16:48 +03:00
|
|
|
deriving (Eq)
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-09-25 03:15:00 +03:00
|
|
|
instance ToNoun Ring where
|
|
|
|
toNoun Ring{..} =
|
2020-01-23 12:22:30 +03:00
|
|
|
Atom $ bytesAtom (C.singleton 'B' <> ringSign <> ringCrypt)
|
2019-09-25 03:15:00 +03:00
|
|
|
|
|
|
|
instance FromNoun Ring where
|
|
|
|
parseNoun n = named "Ring" $ do
|
|
|
|
MkBytes unpadded <- parseNoun n
|
|
|
|
let bs = padByteString unpadded 65
|
|
|
|
when ((C.head bs) /= 'B') $ do
|
|
|
|
fail "Expecting 'B' prefix in public key structure"
|
|
|
|
let removedPrefix = C.tail bs
|
2019-09-26 00:26:51 +03:00
|
|
|
let ringSign = (take 32 removedPrefix)
|
|
|
|
let ringCrypt = (drop 32 removedPrefix)
|
2019-10-10 00:58:27 +03:00
|
|
|
unless ((length ringSign) == 32) $
|
|
|
|
error "Sign seed not 32 bytes"
|
|
|
|
unless ((length ringCrypt) == 32) $
|
|
|
|
error "Crypt seed not 32 bytes"
|
2019-09-25 03:15:00 +03:00
|
|
|
pure $ Ring ringSign ringCrypt
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-09-26 01:16:48 +03:00
|
|
|
instance Show Ring where
|
|
|
|
show r = "(Ring <<seed>> <<seed>>)"
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-10-02 00:44:14 +03:00
|
|
|
data Seed = Seed
|
|
|
|
{ sShip :: Ship
|
|
|
|
, sLife :: Life
|
|
|
|
, sRing :: Ring
|
|
|
|
, sOath :: (Maybe Oath)
|
|
|
|
}
|
2019-09-25 03:15:00 +03:00
|
|
|
deriving (Eq, Show)
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-09-26 23:29:19 +03:00
|
|
|
type Public = (Life, HoonMap Life Pass)
|
2019-07-23 00:26:40 +03:00
|
|
|
|
|
|
|
data Dnses = Dnses { dPri::Cord, dSec::Cord, dTer::Cord }
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-09-21 02:10:03 +03:00
|
|
|
type EthAddr = Atom --Bytes -- 20 bytes
|
2019-07-23 00:26:40 +03:00
|
|
|
type ContNum = Word
|
|
|
|
|
|
|
|
data EthPoint = EthPoint
|
|
|
|
{ epOwn :: (EthAddr, EthAddr, EthAddr, EthAddr)
|
|
|
|
, epNet :: Maybe (Life, Pass, ContNum, (Bool, Ship), Maybe Ship)
|
2019-09-26 23:29:19 +03:00
|
|
|
, epKid :: Maybe (EthAddr, HoonSet Ship)
|
2019-07-23 00:26:40 +03:00
|
|
|
}
|
2019-09-25 00:01:39 +03:00
|
|
|
deriving (Eq, Show)
|
2019-07-23 00:26:40 +03:00
|
|
|
|
2019-07-21 04:29:39 +03:00
|
|
|
data Dawn = MkDawn
|
2019-09-21 02:10:03 +03:00
|
|
|
{ dSeed :: Seed
|
2019-10-04 01:51:34 +03:00
|
|
|
, dSponsor :: [(Ship, EthPoint)]
|
2019-09-27 20:30:26 +03:00
|
|
|
, dCzar :: HoonMap Ship (Rift, Life, Pass)
|
2019-09-21 02:10:03 +03:00
|
|
|
, dTurf :: [Turf]
|
|
|
|
, dBloq :: Bloq
|
|
|
|
, dNode :: (Maybe PUrl)
|
2019-07-21 04:29:39 +03:00
|
|
|
}
|
2019-09-25 00:01:39 +03:00
|
|
|
deriving (Eq, Show)
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-23 00:26:40 +03:00
|
|
|
deriveNoun ''Dnses
|
|
|
|
deriveNoun ''EthPoint
|
2019-07-21 07:36:25 +03:00
|
|
|
deriveNoun ''Seed
|
|
|
|
deriveNoun ''Dawn
|
2019-07-21 04:29:39 +03:00
|
|
|
|
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
-- HTTP ------------------------------------------------------------------------
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
type ServerId = Atom
|
|
|
|
|
|
|
|
data Address
|
2019-08-01 00:52:49 +03:00
|
|
|
= AIpv4 Ipv4
|
|
|
|
| AIpv6 Ipv6
|
2019-07-24 04:34:16 +03:00
|
|
|
| AAmes Ship
|
2019-07-21 04:29:39 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
data HttpRequest = HttpRequest
|
2019-08-02 09:56:42 +03:00
|
|
|
{ reqMeth :: H.StdMethod
|
2019-07-22 21:10:27 +03:00
|
|
|
, reqUrl :: Cord
|
2019-08-02 09:56:42 +03:00
|
|
|
, reqHead :: [Header]
|
2019-07-24 04:34:16 +03:00
|
|
|
, reqBody :: Maybe File
|
2019-07-21 04:29:39 +03:00
|
|
|
}
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-23 03:46:06 +03:00
|
|
|
data HttpServerReq = HttpServerReq
|
|
|
|
{ hsrSecure :: Bool
|
|
|
|
, hsrAddress :: Address
|
|
|
|
, hsrRequest :: HttpRequest
|
|
|
|
}
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data HttpClientEv
|
2019-08-02 08:07:20 +03:00
|
|
|
= HttpClientEvReceive (KingId, ()) ServerId HttpEvent
|
|
|
|
| HttpClientEvBorn (KingId, ()) ()
|
2020-04-28 21:40:43 +03:00
|
|
|
| HttpClientEvCrud Path Noun
|
2019-07-24 04:34:16 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
data HttpServerEv
|
2019-12-19 22:30:09 +03:00
|
|
|
= HttpServerEvRequest (ServId, UD, UD, ()) HttpServerReq
|
|
|
|
| HttpServerEvCancelRequest (ServId, UD, UD, ()) ()
|
|
|
|
| HttpServerEvRequestLocal (ServId, UD, UD, ()) HttpServerReq
|
2019-08-08 01:24:02 +03:00
|
|
|
| HttpServerEvLive (ServId, ()) Port (Maybe Port)
|
|
|
|
| HttpServerEvBorn (KingId, ()) ()
|
2020-04-28 21:40:43 +03:00
|
|
|
| HttpServerEvCrud Path Noun
|
2019-07-21 04:29:39 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
deriveNoun ''Address
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''HttpClientEv
|
2019-07-23 03:46:06 +03:00
|
|
|
deriveNoun ''HttpRequest
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''HttpServerEv
|
2019-07-23 03:46:06 +03:00
|
|
|
deriveNoun ''HttpServerReq
|
2019-07-21 04:29:39 +03:00
|
|
|
|
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
-- Ames ------------------------------------------------------------------------
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data AmesEv
|
2019-08-01 00:52:49 +03:00
|
|
|
= AmesEvHear () AmesDest Bytes
|
2019-12-10 05:45:19 +03:00
|
|
|
| AmesEvHole () AmesDest Bytes
|
2020-04-28 21:40:43 +03:00
|
|
|
| AmesEvCrud Path Noun
|
2019-07-21 04:29:39 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''AmesEv
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
-- Arvo Events -----------------------------------------------------------------
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2020-06-11 01:00:31 +03:00
|
|
|
newtype Entropy = Entropy { entropyBits :: Word512 }
|
|
|
|
deriving newtype (Eq, Ord, FromNoun, ToNoun)
|
|
|
|
|
|
|
|
instance Show Entropy where
|
|
|
|
show = const "\"ENTROPY (secret)\""
|
|
|
|
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data ArvoEv
|
2020-04-28 21:40:43 +03:00
|
|
|
= ArvoEvWhom () Ship
|
2020-06-11 01:00:31 +03:00
|
|
|
| ArvoEvWack () Entropy
|
2020-12-16 19:46:54 +03:00
|
|
|
| ArvoEvWyrd () Vere
|
2020-12-19 04:00:56 +03:00
|
|
|
| ArvoEvCrud Path Noun
|
|
|
|
| ArvoEvTrim UD
|
|
|
|
| ArvoEvWhat [Noun]
|
|
|
|
| ArvoEvWhey ()
|
|
|
|
| ArvoEvVerb (Maybe Bool)
|
2019-07-21 07:13:21 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''ArvoEv
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
-- Boat Events -----------------------------------------------------------------
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data BoatEv
|
2019-08-30 03:23:48 +03:00
|
|
|
= BoatEvBoat () ()
|
2020-04-28 21:40:43 +03:00
|
|
|
| BoatEvCrud Path Noun
|
2019-07-21 07:36:25 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''BoatEv
|
2019-07-21 07:13:21 +03:00
|
|
|
|
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
-- Timer Events ----------------------------------------------------------------
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data BehnEv
|
2019-08-30 03:23:48 +03:00
|
|
|
= BehnEvWake () ()
|
2019-08-08 01:24:02 +03:00
|
|
|
| BehnEvBorn (KingId, ()) ()
|
2020-04-28 21:40:43 +03:00
|
|
|
| BehnEvCrud Path Noun
|
2019-07-21 07:13:21 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''BehnEv
|
2019-07-21 07:13:21 +03:00
|
|
|
|
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
-- Newt Events -----------------------------------------------------------------
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data NewtEv
|
2019-12-10 05:45:19 +03:00
|
|
|
= NewtEvBorn (KingId, ()) ()
|
2020-04-28 21:40:43 +03:00
|
|
|
| NewtEvCrud Path Noun
|
2019-07-21 07:13:21 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''NewtEv
|
2019-07-21 07:36:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
-- FileSystem Events -----------------------------------------------------------
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data SyncEv
|
2019-09-10 23:14:43 +03:00
|
|
|
= SyncEvInto (Nullable (KingId, ())) Desk Bool [(Path, Maybe Mime)]
|
2020-04-28 21:40:43 +03:00
|
|
|
| SyncEvCrud Path Noun
|
2019-07-21 07:13:21 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''SyncEv
|
2019-07-21 07:36:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
-- Terminal Events -------------------------------------------------------------
|
|
|
|
|
|
|
|
data LegacyBootEvent
|
|
|
|
= Fake Ship
|
|
|
|
| Dawn Dawn
|
2019-09-25 00:01:39 +03:00
|
|
|
deriving (Eq, Show)
|
2019-07-21 07:36:25 +03:00
|
|
|
|
2021-04-02 14:58:13 +03:00
|
|
|
data Bolt
|
|
|
|
= Key Char
|
|
|
|
| Aro ArrowKey
|
2019-07-23 05:35:15 +03:00
|
|
|
| Bac ()
|
|
|
|
| Del ()
|
2021-04-02 14:58:13 +03:00
|
|
|
| Hit Word64 Word64
|
2019-07-23 05:35:15 +03:00
|
|
|
| Ret ()
|
2021-04-02 14:58:13 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
data Belt
|
|
|
|
= Bol Bolt
|
|
|
|
| Mod Modifier Bolt
|
2019-07-21 07:36:25 +03:00
|
|
|
| Txt Tour
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2021-04-02 14:58:13 +03:00
|
|
|
data ArrowKey = D | L | R | U
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
data Modifier = Ctl | Met | Hyp
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
--NOTE required to get the above declarations into reify's type environment
|
|
|
|
-- see also ghc/ghc#9813
|
|
|
|
$(pure [])
|
|
|
|
|
|
|
|
instance FromNoun Bolt where
|
|
|
|
parseNoun = \case
|
2021-06-17 21:23:38 +03:00
|
|
|
A c -> pure $ Key $ C.chr $ fromIntegral c
|
|
|
|
C (A 7955819) _ -> fail "%key not valid bolt tag"
|
|
|
|
n -> $(deriveFromNounFunc ''Bolt) n
|
2021-04-02 14:58:13 +03:00
|
|
|
|
|
|
|
instance FromNoun Belt where
|
2021-06-17 21:23:38 +03:00
|
|
|
parseNoun = \case
|
|
|
|
C (A 7106402) _ -> fail "%bol not valid belt tag"
|
|
|
|
n -> Bol <$> parseNoun n <|> $(deriveFromNounFunc ''Belt) n
|
2021-04-02 14:58:13 +03:00
|
|
|
|
|
|
|
instance ToNoun Bolt where
|
|
|
|
toNoun = \case
|
|
|
|
Key c -> A $ fromIntegral $ C.ord c
|
|
|
|
n -> $(deriveToNounFunc ''Bolt) n
|
|
|
|
|
|
|
|
instance ToNoun Belt where
|
|
|
|
toNoun = \case
|
2021-04-14 18:10:50 +03:00
|
|
|
Bol b -> toNoun b
|
2021-04-02 14:58:13 +03:00
|
|
|
n -> $(deriveToNounFunc ''Belt) n
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data TermEv
|
2019-08-29 03:08:47 +03:00
|
|
|
= TermEvBelt (UD, ()) Belt
|
|
|
|
| TermEvBlew (UD, ()) Word Word
|
2019-10-03 20:53:23 +03:00
|
|
|
| TermEvBoot (UD, ()) Bool LegacyBootEvent
|
2019-08-29 03:08:47 +03:00
|
|
|
| TermEvHail (UD, ()) ()
|
2020-04-28 21:40:43 +03:00
|
|
|
| TermEvCrud Path Noun
|
2019-09-25 00:01:39 +03:00
|
|
|
deriving (Eq, Show)
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
deriveNoun ''LegacyBootEvent
|
|
|
|
deriveNoun ''ArrowKey
|
2021-04-02 14:58:13 +03:00
|
|
|
deriveNoun ''Modifier
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''TermEv
|
2019-07-21 04:29:39 +03:00
|
|
|
|
2019-07-21 07:36:25 +03:00
|
|
|
|
|
|
|
-- Events for Device Drivers ---------------------------------------------------
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data BlipEv
|
|
|
|
= BlipEvAmes AmesEv
|
|
|
|
| BlipEvArvo ArvoEv
|
|
|
|
| BlipEvBehn BehnEv
|
|
|
|
| BlipEvBoat BoatEv
|
|
|
|
| BlipEvHttpClient HttpClientEv
|
|
|
|
| BlipEvHttpServer HttpServerEv
|
|
|
|
| BlipEvNewt NewtEv
|
|
|
|
| BlipEvSync SyncEv
|
|
|
|
| BlipEvTerm TermEv
|
2019-09-25 00:01:39 +03:00
|
|
|
deriving (Eq, Show)
|
2019-07-21 07:13:21 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
deriveNoun ''BlipEv
|
2019-07-21 07:36:25 +03:00
|
|
|
|
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
-- The Main Event Type ---------------------------------------------------------
|
2019-07-21 07:36:25 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
data Ev
|
2019-07-24 07:03:04 +03:00
|
|
|
= EvBlip BlipEv
|
2019-09-25 00:01:39 +03:00
|
|
|
deriving (Eq, Show)
|
2019-07-21 07:36:25 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
instance ToNoun Ev where
|
2020-12-11 04:56:56 +03:00
|
|
|
toNoun = toNoun . \case
|
|
|
|
EvBlip v@BlipEvAmes{} -> reorgThroughNoun ("ames", v)
|
|
|
|
EvBlip v@BlipEvArvo{} -> reorgThroughNoun ("", v)
|
|
|
|
EvBlip v@BlipEvBehn{} -> reorgThroughNoun ("behn", v)
|
|
|
|
EvBlip v@BlipEvBoat{} -> reorgThroughNoun ("clay", v)
|
|
|
|
EvBlip v@BlipEvHttpClient{} -> reorgThroughNoun ("iris", v)
|
|
|
|
EvBlip v@BlipEvHttpServer{} -> reorgThroughNoun ("eyre", v)
|
|
|
|
EvBlip v@BlipEvNewt{} -> reorgThroughNoun ("ames", v)
|
|
|
|
EvBlip v@BlipEvSync{} -> reorgThroughNoun ("clay", v)
|
|
|
|
EvBlip v@BlipEvTerm{} -> reorgThroughNoun ("dill", v)
|
|
|
|
|
|
|
|
-- XX We really should check the first path element, but since this is used only
|
|
|
|
-- in the event browser, which otherwise is broken, I don't care right now.
|
2019-07-24 07:03:04 +03:00
|
|
|
instance FromNoun Ev where
|
|
|
|
parseNoun = parseNoun >=> \case
|
2020-12-11 04:56:56 +03:00
|
|
|
ReOrg _ s t p v -> fmap EvBlip $ parseNoun $ toNoun (s,t,p,v)
|
2019-09-16 23:34:55 +03:00
|
|
|
|
2020-06-10 22:22:45 +03:00
|
|
|
|
2019-09-16 23:34:55 +03:00
|
|
|
-- Short Event Names -----------------------------------------------------------
|
|
|
|
|
2019-09-18 07:41:31 +03:00
|
|
|
{-
|
2021-04-14 21:35:17 +03:00
|
|
|
In the case of user input, the cause is technically a terminal event,
|
|
|
|
but we don't display any name because the cause is really the user.
|
2019-09-18 07:41:31 +03:00
|
|
|
-}
|
|
|
|
getSpinnerNameForEvent :: Ev -> Maybe Text
|
2019-09-16 23:34:55 +03:00
|
|
|
getSpinnerNameForEvent = \case
|
2019-09-18 07:41:31 +03:00
|
|
|
EvBlip b -> case b of
|
2021-06-17 21:34:14 +03:00
|
|
|
BlipEvAmes _ -> Just "ames"
|
|
|
|
BlipEvArvo _ -> Just "arvo"
|
|
|
|
BlipEvBehn _ -> Just "behn"
|
|
|
|
BlipEvBoat _ -> Just "boat"
|
|
|
|
BlipEvHttpClient _ -> Just "iris"
|
|
|
|
BlipEvHttpServer _ -> Just "eyre"
|
|
|
|
BlipEvNewt _ -> Just "newt"
|
|
|
|
BlipEvSync _ -> Just "clay"
|
|
|
|
BlipEvTerm (TermEvBelt _ _) -> Nothing
|
|
|
|
BlipEvTerm t -> Just "term"
|
2020-06-11 05:02:09 +03:00
|
|
|
|
|
|
|
summarizeEvent :: Ev -> Text
|
|
|
|
summarizeEvent ev =
|
|
|
|
fromNoun (toNoun ev) & \case
|
|
|
|
Nothing -> "//invalid %event"
|
|
|
|
Just (pax :: [Cord], tag :: Cord, val :: Noun) ->
|
|
|
|
"/" <> intercalate "/" (unCord <$> pax) <> " %" <> unCord tag
|