-- SPDX-FileCopyrightText: 2020 Tocqueville Group
--
-- SPDX-License-Identifier: LicenseRef-MIT-TQ

module Lorentz.Contracts.UpgradeableCounter.V2
  ( Interface
  , UStoreV2
  , CounterV2
  , migrate
  , migrations
  , counterContract
  , counterUpgradeParameters
  ) where

import Lorentz

import Lorentz.Contracts.Upgradeable.Common
import Lorentz.Contracts.Upgradeable.EntrypointWise
import Lorentz.Contracts.UpgradeableCounter.V1 (CounterV1, UStoreTemplateV1)
import Lorentz.UStore
import Lorentz.UStore.Migration

data CounterV2 :: VersionKind

data UStoreTemplateV2 = UStoreTemplateV2
  { UStoreTemplateV2 -> UStoreField Integer
newCounterValue :: UStoreField Integer
  , UStoreTemplateV2 -> MText |~> EntrypointImpl UStoreTemplateV2
code :: MText |~> EntrypointImpl UStoreTemplateV2
  , UStoreTemplateV2 -> UStoreField $ EpwFallback UStoreTemplateV2
fallback :: UStoreField $ EpwFallback UStoreTemplateV2
  } deriving stock (UStoreTemplateV2 -> UStoreTemplateV2 -> Bool
(UStoreTemplateV2 -> UStoreTemplateV2 -> Bool)
-> (UStoreTemplateV2 -> UStoreTemplateV2 -> Bool)
-> Eq UStoreTemplateV2
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UStoreTemplateV2 -> UStoreTemplateV2 -> Bool
$c/= :: UStoreTemplateV2 -> UStoreTemplateV2 -> Bool
== :: UStoreTemplateV2 -> UStoreTemplateV2 -> Bool
$c== :: UStoreTemplateV2 -> UStoreTemplateV2 -> Bool
Eq, (forall x. UStoreTemplateV2 -> Rep UStoreTemplateV2 x)
-> (forall x. Rep UStoreTemplateV2 x -> UStoreTemplateV2)
-> Generic UStoreTemplateV2
forall x. Rep UStoreTemplateV2 x -> UStoreTemplateV2
forall x. UStoreTemplateV2 -> Rep UStoreTemplateV2 x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UStoreTemplateV2 x -> UStoreTemplateV2
$cfrom :: forall x. UStoreTemplateV2 -> Rep UStoreTemplateV2 x
Generic)

type UStoreV2 = UStore UStoreTemplateV2

type Interface =
  [ "inc" ?: ()
  , "dec" ?: ()
  , "getCounterValue" ?: Void_ () Integer
  ]

instance KnownContractVersion CounterV2 where
  type VerInterface CounterV2 = Interface
  type VerUStoreTemplate CounterV2 = UStoreTemplateV2
  contractVersion :: Proxy CounterV2 -> Version
contractVersion Proxy CounterV2
_ = Version
2

epwContract :: EpwContract CounterV2
epwContract :: EpwContract CounterV2
epwContract = IsoRecTuple (Rec (EpwCaseClause UStoreTemplateV2) Interface)
-> EpwFallback UStoreTemplateV2 -> EpwContract CounterV2
forall clauses (ver :: VersionKind) (interface :: [EntrypointKind])
       store.
(interface ~ VerInterface ver, store ~ VerUStoreTemplate ver,
 clauses ~ Rec (EpwCaseClause store) interface,
 RecFromTuple clauses, CodeMigrations interface,
 HasUStore "code" MText (EntrypointImpl store) store,
 HasUField "fallback" (EpwFallback store) store, Typeable store) =>
IsoRecTuple clauses -> EpwFallback store -> EpwContract ver
mkEpwContractT
  ( Label "inc"
forall a. IsLabel "inc" a => a
forall (x :: Symbol) a. IsLabel x a => a
#inc Label "inc"
-> Lambda
     ((), UStore UStoreTemplateV2)
     ([Operation], UStore UStoreTemplateV2)
-> EpwCaseClause UStoreTemplateV2 '("inc", ())
forall (name :: Symbol) arg store.
Label name
-> Lambda (arg, UStore store) ([Operation], UStore store)
-> EpwCaseClause store '(name, arg)
/==> Lambda
  ((), UStore UStoreTemplateV2)
  ([Operation], UStore UStoreTemplateV2)
runInc
  , Label "dec"
forall a. IsLabel "dec" a => a
forall (x :: Symbol) a. IsLabel x a => a
#dec Label "dec"
-> Lambda
     ((), UStore UStoreTemplateV2)
     ([Operation], UStore UStoreTemplateV2)
-> EpwCaseClause UStoreTemplateV2 '("dec", ())
forall (name :: Symbol) arg store.
Label name
-> Lambda (arg, UStore store) ([Operation], UStore store)
-> EpwCaseClause store '(name, arg)
/==> Lambda
  ((), UStore UStoreTemplateV2)
  ([Operation], UStore UStoreTemplateV2)
runDec
  , Label "getCounterValue"
forall a. IsLabel "getCounterValue" a => a
forall (x :: Symbol) a. IsLabel x a => a
#getCounterValue Label "getCounterValue"
-> Lambda
     (Void_ () Integer, UStore UStoreTemplateV2)
     ([Operation], UStore UStoreTemplateV2)
-> EpwCaseClause
     UStoreTemplateV2 '("getCounterValue", Void_ () Integer)
forall (name :: Symbol) arg store.
Label name
-> Lambda (arg, UStore store) ([Operation], UStore store)
-> EpwCaseClause store '(name, arg)
/==> Lambda
  (Void_ () Integer, UStore UStoreTemplateV2)
  ([Operation], UStore UStoreTemplateV2)
runView
  ) EpwFallback UStoreTemplateV2
forall store. EpwFallback store
epwFallbackFail

addInt :: Integer -> Lambda ((), UStoreV2) ([Operation], UStoreV2)
addInt :: Integer
-> Lambda
     ((), UStore UStoreTemplateV2)
     ([Operation], UStore UStoreTemplateV2)
addInt Integer
x = do
  '[((), UStore UStoreTemplateV2)] :-> '[(), UStore UStoreTemplateV2]
forall a b (s :: [*]). ((a, b) : s) :-> (a : b : s)
unpair
  '[(), UStore UStoreTemplateV2] :-> '[UStore UStoreTemplateV2]
forall a (s :: [*]). (a : s) :-> s
drop
  Label "newCounterValue"
-> '[UStore UStoreTemplateV2]
   :-> '[GetUStoreField UStoreTemplateV2 "newCounterValue",
         UStore UStoreTemplateV2]
forall store (name :: Symbol) (s :: [*]).
FieldAccessC store name =>
Label name
-> (UStore store : s)
   :-> (GetUStoreField store name : UStore store : s)
ustoreGetField Label "newCounterValue"
forall a. IsLabel "newCounterValue" a => a
forall (x :: Symbol) a. IsLabel x a => a
#newCounterValue
  Integer
-> '[Integer, UStore UStoreTemplateV2]
   :-> '[Integer, Integer, UStore UStoreTemplateV2]
forall t (s :: [*]). NiceConstant t => t -> s :-> (t : s)
push Integer
x
  '[Integer, Integer, UStore UStoreTemplateV2]
:-> '[Integer, UStore UStoreTemplateV2]
forall n m (s :: [*]).
ArithOpHs Add n m =>
(n : m : s) :-> (ArithResHs Add n m : s)
add
  Label "newCounterValue"
-> '[GetUStoreField UStoreTemplateV2 "newCounterValue",
     UStore UStoreTemplateV2]
   :-> '[UStore UStoreTemplateV2]
forall store (name :: Symbol) (s :: [*]).
FieldAccessC store name =>
Label name
-> (GetUStoreField store name : UStore store : s)
   :-> (UStore store : s)
ustoreSetField Label "newCounterValue"
forall a. IsLabel "newCounterValue" a => a
forall (x :: Symbol) a. IsLabel x a => a
#newCounterValue
  '[UStore UStoreTemplateV2]
:-> '[[Operation], UStore UStoreTemplateV2]
forall p (s :: [*]). KnownValue p => s :-> (List p : s)
nil; '[[Operation], UStore UStoreTemplateV2]
:-> '[([Operation], UStore UStoreTemplateV2)]
forall a b (s :: [*]). (a : b : s) :-> ((a, b) : s)
pair

runInc :: Lambda ((), UStoreV2) ([Operation], UStoreV2)
runInc :: Lambda
  ((), UStore UStoreTemplateV2)
  ([Operation], UStore UStoreTemplateV2)
runInc = Integer
-> Lambda
     ((), UStore UStoreTemplateV2)
     ([Operation], UStore UStoreTemplateV2)
addInt Integer
1

runDec :: Lambda ((), UStoreV2) ([Operation], UStoreV2)
runDec :: Lambda
  ((), UStore UStoreTemplateV2)
  ([Operation], UStore UStoreTemplateV2)
runDec = Integer
-> Lambda
     ((), UStore UStoreTemplateV2)
     ([Operation], UStore UStoreTemplateV2)
addInt (Integer
-1)

runView :: Lambda (Void_ () Integer, UStoreV2) ([Operation], UStoreV2)
runView :: Lambda
  (Void_ () Integer, UStore UStoreTemplateV2)
  ([Operation], UStore UStoreTemplateV2)
runView = do
  '[(Void_ () Integer, UStore UStoreTemplateV2)]
:-> '[Void_ () Integer, UStore UStoreTemplateV2]
forall a b (s :: [*]). ((a, b) : s) :-> (a : b : s)
unpair
  ('[(), UStore UStoreTemplateV2] :-> '[Integer])
-> '[Void_ () Integer, UStore UStoreTemplateV2]
   :-> '[([Operation], UStore UStoreTemplateV2)]
forall a b (s :: [*]) (s' :: [*]) (anything :: [*]).
(IsError (VoidResult b), NiceConstant b) =>
((a : s) :-> (b : s')) -> (Void_ a b : s) :-> anything
void_ (('[(), UStore UStoreTemplateV2] :-> '[Integer])
 -> '[Void_ () Integer, UStore UStoreTemplateV2]
    :-> '[([Operation], UStore UStoreTemplateV2)])
-> ('[(), UStore UStoreTemplateV2] :-> '[Integer])
-> '[Void_ () Integer, UStore UStoreTemplateV2]
   :-> '[([Operation], UStore UStoreTemplateV2)]
forall a b. (a -> b) -> a -> b
$ do
    forall (s :: [*]). (() : s) :-> s
forall a (s :: [*]). (a : s) :-> s
drop @()
    Label "newCounterValue"
-> '[UStore UStoreTemplateV2]
   :-> '[GetUStoreField UStoreTemplateV2 "newCounterValue",
         UStore UStoreTemplateV2]
forall store (name :: Symbol) (s :: [*]).
FieldAccessC store name =>
Label name
-> (UStore store : s)
   :-> (GetUStoreField store name : UStore store : s)
ustoreGetField Label "newCounterValue"
forall a. IsLabel "newCounterValue" a => a
forall (x :: Symbol) a. IsLabel x a => a
#newCounterValue
    ('[UStore UStoreTemplateV2] :-> '[])
-> '[Integer, UStore UStoreTemplateV2] :-> '[Integer]
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip '[UStore UStoreTemplateV2] :-> '[]
forall a (s :: [*]). (a : s) :-> s
drop


migrations :: [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
migrations :: [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
migrations =
    UStoreMigration UStoreTemplateV1 UStoreTemplateV2
-> MigrationScript UStoreTemplateV1 UStoreTemplateV2
forall os ns. UStoreMigration os ns -> MigrationScript os ns
migrationToScript UStoreMigration UStoreTemplateV1 UStoreTemplateV2
migrateStorage
  MigrationScript UStoreTemplateV1 UStoreTemplateV2
-> [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
-> [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
forall a. a -> [a] -> [a]
: MigrationScript UStoreTemplateV1 UStoreTemplateV2
removeOldEndpoints
  MigrationScript UStoreTemplateV1 UStoreTemplateV2
-> [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
-> [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
forall a. a -> [a] -> [a]
: EpwContract CounterV2
-> forall oldStore.
   [MigrationScript oldStore (VerUStoreTemplate CounterV2)]
forall (ver :: VersionKind).
EpwContract ver
-> forall oldStore.
   [MigrationScript oldStore (VerUStoreTemplate ver)]
epwCodeMigrations EpwContract CounterV2
epwContract

removeOldEndpoints :: MigrationScript UStoreTemplateV1 UStoreTemplateV2
removeOldEndpoints :: MigrationScript UStoreTemplateV1 UStoreTemplateV2
removeOldEndpoints = ('[UStore UStoreTemplateV1] :-> '[UStore UStoreTemplateV1])
-> MigrationScript UStoreTemplateV1 UStoreTemplateV2
forall oldStore newStore.
('[UStore oldStore] :-> '[UStore oldStore])
-> MigrationScript oldStore newStore
manualWithOldUStore (('[UStore UStoreTemplateV1] :-> '[UStore UStoreTemplateV1])
 -> MigrationScript UStoreTemplateV1 UStoreTemplateV2)
-> ('[UStore UStoreTemplateV1] :-> '[UStore UStoreTemplateV1])
-> MigrationScript UStoreTemplateV1 UStoreTemplateV2
forall a b. (a -> b) -> a -> b
$ do
  Label "add"
-> '[UStore UStoreTemplateV1] :-> '[UStore UStoreTemplateV1]
forall store (name :: Symbol) (s :: [*]).
(GetUStoreKey store "code" ~ MText) =>
Label name -> (UStore store : s) :-> (UStore store : s)
removeEndpoint Label "add"
forall a. IsLabel "add" a => a
forall (x :: Symbol) a. IsLabel x a => a
#add
  Label "mul"
-> '[UStore UStoreTemplateV1] :-> '[UStore UStoreTemplateV1]
forall store (name :: Symbol) (s :: [*]).
(GetUStoreKey store "code" ~ MText) =>
Label name -> (UStore store : s) :-> (UStore store : s)
removeEndpoint Label "mul"
forall a. IsLabel "mul" a => a
forall (x :: Symbol) a. IsLabel x a => a
#mul

migrateStorage :: UStoreMigration UStoreTemplateV1 UStoreTemplateV2
migrateStorage :: UStoreMigration UStoreTemplateV1 UStoreTemplateV2
migrateStorage = Lambda
  (MUStore
     UStoreTemplateV1
     UStoreTemplateV2
     (BuildDiff UStoreTemplateV1 UStoreTemplateV2)
     '[])
  (MUStore
     UStoreTemplateV1
     UStoreTemplateV2
     '[]
     '["newCounterValue", "counterValue"])
-> UStoreMigration UStoreTemplateV1 UStoreTemplateV2
forall oldTempl newTempl (_1 :: [Symbol]).
Lambda
  (MUStore oldTempl newTempl (BuildDiff oldTempl newTempl) '[])
  (MUStore oldTempl newTempl '[] _1)
-> UStoreMigration oldTempl newTempl
mkUStoreMigration (Lambda
   (MUStore
      UStoreTemplateV1
      UStoreTemplateV2
      (BuildDiff UStoreTemplateV1 UStoreTemplateV2)
      '[])
   (MUStore
      UStoreTemplateV1
      UStoreTemplateV2
      '[]
      '["newCounterValue", "counterValue"])
 -> UStoreMigration UStoreTemplateV1 UStoreTemplateV2)
-> Lambda
     (MUStore
        UStoreTemplateV1
        UStoreTemplateV2
        (BuildDiff UStoreTemplateV1 UStoreTemplateV2)
        '[])
     (MUStore
        UStoreTemplateV1
        UStoreTemplateV2
        '[]
        '["newCounterValue", "counterValue"])
-> UStoreMigration UStoreTemplateV1 UStoreTemplateV2
forall a b. (a -> b) -> a -> b
$ do
  Label "counterValue"
-> '[MUStore
       UStoreTemplateV1
       UStoreTemplateV2
       '[ '( 'ToAdd, '("newCounterValue", UStoreField Integer)),
          '( 'ToAdd, '("code", MText |~> EntrypointImpl UStoreTemplateV2)),
          '( 'ToAdd,
             '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
          '( 'ToDel,
             '("counterValue", UStoreFieldExt UMarkerPlainField Natural)),
          '( 'ToDel,
             '("code",
               MText
               |~> ('[(ByteString, UStore UStoreTemplateV1)]
                    :-> '[([Operation], UStore UStoreTemplateV1)]))),
          '( 'ToDel,
             '("fallback",
               UStoreFieldExt
                 UMarkerPlainField
                 ('[((MText, ByteString), UStore UStoreTemplateV1)]
                  :-> '[([Operation], UStore UStoreTemplateV1)])))]
       '[]]
   :-> '[Natural,
         MUStore
           UStoreTemplateV1
           UStoreTemplateV2
           '[ '( 'ToAdd, '("newCounterValue", UStoreField Integer)),
              '( 'ToAdd, '("code", MText |~> EntrypointImpl UStoreTemplateV2)),
              '( 'ToAdd,
                 '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
              '( 'ToDel,
                 '("code",
                   MText
                   |~> ('[(ByteString, UStore UStoreTemplateV1)]
                        :-> '[([Operation], UStore UStoreTemplateV1)]))),
              '( 'ToDel,
                 '("fallback",
                   UStoreFieldExt
                     UMarkerPlainField
                     ('[((MText, ByteString), UStore UStoreTemplateV1)]
                      :-> '[([Operation], UStore UStoreTemplateV1)])))]
           '["counterValue"]]
forall (field :: Symbol) oldTempl newTempl (diff :: [DiffItem])
       (touched :: [Symbol]) fieldTy (newDiff :: [DiffItem])
       (marker :: UStoreMarkerType) (s :: [*]).
('(UStoreFieldExt marker fieldTy, newDiff)
 ~ CoverDiff 'DcRemove field diff,
 HasUField field fieldTy oldTempl,
 RequireUntouched field (IsElem field touched)) =>
Label field
-> (MUStore oldTempl newTempl diff touched : s)
   :-> (fieldTy
          : MUStore oldTempl newTempl newDiff (field : touched) : s)
migrateExtractField Label "counterValue"
forall a. IsLabel "counterValue" a => a
forall (x :: Symbol) a. IsLabel x a => a
#counterValue
  '[Natural,
  MUStore
    UStoreTemplateV1
    UStoreTemplateV2
    '[ '( 'ToAdd, '("newCounterValue", UStoreField Integer)),
       '( 'ToAdd, '("code", MText |~> EntrypointImpl UStoreTemplateV2)),
       '( 'ToAdd,
          '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
       '( 'ToDel,
          '("code",
            MText
            |~> ('[(ByteString, UStore UStoreTemplateV1)]
                 :-> '[([Operation], UStore UStoreTemplateV1)]))),
       '( 'ToDel,
          '("fallback",
            UStoreFieldExt
              UMarkerPlainField
              ('[((MText, ByteString), UStore UStoreTemplateV1)]
               :-> '[([Operation], UStore UStoreTemplateV1)])))]
    '["counterValue"]]
:-> '[Integer,
      MUStore
        UStoreTemplateV1
        UStoreTemplateV2
        '[ '( 'ToAdd, '("newCounterValue", UStoreField Integer)),
           '( 'ToAdd, '("code", MText |~> EntrypointImpl UStoreTemplateV2)),
           '( 'ToAdd,
              '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
           '( 'ToDel,
              '("code",
                MText
                |~> ('[(ByteString, UStore UStoreTemplateV1)]
                     :-> '[([Operation], UStore UStoreTemplateV1)]))),
           '( 'ToDel,
              '("fallback",
                UStoreFieldExt
                  UMarkerPlainField
                  ('[((MText, ByteString), UStore UStoreTemplateV1)]
                   :-> '[([Operation], UStore UStoreTemplateV1)])))]
        '["counterValue"]]
forall i (s :: [*]).
ToIntegerArithOpHs i =>
(i : s) :-> (Integer : s)
int
  Label "newCounterValue"
-> '[Integer,
     MUStore
       UStoreTemplateV1
       UStoreTemplateV2
       '[ '( 'ToAdd, '("newCounterValue", UStoreField Integer)),
          '( 'ToAdd, '("code", MText |~> EntrypointImpl UStoreTemplateV2)),
          '( 'ToAdd,
             '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
          '( 'ToDel,
             '("code",
               MText
               |~> ('[(ByteString, UStore UStoreTemplateV1)]
                    :-> '[([Operation], UStore UStoreTemplateV1)]))),
          '( 'ToDel,
             '("fallback",
               UStoreFieldExt
                 UMarkerPlainField
                 ('[((MText, ByteString), UStore UStoreTemplateV1)]
                  :-> '[([Operation], UStore UStoreTemplateV1)])))]
       '["counterValue"]]
   :-> '[MUStore
           UStoreTemplateV1
           UStoreTemplateV2
           '[ '( 'ToAdd,
                 '("code", MText |~> EntrypointImpl UStoreTemplateV2)),
              '( 'ToAdd,
                 '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
              '( 'ToDel,
                 '("code",
                   MText
                   |~> ('[(ByteString, UStore UStoreTemplateV1)]
                        :-> '[([Operation], UStore UStoreTemplateV1)]))),
              '( 'ToDel,
                 '("fallback",
                   UStoreFieldExt
                     UMarkerPlainField
                     ('[((MText, ByteString), UStore UStoreTemplateV1)]
                      :-> '[([Operation], UStore UStoreTemplateV1)])))]
           '["newCounterValue", "counterValue"]]
forall (field :: Symbol) oldTempl newTempl (diff :: [DiffItem])
       (touched :: [Symbol]) fieldTy (newDiff :: [DiffItem])
       (marker :: UStoreMarkerType) (s :: [*]).
('(UStoreFieldExt marker fieldTy, newDiff)
 ~ CoverDiff 'DcAdd field diff,
 HasUField field fieldTy newTempl) =>
Label field
-> (fieldTy : MUStore oldTempl newTempl diff touched : s)
   :-> (MUStore oldTempl newTempl newDiff (field : touched) : s)
migrateAddField Label "newCounterValue"
forall a. IsLabel "newCounterValue" a => a
forall (x :: Symbol) a. IsLabel x a => a
#newCounterValue

  Label "code"
-> '[MUStore
       UStoreTemplateV1
       UStoreTemplateV2
       '[ '( 'ToAdd,
             '("code", MText |~> EntrypointImpl UStoreTemplateV2)),
          '( 'ToAdd,
             '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
          '( 'ToDel,
             '("code",
               MText
               |~> ('[(ByteString, UStore UStoreTemplateV1)]
                    :-> '[([Operation], UStore UStoreTemplateV1)]))),
          '( 'ToDel,
             '("fallback",
               UStoreFieldExt
                 UMarkerPlainField
                 ('[((MText, ByteString), UStore UStoreTemplateV1)]
                  :-> '[([Operation], UStore UStoreTemplateV1)])))]
       '["newCounterValue", "counterValue"]]
   :-> '[MUStore
           UStoreTemplateV1
           UStoreTemplateV2
           '[ '( 'ToAdd,
                 '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
              '( 'ToDel,
                 '("fallback",
                   UStoreFieldExt
                     UMarkerPlainField
                     ('[((MText, ByteString), UStore UStoreTemplateV1)]
                      :-> '[([Operation], UStore UStoreTemplateV1)])))]
           '["newCounterValue", "counterValue"]]
forall (field :: Symbol) oldTempl newTempl (diff :: [DiffItem])
       (touched :: [Symbol]) (newDiff :: [DiffItem])
       (newDiff0 :: [DiffItem]) _1 _2 (s :: [*]).
('(_1, newDiff0) ~ CoverDiff 'DcRemove field diff,
 '(_2, newDiff) ~ CoverDiff 'DcAdd field newDiff0) =>
Label field
-> (MUStore oldTempl newTempl diff touched : s)
   :-> (MUStore oldTempl newTempl newDiff touched : s)
migrateCoerceUnsafe Label "code"
forall a. IsLabel "code" a => a
forall (x :: Symbol) a. IsLabel x a => a
#code
  Label "fallback"
-> '[MUStore
       UStoreTemplateV1
       UStoreTemplateV2
       '[ '( 'ToAdd,
             '("fallback", UStoreField $ EpwFallback UStoreTemplateV2)),
          '( 'ToDel,
             '("fallback",
               UStoreFieldExt
                 UMarkerPlainField
                 ('[((MText, ByteString), UStore UStoreTemplateV1)]
                  :-> '[([Operation], UStore UStoreTemplateV1)])))]
       '["newCounterValue", "counterValue"]]
   :-> '[MUStore
           UStoreTemplateV1
           UStoreTemplateV2
           '[]
           '["newCounterValue", "counterValue"]]
forall (field :: Symbol) oldTempl newTempl (diff :: [DiffItem])
       (touched :: [Symbol]) (newDiff :: [DiffItem])
       (newDiff0 :: [DiffItem]) _1 _2 (s :: [*]).
('(_1, newDiff0) ~ CoverDiff 'DcRemove field diff,
 '(_2, newDiff) ~ CoverDiff 'DcAdd field newDiff0) =>
Label field
-> (MUStore oldTempl newTempl diff touched : s)
   :-> (MUStore oldTempl newTempl newDiff touched : s)
migrateCoerceUnsafe Label "fallback"
forall a. IsLabel "fallback" a => a
forall (x :: Symbol) a. IsLabel x a => a
#fallback

  '[MUStore
    UStoreTemplateV1
    UStoreTemplateV2
    '[]
    '["newCounterValue", "counterValue"]]
:-> '[MUStore
        UStoreTemplateV1
        UStoreTemplateV2
        '[]
        '["newCounterValue", "counterValue"]]
forall a. MigrationFinishCheckPosition a => a
migrationFinish

migrate :: MigrationScript UStoreTemplateV1 UStoreTemplateV2
migrate :: MigrationScript UStoreTemplateV1 UStoreTemplateV2
migrate = [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
-> MigrationScript UStoreTemplateV1 UStoreTemplateV2
forall os ns. [MigrationScript os ns] -> MigrationScript os ns
manualConcatMigrationScripts [MigrationScript UStoreTemplateV1 UStoreTemplateV2]
migrations

counterContract :: UContractRouter CounterV2
counterContract :: UContractRouter CounterV2
counterContract = EpwContract CounterV2 -> UContractRouter CounterV2
forall (ver :: VersionKind). EpwContract ver -> UContractRouter ver
epwServe EpwContract CounterV2
epwContract

counterUpgradeParameters :: EpwUpgradeParameters [] CounterV1 CounterV2
counterUpgradeParameters :: EpwUpgradeParameters [] CounterV1 CounterV2
counterUpgradeParameters = EpwUpgradeParameters :: forall (t :: * -> *) (curVer :: VersionKind)
       (newVer :: VersionKind) code codePerm.
(Traversable t, KnownContractVersion curVer,
 KnownContractVersion newVer,
 RequireSamePermanents (VerPermanent curVer) (VerPermanent newVer),
 RecognizeUpgPiece (UContractRouterUpdate curVer newVer) code,
 RecognizeUpgPiece (PermanentImplUpdate curVer newVer) codePerm) =>
t (MigrationScript
     (VerUStoreTemplate curVer) (VerUStoreTemplate newVer))
-> code -> codePerm -> EpwUpgradeParameters t curVer newVer
EpwUpgradeParameters
  { upMigrationScripts :: [MigrationScript
   (VerUStoreTemplate CounterV1) (VerUStoreTemplate CounterV2)]
upMigrationScripts = [MigrationScript
   (VerUStoreTemplate CounterV1) (VerUStoreTemplate CounterV2)]
[MigrationScript UStoreTemplateV1 UStoreTemplateV2]
migrations
  , upNewCode :: UContractRouter CounterV2
upNewCode = UContractRouter CounterV2
counterContract
  , upNewPermCode :: PermanentImpl CounterV2
upNewPermCode = PermanentImpl CounterV2
forall (ver :: VersionKind).
(VerPermanent ver ~ Empty) =>
PermanentImpl ver
emptyPermanentImpl
  }