-
Notifications
You must be signed in to change notification settings - Fork 44
/
State.purs
598 lines (570 loc) · 23.9 KB
/
State.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
module Page.Dashboard.State
( handleAction
, mkInitialState
) where
import Prologue
import Bridge (toFront)
import Capability.Contract (class ManageContract)
import Capability.MainFrameLoop (class MainFrameLoop, callMainFrameAction)
import Capability.Marlowe
( class ManageMarlowe
, createContract
, createPendingFollowerApp
, followContract
, followContractWithPendingFollowerApp
, redeem
, subscribeToPlutusApp
)
import Capability.MarloweStorage
( class ManageMarloweStorage
, insertIntoContractNicknames
)
import Capability.Toast (class Toast, addToast)
import Capability.Wallet (class ManageWallet, getWalletTotalFunds)
import Clipboard (class MonadClipboard)
import Clipboard (handleAction) as Clipboard
import Component.Contacts.Lenses
( _assets
, _cardSection
, _walletId
, _walletInfo
, _walletNickname
)
import Component.Contacts.State (getAda)
import Component.Contacts.State (handleAction, initialState) as Contacts
import Component.Contacts.Types (Action(..), State) as Contacts
import Component.Contacts.Types (CardSection(..), WalletDetails)
import Component.InputField.Lenses (_value)
import Component.InputField.Types (Action(..)) as InputField
import Component.LoadingSubmitButton.Types (Query(..), _submitButtonSlot)
import Component.Template.Lenses
( _contractNicknameInput
, _contractSetupStage
, _contractTemplate
, _roleWalletInputs
)
import Component.Template.State (dummyState, handleAction, initialState) as Template
import Component.Template.State (instantiateExtendedContract)
import Component.Template.Types (Action(..), State) as Template
import Component.Template.Types (ContractSetupStage(..))
import Control.Monad.Reader (class MonadAsk)
import Data.AddressBook as AB
import Data.Array (null)
import Data.Either (hush)
import Data.Filterable (filterMap)
import Data.Foldable (for_)
import Data.Lens
( _Just
, assign
, elemOf
, filtered
, modifying
, set
, use
, view
, (^.)
)
import Data.Lens.At (at)
import Data.Lens.Extra (peruse)
import Data.Lens.Index (ix)
import Data.Lens.Traversal (traversed)
import Data.List (filter, fromFoldable) as List
import Data.Map
( Map
, filterKeys
, findMin
, insert
, lookup
, mapMaybe
, mapMaybeWithKey
, toUnfoldable
)
import Data.Maybe (fromMaybe)
import Data.Set (delete, fromFoldable, isEmpty) as Set
import Data.Time.Duration (Milliseconds(..))
import Data.Traversable (for)
import Data.Tuple.Nested ((/\))
import Data.WalletNickname as WN
import Effect.Aff.Class (class MonadAff)
import Env (Env)
import Halogen (HalogenM, modify_, tell)
import Halogen.Extra (mapMaybeSubmodule, mapSubmodule)
import MainFrame.Types (Action(..)) as MainFrame
import MainFrame.Types (ChildSlots, Msg)
import Marlowe.Client (ContractHistory, _chHistory, _chParams)
import Marlowe.Deinstantiate (findTemplate)
import Marlowe.Execution.State (getAllPayments)
import Marlowe.Extended.Metadata (_metaData)
import Marlowe.PAB (PlutusAppId, transactionFee)
import Marlowe.Run.Wallet.V1 (GetTotalFundsResponse(..))
import Marlowe.Semantics
( MarloweData
, MarloweParams
, Party(..)
, Payee(..)
, Payment(..)
, Slot
, _marloweContract
)
import Page.Contract.Lenses (_Started, _marloweParams, _selectedStep)
import Page.Contract.State (applyTimeout)
import Page.Contract.State
( dummyState
, handleAction
, mkInitialState
, mkPlaceholderState
, updateState
) as Contract
import Page.Contract.Types (Action(..), StartingState, State(..)) as Contract
import Page.Dashboard.Lenses
( _card
, _cardOpen
, _contactsState
, _contract
, _contractFilter
, _contracts
, _menuOpen
, _selectedContract
, _selectedContractFollowerAppId
, _templateState
, _walletCompanionStatus
, _walletDetails
)
import Page.Dashboard.Types
( Action(..)
, Card(..)
, ContractFilter(..)
, Input
, State
, WalletCompanionStatus(..)
)
import Toast.Types
( ajaxErrorToast
, decodedAjaxErrorToast
, errorToast
, successToast
)
{- [Workflow 2][4] Connect a wallet
When we connect a wallet, it has this initial state. Notable is the walletCompanionStatus of
`FirstUpdatePending`. Follow the trail of worflow comments to see what happens next.
-}
mkInitialState
:: WalletDetails
-> Map PlutusAppId ContractHistory
-> Map PlutusAppId String
-> Slot
-> State
mkInitialState walletDetails contracts contractNicknames currentSlot =
let
mkInitialContractState followerAppId contractHistory =
let
nickname = fromMaybe mempty $ lookup followerAppId contractNicknames
in
Contract.mkInitialState walletDetails currentSlot nickname
contractHistory
in
{ contactsState: Contacts.initialState
, walletDetails
, walletCompanionStatus: FirstUpdatePending
, menuOpen: false
, card: Nothing
, cardOpen: false
, contracts: mapMaybeWithKey mkInitialContractState contracts
, contractFilter: Running
, selectedContractFollowerAppId: Nothing
, templateState: Template.dummyState
}
handleAction
:: forall m
. MonadAff m
=> MonadAsk Env m
=> MainFrameLoop m
=> ManageContract m
=> ManageMarloweStorage m
=> ManageMarlowe m
=> Toast m
=> MonadClipboard m
=> Input
-> Action
-> HalogenM State Action ChildSlots Msg m Unit
{- [Workflow 3][0] Disconnect a wallet -}
handleAction _ DisconnectWallet = do
walletDetails <- use _walletDetails
contracts <- use _contracts
callMainFrameAction $ MainFrame.EnterWelcomeState walletDetails contracts
handleAction { addressBook } (ContactsAction contactsAction) =
case contactsAction of
Contacts.CancelNewContactForRole -> assign _card $ Just ContractTemplateCard
_ -> toContacts $ Contacts.handleAction addressBook contactsAction
handleAction _ ToggleMenu = modifying _menuOpen not
handleAction _ (ClipboardAction action) = do
Clipboard.handleAction action
addToast $ successToast "Copied to clipboard"
handleAction _ (OpenCard card) = do
-- Most cards requires to show the assets of the current wallet, so we update the funds
-- before opening a card.
-- See note [polling updateTotalFunds]
updateTotalFunds
-- Then we set the card and reset the contact and template card states to their first section
-- (we could check the card and only reset if relevant, but it doesn't seem worth the bother)
modify_
$ set _card (Just card)
<<< set (_contactsState <<< _cardSection) Home
<<< set (_templateState <<< _contractSetupStage) Start
-- then we set the card to open (and close the mobile menu) in a separate `modify_`, so that the
-- CSS transition animation works
modify_
$ set _cardOpen true
<<< set _menuOpen false
handleAction _ CloseCard = assign _cardOpen false
handleAction _ (SetContractFilter contractFilter) = assign _contractFilter
contractFilter
handleAction _ (SelectContract mFollowerAppId) = assign
_selectedContractFollowerAppId
mFollowerAppId
{- [Workflow 2][6] Connect a wallet
If we have just connected a wallet (and the walletCompanionStatus is still `FirstUpdatePending`),
then we know the `MarloweFollower` apps that are running in this wallet, and have just been given
the current state of its `WalletCompanion` app for the first time since connecting. If the status
of the `WalletCompanion` app contains a record of `MarloweParams` for any _new_ Marlowe contracts
(created since the last time we connected this wallet, and for which we therefore have no
corresponding `MarloweFollowr` apps), we now need to create `MarloweFollower` apps for those new
contracts.
In this case, we change the walletCompanionStatus to `LoadingNewContracts`, and subscribe to every
new `MarloweFollower`. We'll know the loading is finished when we've received the first status
update for each of these `MarloweFollower` apps through the WebSocket.
-}
{- [Workflow 4][2] Start a Marlowe contract
After starting a new Marlowe contract, we should receive a WebSocket notification informing us of
the `MarloweParams` and initial `MarloweData` for that contract (via a status update for our
`WalletCompanion` app). We now need to start following that contract with a `MarloweFollower` app.
If we started the contract ourselves, we already created a `MarloweFollower` app as a placeholder.
So here we need to check whether there is an existing `MarloweFollower` app with the right metadata
(and no `MarloweParams`) - and potentially use that instead of creating a new one.
If someone else started the contract, and gave us a role, we will have no placeholder
`MarloweFollower` app, and so we simply create a new one and start following immediately.
-}
handleAction _ (UpdateFollowerApps companionAppState) = do
walletCompanionStatus <- use _walletCompanionStatus
walletDetails <- use _walletDetails
existingContracts <- use _contracts
let
contractExists marloweParams =
elemOf
(traversed <<< _Started <<< _marloweParams)
marloweParams
existingContracts
newContracts = filterKeys (not contractExists) companionAppState
newContractsArray :: Array (Tuple MarloweParams MarloweData)
newContractsArray = toUnfoldable newContracts
if
( walletCompanionStatus /= FirstUpdateComplete &&
(not $ null newContractsArray)
) then
assign _walletCompanionStatus $ LoadingNewContracts $ Set.fromFoldable $ map
fst
newContractsArray
else
assign _walletCompanionStatus FirstUpdateComplete
void
$ for newContractsArray \(marloweParams /\ marloweData) -> do
let
mTemplate = findTemplate $ view _marloweContract marloweData
isStartingAndMetadataMatches
:: Contract.State -> Maybe Contract.StartingState
isStartingAndMetadataMatches = case _, mTemplate of
Contract.Starting starting@{ metadata }, Just template
| template.metaData == metadata -> Just starting
_, _ -> Nothing
mPendingContract = findMin $ mapMaybe isStartingAndMetadataMatches
existingContracts
ajaxFollowerApp <- case mPendingContract of
Just { key: followerAppId } -> followContractWithPendingFollowerApp
walletDetails
marloweParams
followerAppId
Nothing -> followContract walletDetails marloweParams
case ajaxFollowerApp of
Left decodedAjaxError -> addToast $ decodedAjaxErrorToast
"Failed to load new contract."
decodedAjaxError
Right (followerAppId /\ _) -> subscribeToPlutusApp followerAppId
{- [Workflow 2][8] Connect a wallet
If this is the first update we are receiving from a new `MarloweFollower` app that was created
after we connected the wallet, but _before_ the walletCompanionStatus was set to
`FirstUpdateComplete`, we need to remove the app from the `LoadingNewContracts` set. And if it's
the last element of that set, we can set the walletCompanionStatus to `FirstUpdateComplete`. This
(finally!) completes the workflow of connecting a wallet.
-}
{- [Workflow 4][4] Start a contract
If we started a contract (or someone else started one and gave us a role in it), we will have
created a `MarloweFollower` app for that contract, and started following the contract with that
`MarloweFollower` app. Since we will also be subscribed to that app, we will receive an update
about its initial state through the WebSocket. We potentially use that to change the corresponding
`Contract.State` from `Starting` to `Started`.
-}
{- [Workflow 5][2] Move a contract forward -}
handleAction
input@{ currentSlot }
(UpdateContract followerAppId contractHistory) = do
let
chParams = view _chParams contractHistory
-- Before we update the contract state we need to update the total funds to see if there has
-- been a change in the role tokens.
-- There is a chance that the data is not fully synced
-- See note [polling updateTotalFunds]
updateTotalFunds
-- if the chParams have not yet been set, we can't do anything; that's fine though, we'll get
-- another notification through the websocket as soon as they are set
for_ chParams \(marloweParams /\ marloweData) -> do
walletDetails <- use _walletDetails
contracts <- use _contracts
case lookup followerAppId contracts of
Just contractState -> do
let
chHistory = view _chHistory contractHistory
selectedStep <- peruse $ _selectedContract <<< _Started <<<
_selectedStep
modifying _contracts $ insert followerAppId $ Contract.updateState
walletDetails
marloweParams
marloweData
currentSlot
chHistory
contractState
-- if the modification changed the currently selected step, that means the card for the contract
-- that was changed is currently open, so we need to realign the step cards
selectedStep' <- peruse $ _selectedContract <<< _Started <<<
_selectedStep
when (selectedStep /= selectedStep')
$ for_ selectedStep'
( handleAction input <<< ContractAction followerAppId <<<
Contract.MoveToStep
)
Nothing -> for_
( Contract.mkInitialState walletDetails currentSlot mempty
contractHistory
)
(modifying _contracts <<< insert followerAppId)
-- if we're currently loading the first bunch of contracts, we can report that this one has now been loaded
walletCompanionStatus <- use _walletCompanionStatus
case walletCompanionStatus of
LoadingNewContracts pendingMarloweParams -> do
let
updatedPendingMarloweParams = Set.delete marloweParams
pendingMarloweParams
if Set.isEmpty updatedPendingMarloweParams then
assign _walletCompanionStatus FirstUpdateComplete
else
assign _walletCompanionStatus $ LoadingNewContracts
updatedPendingMarloweParams
_ -> pure unit
{- [Workflow 6][1] Redeem payments
This action is triggered every time we receive a status update for a `MarloweFollower` app. The
handler looks, in the corresponding contract, for any payments to roles for which the current
wallet holds the token, and then calls the "redeem" endpoint of the wallet's `MarloweApp` for each
one, to make sure those funds reach the user's wallet (without the user having to do anything).
This is not very sophisticated, and results in the "redeem" endpoint being called more times than
necessary (we are not attempting to keep track of which payments have already been redeemed). Also,
we thought it would be more user-friendly for now to trigger this automatically - but when we
integrate with real wallets, I'm pretty sure we will need to provide a UI for the user to do it
manually (and sign the transaction). So this will almost certainly have to change.
-}
handleAction _ (RedeemPayments followerAppId) = do
walletDetails <- use _walletDetails
mStartedContract <- peruse $ _contracts <<< ix followerAppId <<< _Started
for_ mStartedContract \{ executionState, marloweParams, userParties } ->
let
payments = getAllPayments executionState
isToParty party (Payment _ payee _) = case payee of
Party p -> p == party
_ -> false
in
for (List.fromFoldable userParties) \party ->
let
paymentsToParty = List.filter (isToParty party) payments
in
for paymentsToParty \payment -> case payment of
Payment _ (Party (Role tokenName)) _ -> void $ redeem walletDetails
marloweParams
tokenName
_ -> pure unit
handleAction input@{ currentSlot } AdvanceTimedoutSteps = do
selectedStep <- peruse $ _selectedContract <<< _Started <<< _selectedStep
modifying
( _contracts
<<< traversed
<<< _Started
<<< filtered
( \contract ->
contract.executionState.mNextTimeout /= Nothing &&
contract.executionState.mNextTimeout <= Just currentSlot
)
)
(applyTimeout currentSlot)
selectedContractFollowerAppId <- use _selectedContractFollowerAppId
for_ selectedContractFollowerAppId \followerAppId -> do
-- If the modification changed the currently selected step, that means the screen for the
-- contract that was changed is currently open, so we need to realign the step cards. We also
-- call the CancelConfirmation action - because if the user had the action confirmation card
-- open for an action in the current step, we want to close it (otherwise they could confirm an
-- action that is no longer possible).
selectedStep' <- peruse $ _selectedContract <<< _Started <<< _selectedStep
when (selectedStep /= selectedStep') do
for_ selectedStep'
( handleAction input <<< ContractAction followerAppId <<<
Contract.MoveToStep
)
handleAction input $ ContractAction followerAppId $
Contract.CancelConfirmation
handleAction input@{ currentSlot, addressBook } (TemplateAction templateAction) =
case templateAction of
Template.OpenCreateWalletCard tokenName -> do
modify_
$ set _card (Just $ ContactsCard)
<<< set (_contactsState <<< _cardSection)
(NewWallet $ Just tokenName)
{- [Workflow 4][0] Starting a Marlowe contract -}
Template.StartContract -> do
templateState <- use _templateState
case instantiateExtendedContract currentSlot templateState of
Nothing -> do
void $ tell _submitButtonSlot "action-pay-and-start" $ SubmitResult
(Milliseconds 600.0)
(Left "Error")
addToast $ errorToast "Failed to instantiate contract." $ Just
"Something went wrong when trying to instantiate a contract from this template using the parameters you specified."
Just contract -> do
-- the user enters wallet nicknames for roles; here we convert these into pubKeyHashes
walletDetails <- use _walletDetails
roleWalletInputs <- use (_templateState <<< _roleWalletInputs)
let
roleWallets =
filterMap (hush <<< WN.fromString mempty <<< view _value)
roleWalletInputs
roles = mapMaybe (flip AB.lookupAddress addressBook) roleWallets
ajaxCreateContract <- createContract walletDetails roles contract
case ajaxCreateContract of
-- TODO: make this error message more informative
Left ajaxError -> do
void $ tell _submitButtonSlot "action-pay-and-start" $
SubmitResult (Milliseconds 600.0) (Left "Error")
addToast $ ajaxErrorToast "Failed to initialise contract."
ajaxError
_ -> do
-- Here we create a `MarloweFollower` app with no `MarloweParams`; when the next status
-- update of the wallet's `WalletCompanion` app comes in, we will know the `MarloweParams`,
-- and can use this placeholder `MarloweFollower` app to follow it. Follow the workflow
-- comments to see more...
ajaxPendingFollowerApp <- createPendingFollowerApp walletDetails
case ajaxPendingFollowerApp of
Left ajaxError -> do
void $ tell _submitButtonSlot "action-pay-and-start" $
SubmitResult (Milliseconds 600.0) (Left "Error")
addToast $ ajaxErrorToast "Failed to initialise contract."
ajaxError
Right followerAppId -> do
contractNickname <- use
(_templateState <<< _contractNicknameInput <<< _value)
insertIntoContractNicknames followerAppId contractNickname
metaData <- use
(_templateState <<< _contractTemplate <<< _metaData)
modifying _contracts $ insert followerAppId $
Contract.mkPlaceholderState contractNickname metaData
contract
handleAction input CloseCard
void $ tell _submitButtonSlot "action-pay-and-start" $
SubmitResult (Milliseconds 600.0) (Right "")
addToast $ successToast
"The request to initialise this contract has been submitted."
assign _templateState Template.initialState
_ -> do
toTemplate $ Template.handleAction { addressBook } templateAction
-- FIXME: this all feels like a horrible hack that should be refactored.
-- This action is a bridge from the Contacts to the Template modules. It is used to create a
-- contract for a specific role during contract setup.
handleAction input (SetContactForRole tokenName walletNickname) = do
handleAction input $ TemplateAction Template.UpdateRoleWalletValidators
handleAction input
$ TemplateAction
$ Template.RoleWalletInputAction tokenName
$ InputField.SetValue
$ WN.toString walletNickname
-- we assign the card directly rather than calling the OpenCard action, because this action is
-- triggered when the ContactsCard is open, and we don't want to animate opening and closing
-- cards - we just want to switch instantly back to this card
assign _card $ Just ContractTemplateCard
handleAction
input@{ currentSlot, tzOffset }
(ContractAction followerAppId contractAction) = do
walletDetails <- use _walletDetails
startedState <- peruse $ _contracts <<< at followerAppId <<< _Just <<<
_Started
let
contractInput = { currentSlot, walletDetails, followerAppId, tzOffset }
case contractAction of
Contract.AskConfirmation action ->
for_ startedState \contractState ->
handleAction input $ OpenCard
$ ContractActionConfirmationCard
followerAppId
{ action
, contractState
, currentSlot
, transactionFeeQuote: transactionFee
, userNickname: walletDetails ^. _walletNickname
, walletBalance: getAda $ walletDetails ^. _assets
}
Contract.ConfirmAction _ -> do
void $ toContract followerAppId $ Contract.handleAction contractInput
contractAction
handleAction input CloseCard
Contract.CancelConfirmation -> handleAction input CloseCard
_ -> toContract followerAppId $ Contract.handleAction contractInput
contractAction
------------------------------------------------------------
-- Note [polling updateTotalFunds]
-- We used to have a WebSocket notification whenever the wallet assets changed but that was
-- removed from the Mock Wallet (see link below) and the WalletBackEnd doesn't provide such
-- a mechanism anyways.
-- https://github.com/input-output-hk/plutus-apps/pull/50
-- Besides that, the WBE has the notion of a wallet being synced, so it makes sense to eventually
-- switch from WebSocket push to a rest Pull. The reason I didn't do this change in the PR I
-- introduced this code is that the wallet information is scattered between the Dashboard, Contract
-- and Contact page.
-- TODO: SCP-3211 After Halogen Store is merged and once we refactor wallet state into a global store
-- Refactor this code and do a global polling mechanism.
updateTotalFunds
:: forall m slots msg
. MonadAff m
=> ManageWallet m
=> HalogenM State Action slots msg m Unit
updateTotalFunds = do
walletId <- use (_walletDetails <<< _walletInfo <<< _walletId)
response <- getWalletTotalFunds walletId
for_ response \(GetTotalFundsResponse { assets }) ->
modify_
$ set (_walletDetails <<< _assets)
$ toFront assets
toContacts
:: forall m msg slots
. Functor m
=> HalogenM Contacts.State Contacts.Action slots msg m Unit
-> HalogenM State Action slots msg m Unit
toContacts = mapSubmodule _contactsState ContactsAction
toTemplate
:: forall m msg slots
. Functor m
=> HalogenM Template.State Template.Action slots msg m Unit
-> HalogenM State Action slots msg m Unit
toTemplate = mapSubmodule _templateState TemplateAction
-- see note [dummyState] in MainFrame.State
toContract
:: forall m msg slots
. Functor m
=> PlutusAppId
-> HalogenM Contract.State Contract.Action slots msg m Unit
-> HalogenM State Action slots msg m Unit
toContract followerAppId = mapMaybeSubmodule (_contract followerAppId)
(ContractAction followerAppId)
Contract.dummyState