-
Notifications
You must be signed in to change notification settings - Fork 463
/
Effects.hs
89 lines (82 loc) · 2.92 KB
/
Effects.hs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Wallet.Effects(
WalletEffects
-- * Wallet effect
, WalletEffect(..)
, Payment(..)
, submitTxn
, ownPubKey
, updatePaymentWithChange
, walletSlot
, ownOutputs
, walletAddSignature
-- * Node client
, NodeClientEffect(..)
, publishTx
, getClientSlot
-- * Chain index
, ChainIndexEffect(..)
, AddressChangeRequest(..)
, AddressChangeResponse(..)
, startWatching
, watchedAddresses
, confirmedBlocks
, transactionConfirmed
, nextTx
-- * Contract runtime
, ContractRuntimeEffect(..)
, sendNotification
) where
import Control.Monad.Freer.TH (makeEffect)
import Ledger (Address, PubKey, Slot, Tx, TxId, Value)
import Ledger.AddressMap (AddressMap, UtxoMap)
import Wallet.Types (AddressChangeRequest (..), AddressChangeResponse (..), Notification,
NotificationError, Payment (..))
data WalletEffect r where
SubmitTxn :: Tx -> WalletEffect ()
OwnPubKey :: WalletEffect PubKey
UpdatePaymentWithChange :: Value -> Payment -> WalletEffect Payment
WalletSlot :: WalletEffect Slot
OwnOutputs :: WalletEffect UtxoMap
WalletAddSignature :: Tx -> WalletEffect Tx
makeEffect ''WalletEffect
data NodeClientEffect r where
PublishTx :: Tx -> NodeClientEffect ()
GetClientSlot :: NodeClientEffect Slot
makeEffect ''NodeClientEffect
{-| Access the chain index. The chain index keeps track of the
datums that are associated with unspent transaction outputs. Addresses that
are of interest need to be added with 'startWatching' before their outputs
show up in the 'AddressMap' returned by 'watchedAddresses'.
-}
data ChainIndexEffect r where
StartWatching :: Address -> ChainIndexEffect ()
WatchedAddresses :: ChainIndexEffect AddressMap
ConfirmedBlocks :: ChainIndexEffect [[Tx]]
-- TODO: In the future we should have degrees of confirmation
TransactionConfirmed :: TxId -> ChainIndexEffect Bool
NextTx :: AddressChangeRequest -> ChainIndexEffect AddressChangeResponse
makeEffect ''ChainIndexEffect
{-| Interact with other contracts.
-}
data ContractRuntimeEffect r where
SendNotification :: Notification -> ContractRuntimeEffect (Maybe NotificationError)
makeEffect ''ContractRuntimeEffect
-- | Effects that allow contracts to interact with the blockchain
type WalletEffects =
'[ WalletEffect
, NodeClientEffect
, ChainIndexEffect
, ContractRuntimeEffect
]