{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_GHC -Wno-unused-do-bind #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE NoApplicativeDo #-}
module Lorentz.Tickets
(
authorizeAction
, verifyTargetContract
, verifyTargetContractAnd
, STicket (..)
, toSTicket
, coerceUnwrap
, readSTicket
, sTicketAmount
, subtractSTicket
, subtractSTicketPlain
, addSTicket
, addSTicketPlain
, verifyTicketGeneric
, verifyTicketGeneric'
, verifyTicketer
) where
import Prelude (Generic, Typeable, ($))
import qualified Prelude as P
import Lorentz.ADT
import Lorentz.Annotation
import Lorentz.Base
import Lorentz.Coercions
import Lorentz.Constraints
import Lorentz.Doc
import Lorentz.Errors
import Lorentz.Expr
import Lorentz.Instr
import Lorentz.Macro
import Lorentz.Rebinded
import Lorentz.Value
import Morley.Michelson.Typed.Haskell.Doc
import Morley.Util.Markdown
type instance ErrorArg "wRONG_TICKETER" = NoErrorArg
instance CustomErrorHasDoc "wRONG_TICKETER" where
customErrClass :: ErrorClass
customErrClass = ErrorClass
ErrClassActionException
customErrDocMdCause :: Markdown
customErrDocMdCause = Markdown
"Ticket emitted by the wrong entity."
type instance ErrorArg "nOT_TICKET_TARGET" = NoErrorArg
instance CustomErrorHasDoc "nOT_TICKET_TARGET" where
customErrClass :: ErrorClass
customErrClass = ErrorClass
ErrClassBadArgument
customErrDocMdCause :: Markdown
customErrDocMdCause =
Markdown
"Data in the ticket tells that it is intended for a different contract."
type instance ErrorArg "nOT_SINGLE_TICKET_TOKEN" = NoErrorArg
instance CustomErrorHasDoc "nOT_SINGLE_TICKET_TOKEN" where
customErrClass :: ErrorClass
customErrClass = ErrorClass
ErrClassBadArgument
customErrDocMdCause :: Markdown
customErrDocMdCause =
Markdown
"This action expected a ticket with exactly one token."
verifyTicketGeneric'
:: (IsoValue td)
=> (forall s0. Address : Address : s0 :-> s0)
-> (forall s0. Natural : s0 :-> s0)
-> td : s :-> s'
-> TAddress emitterParam : Ticket td : s :-> Ticket td : s'
verifyTicketGeneric' :: (forall (s0 :: [*]). (Address : Address : s0) :-> s0)
-> (forall (s0 :: [*]). (Natural : s0) :-> s0)
-> ((td : s) :-> s')
-> (TAddress emitterParam : Ticket td : s) :-> (Ticket td : s')
verifyTicketGeneric' forall (s0 :: [*]). (Address : Address : s0) :-> s0
verifyTicketer' forall (s0 :: [*]). (Natural : s0) :-> s0
verifyTokens (td : s) :-> s'
verifyData = do
((Ticket td : s) :-> (Ticket td : Address : td : Natural : s))
-> (TAddress emitterParam : Ticket td : s)
:-> (TAddress emitterParam
: Ticket td : Address : td : Natural : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip do
(Ticket td : s) :-> (ReadTicket td : Ticket td : s)
forall a (s :: [*]).
(Ticket a : s) :-> (ReadTicket a : Ticket a : s)
readTicket; (ReadTicket td : Ticket td : s) :-> (Ticket td : ReadTicket td : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap; ((ReadTicket td : s) :-> (Address : td : Natural : s))
-> (Ticket td : ReadTicket td : s)
:-> (Ticket td : Address : td : Natural : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip (ReadTicket td : s) :-> (Address : td : Natural : s)
forall dt (fields :: [*]) (st :: [*]).
(InstrDeconstructC dt, KnownList fields,
fields ~ ConstructorFieldTypes dt) =>
(dt : st) :-> (fields ++ st)
deconstruct
(TAddress emitterParam : Ticket td : Address : td : Natural : s)
:-> (Ticket td
: TAddress emitterParam : Address : td : Natural : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap; forall (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (Ticket td : s) :-> (Ticket td : s')
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip @(Ticket _) (((TAddress emitterParam : Address : td : Natural : s) :-> s')
-> (Ticket td : TAddress emitterParam : Address : td : Natural : s)
:-> (Ticket td : s'))
-> ((TAddress emitterParam : Address : td : Natural : s) :-> s')
-> (Ticket td : TAddress emitterParam : Address : td : Natural : s)
:-> (Ticket td : s')
forall a b. (a -> b) -> a -> b
$ do
(TAddress emitterParam : Address : td : Natural : s)
:-> (Address : Address : td : Natural : s)
forall a b (s :: [*]). Castable_ a b => (a : s) :-> (b : s)
checkedCoerce_; (Address : Address : td : Natural : s) :-> (td : Natural : s)
forall (s0 :: [*]). (Address : Address : s0) :-> s0
verifyTicketer'
(td : Natural : s) :-> (Natural : td : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap
(Natural : td : s) :-> (td : s)
forall (s0 :: [*]). (Natural : s0) :-> s0
verifyTokens
(td : s) :-> s'
verifyData
verifyTicketGeneric
:: (IsoValue td)
=> (forall s0. Natural : s0 :-> s0)
-> td : s :-> s'
-> TAddress emitterParam : Ticket td : s :-> Ticket td : s'
verifyTicketGeneric :: (forall (s0 :: [*]). (Natural : s0) :-> s0)
-> ((td : s) :-> s')
-> (TAddress emitterParam : Ticket td : s) :-> (Ticket td : s')
verifyTicketGeneric = (forall (s0 :: [*]). (Address : Address : s0) :-> s0)
-> (forall (s0 :: [*]). (Natural : s0) :-> s0)
-> ((td : s) :-> s')
-> (TAddress emitterParam : Ticket td : s) :-> (Ticket td : s')
forall td (s :: [*]) (s' :: [*]) emitterParam.
IsoValue td =>
(forall (s0 :: [*]). (Address : Address : s0) :-> s0)
-> (forall (s0 :: [*]). (Natural : s0) :-> s0)
-> ((td : s) :-> s')
-> (TAddress emitterParam : Ticket td : s) :-> (Ticket td : s')
verifyTicketGeneric' forall (s0 :: [*]). (Address : Address : s0) :-> s0
verifyTicketer
verifyTicketer :: Address : Address : s :-> s
verifyTicketer :: (Address : Address : s) :-> s
verifyTicketer = if Condition (Address : Address : s) s s s s
forall a (s :: [*]) (o :: [*]).
NiceComparable a =>
Condition (a : a : s) s s o o
IsEq then s :-> s
forall (s :: [*]). s :-> s
nop else Label "wRONG_TICKETER" -> s :-> s
forall (tag :: Symbol) (s :: [*]) (any :: [*]).
(MustHaveErrorArg tag MText, CustomErrorHasDoc tag) =>
Label tag -> s :-> any
failCustomNoArg Label "wRONG_TICKETER"
forall a. IsLabel "wRONG_TICKETER" a => a
forall (x :: Symbol) a. IsLabel x a => a
#wRONG_TICKETER
verifyTargetContractAnd
:: (d : s :-> s')
-> (TAddress selfParam, d) : s :-> s'
verifyTargetContractAnd :: ((d : s) :-> s') -> ((TAddress selfParam, d) : s) :-> s'
verifyTargetContractAnd (d : s) :-> s'
verifyData = do
((TAddress selfParam, d) : s) :-> (TAddress selfParam : d : s)
forall a b (s :: [*]). ((a, b) : s) :-> (a : b : s)
unpair; (TAddress selfParam : d : s) :-> (d : s)
forall selfParam (s :: [*]). (TAddress selfParam : s) :-> s
verifyTargetContract; (d : s) :-> s'
verifyData
verifyTargetContract :: TAddress selfParam : s :-> s
verifyTargetContract :: (TAddress selfParam : s) :-> s
verifyTargetContract =
if (TAddress selfParam : s) :-> (Address : s)
forall a b (s :: [*]). Castable_ a b => (a : s) :-> (b : s)
checkedCoerce_ ((TAddress selfParam : s) :-> (Address : s))
-> Expr s s Address -> Expr (TAddress selfParam : s) s Bool
forall a (s0 :: [*]) (s1 :: [*]) (s2 :: [*]).
NiceComparable a =>
Expr s0 s1 a -> Expr s1 s2 a -> Expr s0 s2 Bool
|==| Expr s s Address
forall (s :: [*]). s :-> (Address : s)
selfAddress
then s :-> s
forall (s :: [*]). s :-> s
nop
else Label "nOT_TICKET_TARGET" -> s :-> s
forall (tag :: Symbol) (s :: [*]) (any :: [*]).
(MustHaveErrorArg tag MText, CustomErrorHasDoc tag) =>
Label tag -> s :-> any
failCustomNoArg Label "nOT_TICKET_TARGET"
forall a. IsLabel "nOT_TICKET_TARGET" a => a
forall (x :: Symbol) a. IsLabel x a => a
#nOT_TICKET_TARGET
authorizeAction
:: (IsoValue td)
=> (td : s :-> s')
-> TAddress emitterParam : Ticket td : s :-> s'
authorizeAction :: ((td : s) :-> s') -> (TAddress emitterParam : Ticket td : s) :-> s'
authorizeAction (td : s) :-> s'
verifyTicketData = do
(forall (s0 :: [*]). (Natural : s0) :-> s0)
-> ((td : s) :-> s')
-> (TAddress emitterParam : Ticket td : s) :-> (Ticket td : s')
forall td (s :: [*]) (s' :: [*]) emitterParam.
IsoValue td =>
(forall (s0 :: [*]). (Natural : s0) :-> s0)
-> ((td : s) :-> s')
-> (TAddress emitterParam : Ticket td : s) :-> (Ticket td : s')
verifyTicketGeneric
forall (s0 :: [*]). (Natural : s0) :-> s0
verifySingleToken
(td : s) :-> s'
verifyTicketData
(Ticket td : s') :-> s'
forall a (s :: [*]). (a : s) :-> s
drop
where
verifySingleToken :: Natural : s :-> s
verifySingleToken :: (Natural : s) :-> s
verifySingleToken =
if Expr (Natural : s) s Natural
forall a (s :: [*]). Expr (a : s) s a
take Expr (Natural : s) s Natural
-> Expr s s Natural -> Expr (Natural : s) s Bool
forall a (s0 :: [*]) (s1 :: [*]) (s2 :: [*]).
NiceComparable a =>
Expr s0 s1 a -> Expr s1 s2 a -> Expr s0 s2 Bool
|==| Natural -> Expr s s Natural
forall t (s :: [*]). NiceConstant t => t -> s :-> (t : s)
push Natural
1
then s :-> s
forall (s :: [*]). s :-> s
nop
else Label "nOT_SINGLE_TICKET_TOKEN" -> s :-> s
forall (tag :: Symbol) (s :: [*]) (any :: [*]).
(MustHaveErrorArg tag MText, CustomErrorHasDoc tag) =>
Label tag -> s :-> any
failCustomNoArg Label "nOT_SINGLE_TICKET_TOKEN"
forall a. IsLabel "nOT_SINGLE_TICKET_TOKEN" a => a
forall (x :: Symbol) a. IsLabel x a => a
#nOT_SINGLE_TICKET_TOKEN
newtype STicket (action :: k) td = STicket (Ticket td)
deriving stock ((forall x. STicket action td -> Rep (STicket action td) x)
-> (forall x. Rep (STicket action td) x -> STicket action td)
-> Generic (STicket action td)
forall x. Rep (STicket action td) x -> STicket action td
forall x. STicket action td -> Rep (STicket action td) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (action :: k) td x.
Rep (STicket action td) x -> STicket action td
forall k (action :: k) td x.
STicket action td -> Rep (STicket action td) x
$cto :: forall k (action :: k) td x.
Rep (STicket action td) x -> STicket action td
$cfrom :: forall k (action :: k) td x.
STicket action td -> Rep (STicket action td) x
Generic)
deriving anyclass (ToT (STicket action td) ~ ToT (Unwrappabled (STicket action td))
(ToT (STicket action td) ~ ToT (Unwrappabled (STicket action td)))
-> Unwrappable (STicket action td)
forall s. (ToT s ~ ToT (Unwrappabled s)) -> Unwrappable s
forall k (action :: k) td.
ToT (STicket action td) ~ ToT (Unwrappabled (STicket action td))
Unwrappable)
deriving newtype instance
NiceComparable td =>
IsoValue (STicket action td)
deriving newtype instance
(HasAnnotation td, NiceComparable td) =>
HasAnnotation (STicket action td)
instance (a `CanCastTo` a2, td `CanCastTo` td2) =>
STicket a td `CanCastTo` STicket a2 td2
instance (NiceComparable d, Typeable k, Typeable action) =>
NonZero (STicket (action :: k) d) where
nonZero :: (STicket action d : s) :-> (Maybe (STicket action d) : s)
nonZero = do (STicket action d : s) :-> (Ticket d : s)
forall a (s :: [*]).
Unwrappable a =>
(a : s) :-> (Unwrappabled a : s)
coerceUnwrap; (Ticket d : s) :-> (Maybe (Ticket d) : s)
forall t (s :: [*]). NonZero t => (t : s) :-> (Maybe t : s)
nonZero; ((Ticket d : s) :-> (STicket action d : s))
-> (Maybe (Ticket d) : s) :-> (Maybe (STicket action d) : s)
forall (c :: * -> *) b a (s :: [*]).
(LorentzFunctor c, KnownValue b) =>
((a : s) :-> (b : s)) -> (c a : s) :-> (c b : s)
lmap (Ticket d : s) :-> (STicket action d : s)
forall a (s :: [*]).
Unwrappable a =>
(Unwrappabled a : s) :-> (a : s)
unsafeCoerceWrap
instance (Typeable k, Typeable action, TypeHasDoc td) =>
TypeHasDoc (STicket (action :: k) td) where
typeDocMdDescription :: Markdown
typeDocMdDescription = [md|
Ticket kept in storage that remembers permissions to spend something.
The first type argument describes the kind of action or currency that is
being permitted to perform/spend.
|]
typeDocMdReference :: Proxy (STicket action td) -> WithinParens -> Markdown
typeDocMdReference Proxy (STicket action td)
p =
(Text, DType)
-> [WithinParens -> Markdown] -> WithinParens -> Markdown
customTypeDocMdReference' (Text
"STicket", Proxy (STicket action td) -> DType
forall a. TypeHasDoc a => Proxy a -> DType
DType Proxy (STicket action td)
p)
[ \WithinParens
wp -> Markdown -> Markdown
mdTicked (Markdown -> Markdown) -> Markdown -> Markdown
forall a b. (a -> b) -> a -> b
$ WithinParens -> Markdown
forall k (a :: k). Typeable a => WithinParens -> Markdown
buildTypeWithinParens @action WithinParens
wp
, Proxy td -> WithinParens -> Markdown
forall a. TypeHasDoc a => Proxy a -> WithinParens -> Markdown
typeDocMdReference (Proxy td
forall k (t :: k). Proxy t
P.Proxy @td)
]
typeDocDependencies :: Proxy (STicket action td) -> [SomeDocDefinitionItem]
typeDocDependencies Proxy (STicket action td)
_ = [TypeHasDoc (Ticket Natural) => SomeDocDefinitionItem
forall t. TypeHasDoc t => SomeDocDefinitionItem
dTypeDep @(Ticket Natural)]
typeDocHaskellRep :: TypeDocHaskellRep (STicket action td)
typeDocHaskellRep =
forall b.
(Typeable (STicket "myTokens" Natural),
GenericIsoValue (STicket "myTokens" Natural),
GTypeHasDoc (Rep (STicket "myTokens" Natural))) =>
TypeDocHaskellRep b
forall a b.
(Typeable a, GenericIsoValue a, GTypeHasDoc (Rep a)) =>
TypeDocHaskellRep b
unsafeConcreteTypeDocHaskellRep @(STicket "myTokens" Natural)
typeDocMichelsonRep :: TypeDocMichelsonRep (STicket action td)
typeDocMichelsonRep =
forall b.
(Typeable (STicket "myTokens" Natural),
KnownIsoT (STicket "myTokens" Natural)) =>
TypeDocMichelsonRep b
forall k a (b :: k).
(Typeable a, KnownIsoT a) =>
TypeDocMichelsonRep b
unsafeConcreteTypeDocMichelsonRep @(STicket "myTokens" Natural)
toSTicket
:: (IsoValue td)
=> Ticket td : s
:-> Address : td : STicket action td : s
toSTicket :: (Ticket td : s) :-> (Address : td : STicket action td : s)
toSTicket = do
(Ticket td : s) :-> (ReadTicket td : Ticket td : s)
forall a (s :: [*]).
(Ticket a : s) :-> (ReadTicket a : Ticket a : s)
readTicket
((Ticket td : s) :-> (STicket action td : s))
-> (ReadTicket td : Ticket td : s)
:-> (ReadTicket td : STicket action td : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip (Ticket td : s) :-> (STicket action td : s)
forall a (s :: [*]).
Unwrappable a =>
(Unwrappabled a : s) :-> (a : s)
unsafeCoerceWrap
(ReadTicket td : STicket action td : s)
:-> (Address : td : Natural : STicket action td : s)
forall dt (fields :: [*]) (st :: [*]).
(InstrDeconstructC dt, KnownList fields,
fields ~ ConstructorFieldTypes dt) =>
(dt : st) :-> (fields ++ st)
deconstruct
((Natural : STicket action td : s) :-> (STicket action td : s))
-> (Address : td : Natural : STicket action td : s)
:-> (Address : td : STicket action td : s)
forall (n :: Nat) (inp :: [*]) (out :: [*]) (s :: [*]) (s' :: [*]).
ConstraintDIPNLorentz (ToPeano n) inp out s s' =>
(s :-> s') -> inp :-> out
dipN @2 (Natural : STicket action td : s) :-> (STicket action td : s)
forall a (s :: [*]). (a : s) :-> s
drop
readSTicket
:: STicket action td : s
:-> ReadTicket td : STicket action td : s
readSTicket :: (STicket action td : s) :-> (ReadTicket td : STicket action td : s)
readSTicket = do
(STicket action td : s) :-> (Ticket td : s)
forall a (s :: [*]).
Unwrappable a =>
(a : s) :-> (Unwrappabled a : s)
coerceUnwrap; (Ticket td : s) :-> (ReadTicket td : Ticket td : s)
forall a (s :: [*]).
(Ticket a : s) :-> (ReadTicket a : Ticket a : s)
readTicket; ((Ticket td : s) :-> (STicket action td : s))
-> (ReadTicket td : Ticket td : s)
:-> (ReadTicket td : STicket action td : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip (Ticket td : s) :-> (STicket action td : s)
forall a (s :: [*]).
Unwrappable a =>
(Unwrappabled a : s) :-> (a : s)
unsafeCoerceWrap
sTicketAmount
:: (IsoValue td)
=> Maybe (STicket action td) : s
:-> Natural : s
sTicketAmount :: (Maybe (STicket action td) : s) :-> (Natural : s)
sTicketAmount =
if Condition
(Maybe (STicket action td) : s)
(STicket action td : s)
s
(Natural : s)
(Natural : s)
forall a (s :: [*]) (o :: [*]).
Condition (Maybe a : s) (a : s) s o o
IsSome then (STicket action td : s) :-> (Natural : s)
forall k td (action :: k) (s :: [*]).
IsoValue td =>
(STicket action td : s) :-> (Natural : s)
sTicketAmountPlain else Natural -> s :-> (Natural : s)
forall t (s :: [*]). NiceConstant t => t -> s :-> (t : s)
push Natural
0
sTicketAmountPlain
:: (IsoValue td)
=> STicket action td : s
:-> Natural : s
sTicketAmountPlain :: (STicket action td : s) :-> (Natural : s)
sTicketAmountPlain = do
(STicket action td : s) :-> (ReadTicket td : STicket action td : s)
forall k (action :: k) td (s :: [*]).
(STicket action td : s) :-> (ReadTicket td : STicket action td : s)
readSTicket; Label "rtAmount"
-> (ReadTicket td : STicket action td : s)
:-> (GetFieldType (ReadTicket td) "rtAmount"
: STicket action td : s)
forall dt (name :: Symbol) (st :: [*]).
InstrGetFieldC dt name =>
Label name -> (dt : st) :-> (GetFieldType dt name : st)
toField Label "rtAmount"
forall a. IsLabel "rtAmount" a => a
forall (x :: Symbol) a. IsLabel x a => a
#rtAmount; ((STicket action td : s) :-> s)
-> (Natural : STicket action td : s) :-> (Natural : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip (STicket action td : s) :-> s
forall a (s :: [*]). (a : s) :-> s
drop
subtractSTicket
:: (IsoValue d, KnownValue (STicket action d))
=> (forall s0. ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0))
-> Natural : Maybe (STicket action d) : s
:-> Maybe (STicket action d) : s
subtractSTicket :: (forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0))
-> (Natural : Maybe (STicket action d) : s)
:-> (Maybe (STicket action d) : s)
subtractSTicket forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0)
onInsufficientTokens = do
(Natural : Maybe (STicket action d) : s)
:-> (Maybe (STicket action d) : Natural : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap
if Condition
(Maybe (STicket action d) : Natural : s)
(Natural : s)
(STicket action d : Natural : s)
(Maybe (STicket action d) : s)
(Maybe (STicket action d) : s)
forall a (s :: [*]) (o :: [*]).
Condition (Maybe a : s) s (a : s) o o
IsNone
then do forall (s0 :: [*]). (Natural : s0) :-> s0
forall a (s :: [*]). (a : s) :-> s
drop @Natural; s :-> (Maybe (STicket action d) : s)
forall a (s :: [*]). KnownValue a => s :-> (Maybe a : s)
none
else do (STicket action d : Natural : s)
:-> (Natural : STicket action d : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap; (forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0))
-> (Natural : STicket action d : s) :-> (STicket action d : s)
forall k d (action :: k) (s :: [*]).
IsoValue d =>
(forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0))
-> (Natural : STicket action d : s) :-> (STicket action d : s)
subtractSTicketPlain forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0)
onInsufficientTokens; (STicket action d : s) :-> (Maybe (STicket action d) : s)
forall a (s :: [*]). (a : s) :-> (Maybe a : s)
some
subtractSTicketPlain
:: (IsoValue d)
=> (forall s0. ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0))
-> Natural : STicket action d : s
:-> STicket action d : s
subtractSTicketPlain :: (forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0))
-> (Natural : STicket action d : s) :-> (STicket action d : s)
subtractSTicketPlain forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0)
onInsufficientTokens = do
Label "spent"
-> (Natural : STicket action d : s)
:-> (("spent" :! Natural) : STicket action d : s)
forall (name :: Symbol) a (s :: [*]).
Label name -> (a : s) :-> ((name :! a) : s)
toNamed Label "spent"
forall a. IsLabel "spent" a => a
forall (x :: Symbol) a. IsLabel x a => a
#spent
((STicket action d : s)
:-> (("permitted" :! Natural) : Ticket d : s))
-> (("spent" :! Natural) : STicket action d : s)
:-> (("spent" :! Natural)
: ("permitted" :! Natural) : Ticket d : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip do
(STicket action d : s) :-> (Ticket d : s)
forall a (s :: [*]).
Unwrappable a =>
(a : s) :-> (Unwrappabled a : s)
coerceUnwrap;
(Ticket d : s) :-> (ReadTicket d : Ticket d : s)
forall a (s :: [*]).
(Ticket a : s) :-> (ReadTicket a : Ticket a : s)
readTicket; Label "rtAmount"
-> (ReadTicket d : Ticket d : s)
:-> (GetFieldType (ReadTicket d) "rtAmount" : Ticket d : s)
forall dt (name :: Symbol) (st :: [*]).
InstrGetFieldC dt name =>
Label name -> (dt : st) :-> (GetFieldType dt name : st)
toField Label "rtAmount"
forall a. IsLabel "rtAmount" a => a
forall (x :: Symbol) a. IsLabel x a => a
#rtAmount; Label "permitted"
-> (Natural : Ticket d : s)
:-> (("permitted" :! Natural) : Ticket d : s)
forall (name :: Symbol) a (s :: [*]).
Label name -> (a : s) :-> ((name :! a) : s)
toNamed Label "permitted"
forall a. IsLabel "permitted" a => a
forall (x :: Symbol) a. IsLabel x a => a
#permitted
(("spent" :! Natural) : ("permitted" :! Natural) : Ticket d : s)
:-> (("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap; (("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("permitted" :! Natural)
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
forall a b (s :: [*]).
(Dupable a, Dupable b) =>
(a : b : s) :-> (a : b : a : b : s)
dupTop2
forall (s :: [*]). (Integer : s) :-> (Maybe Natural : s)
isNat (forall (s :: [*]). (Integer : s) :-> (Maybe Natural : s))
-> Expr
(("permitted" :! Natural)
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
(("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
Integer
-> Expr
(("permitted" :! Natural)
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
(("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
(Maybe Natural)
forall a r (s0 :: [*]) (s1 :: [*]).
(forall (s :: [*]). (a : s) :-> (r : s))
-> Expr s0 s1 a -> Expr s0 s1 r
$: (Label "permitted"
-> (("permitted" :! Natural)
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
:-> (Natural
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
forall (name :: Symbol) a (s :: [*]).
Label name -> ((name :! a) : s) :-> (a : s)
fromNamed Label "permitted"
forall a. IsLabel "permitted" a => a
forall (x :: Symbol) a. IsLabel x a => a
#permitted ((("permitted" :! Natural)
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
:-> (Natural
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s))
-> Expr
(("spent" :! Natural)
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
(("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
Natural
-> Expr
(("permitted" :! Natural)
: ("spent" :! Natural) : ("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
(("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
Integer
forall a b r (s0 :: [*]) (s1 :: [*]) (s2 :: [*]).
ArithOpHs Sub a b r =>
Expr s0 s1 a -> Expr s1 s2 b -> Expr s0 s2 r
|-| Label "spent"
-> Expr
(("spent" :! Natural)
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
(("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
Natural
forall (name :: Symbol) a (s :: [*]).
Label name -> ((name :! a) : s) :-> (a : s)
fromNamed Label "spent"
forall a. IsLabel "spent" a => a
forall (x :: Symbol) a. IsLabel x a => a
#spent)
if Condition
(Maybe Natural
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
(Natural
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
(("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
(("remainder" :! Natural) : ("spent" :! Natural) : Ticket d : s)
(("remainder" :! Natural) : ("spent" :! Natural) : Ticket d : s)
forall a (s :: [*]) (o :: [*]).
Condition (Maybe a : s) (a : s) s o o
IsSome
then do Label "remainder"
-> (Natural
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("remainder" :! Natural)
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
forall (name :: Symbol) a (s :: [*]).
Label name -> (a : s) :-> ((name :! a) : s)
toNamed Label "remainder"
forall a. IsLabel "remainder" a => a
forall (x :: Symbol) a. IsLabel x a => a
#remainder; ((("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("spent" :! Natural) : Ticket d : s))
-> (("remainder" :! Natural)
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("remainder" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip (((("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("spent" :! Natural) : Ticket d : s))
-> (("remainder" :! Natural)
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("remainder" :! Natural)
: ("spent" :! Natural) : Ticket d : s))
-> ((("permitted" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
:-> (("spent" :! Natural) : Ticket d : s))
-> (("remainder" :! Natural)
: ("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("remainder" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
forall a b. (a -> b) -> a -> b
$ forall (s :: [*]). (("permitted" :! Natural) : s) :-> s
forall a (s :: [*]). (a : s) :-> s
drop @("permitted" :! _)
else do (("permitted" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("permitted" :! Natural, "spent" :! Natural) : Ticket d : s)
forall a b (s :: [*]). (a : b : s) :-> ((a, b) : s)
pair; (("permitted" :! Natural, "spent" :! Natural) : Ticket d : s)
:-> (("remainder" :! Natural)
: ("spent" :! Natural) : Ticket d : s)
forall (s0 :: [*]).
ErrInstr (("permitted" :! Natural, "spent" :! Natural) : s0)
onInsufficientTokens
(("remainder" :! Natural) : ("spent" :! Natural) : Ticket d : s)
:-> (("remainder" :! Natural, "spent" :! Natural) : Ticket d : s)
forall a b (s :: [*]). (a : b : s) :-> ((a, b) : s)
pair; (("remainder" :! Natural, "spent" :! Natural) : Ticket d : s)
:-> (Ticket d : ("remainder" :! Natural, "spent" :! Natural) : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap; (Ticket d : ("remainder" :! Natural, "spent" :! Natural) : s)
:-> (Maybe ("remainder" :! Ticket d, "spent" :! Ticket d) : s)
forall (n1 :: Symbol) (n2 :: Symbol) a (s :: [*]).
(Ticket a : (n1 :! Natural, n2 :! Natural) : s)
:-> (Maybe (n1 :! Ticket a, n2 :! Ticket a) : s)
splitTicketNamed
Impossible "by construction of token parts"
-> (Maybe ("remainder" :! Ticket d, "spent" :! Ticket d) : s)
:-> (("remainder" :! Ticket d, "spent" :! Ticket d) : s)
forall err a (s :: [*]).
IsError err =>
err -> (Maybe a : s) :-> (a : s)
assertSome (HasCallStack => Impossible "by construction of token parts"
forall (reason :: Symbol). HasCallStack => Impossible reason
Impossible @"by construction of token parts")
(("remainder" :! Ticket d, "spent" :! Ticket d) : s)
:-> (("remainder" :! Ticket d) : s)
forall a b (s :: [*]). ((a, b) : s) :-> (a : s)
car; Label "remainder"
-> (("remainder" :! Ticket d) : s) :-> (Ticket d : s)
forall (name :: Symbol) a (s :: [*]).
Label name -> ((name :! a) : s) :-> (a : s)
fromNamed Label "remainder"
forall a. IsLabel "remainder" a => a
forall (x :: Symbol) a. IsLabel x a => a
#remainder
(Ticket d : s) :-> (STicket action d : s)
forall a (s :: [*]).
Unwrappable a =>
(Unwrappabled a : s) :-> (a : s)
unsafeCoerceWrap
addSTicket
:: STicket action d : Maybe (STicket action d) : s
:-> Maybe (STicket action d) : s
addSTicket :: (STicket action d : Maybe (STicket action d) : s)
:-> (Maybe (STicket action d) : s)
addSTicket = do
(STicket action d : Maybe (STicket action d) : s)
:-> (Maybe (STicket action d) : STicket action d : s)
forall a b (s :: [*]). (a : b : s) :-> (b : a : s)
swap; ((STicket action d : STicket action d : s)
:-> (STicket action d : s))
-> ((STicket action d : s) :-> (STicket action d : s))
-> (Maybe (STicket action d) : STicket action d : s)
:-> (STicket action d : s)
forall a (s :: [*]) (s' :: [*]).
((a : s) :-> s') -> (s :-> s') -> (Maybe a : s) :-> s'
ifSome (STicket action d : STicket action d : s)
:-> (STicket action d : s)
forall k (action :: k) d (s :: [*]).
(STicket action d : STicket action d : s)
:-> (STicket action d : s)
addSTicketPlain (STicket action d : s) :-> (STicket action d : s)
forall (s :: [*]). s :-> s
nop; (STicket action d : s) :-> (Maybe (STicket action d) : s)
forall a (s :: [*]). (a : s) :-> (Maybe a : s)
some
addSTicketPlain
:: STicket action d : STicket action d : s
:-> STicket action d : s
addSTicketPlain :: (STicket action d : STicket action d : s)
:-> (STicket action d : s)
addSTicketPlain = do
(STicket action d : STicket action d : s)
:-> (Ticket d : STicket action d : s)
forall a (s :: [*]).
Unwrappable a =>
(a : s) :-> (Unwrappabled a : s)
coerceUnwrap; ((STicket action d : s) :-> (Ticket d : s))
-> (Ticket d : STicket action d : s) :-> (Ticket d : Ticket d : s)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a : s) :-> (a : s')
dip (STicket action d : s) :-> (Ticket d : s)
forall a (s :: [*]).
Unwrappable a =>
(a : s) :-> (Unwrappabled a : s)
coerceUnwrap
(Ticket d : Ticket d : s) :-> ((Ticket d, Ticket d) : s)
forall a b (s :: [*]). (a : b : s) :-> ((a, b) : s)
pair; ((Ticket d, Ticket d) : s) :-> (Maybe (Ticket d) : s)
forall a (s :: [*]).
((Ticket a, Ticket a) : s) :-> (Maybe (Ticket a) : s)
joinTickets
MText -> (Maybe (Ticket d) : s) :-> (Ticket d : s)
forall err a (s :: [*]).
IsError err =>
err -> (Maybe a : s) :-> (a : s)
assertSome [mt|badtjoin|]
(Ticket d : s) :-> (STicket action d : s)
forall a (s :: [*]).
Unwrappable a =>
(Unwrappabled a : s) :-> (a : s)
unsafeCoerceWrap