Safe Haskell | None |
---|---|
Language | Haskell2010 |
Common Michelson macros defined using Lorentz syntax.
Synopsis
- type NiceComparable n = (KnownValue n, Comparable (ToT n))
- eq :: NiceComparable n => (n & (n & s)) :-> (Bool & s)
- neq :: NiceComparable n => (n & (n & s)) :-> (Bool & s)
- lt :: NiceComparable n => (n & (n & s)) :-> (Bool & s)
- gt :: NiceComparable n => (n & (n & s)) :-> (Bool & s)
- le :: NiceComparable n => (n & (n & s)) :-> (Bool & s)
- ge :: NiceComparable n => (n & (n & s)) :-> (Bool & s)
- ifEq0 :: IfCmp0Constraints a Eq' => (s :-> s') -> (s :-> s') -> (a & s) :-> s'
- ifGe0 :: IfCmp0Constraints a Ge => (s :-> s') -> (s :-> s') -> (a & s) :-> s'
- ifGt0 :: IfCmp0Constraints a Gt => (s :-> s') -> (s :-> s') -> (a & s) :-> s'
- ifLe0 :: IfCmp0Constraints a Le => (s :-> s') -> (s :-> s') -> (a & s) :-> s'
- ifLt0 :: IfCmp0Constraints a Lt => (s :-> s') -> (s :-> s') -> (a & s) :-> s'
- ifNeq0 :: IfCmp0Constraints a Neq => (s :-> s') -> (s :-> s') -> (a & s) :-> s'
- ifEq :: NiceComparable a => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s'
- ifGe :: NiceComparable a => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s'
- ifGt :: NiceComparable a => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s'
- ifLe :: NiceComparable a => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s'
- ifLt :: NiceComparable a => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s'
- ifNeq :: NiceComparable a => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s'
- fail_ :: a :-> c
- assert :: IsError err => err -> (Bool & s) :-> s
- assertEq0 :: (IfCmp0Constraints a Eq', IsError err) => err -> (a & s) :-> s
- assertNeq0 :: (IfCmp0Constraints a Neq, IsError err) => err -> (a & s) :-> s
- assertLt0 :: (IfCmp0Constraints a Lt, IsError err) => err -> (a & s) :-> s
- assertGt0 :: (IfCmp0Constraints a Gt, IsError err) => err -> (a & s) :-> s
- assertLe0 :: (IfCmp0Constraints a Le, IsError err) => err -> (a & s) :-> s
- assertGe0 :: (IfCmp0Constraints a Ge, IsError err) => err -> (a & s) :-> s
- assertEq :: (NiceComparable a, IsError err) => err -> (a & (a & s)) :-> s
- assertNeq :: (NiceComparable a, IsError err) => err -> (a & (a & s)) :-> s
- assertLt :: (NiceComparable a, IsError err) => err -> (a & (a & s)) :-> s
- assertGt :: (NiceComparable a, IsError err) => err -> (a & (a & s)) :-> s
- assertLe :: (NiceComparable a, IsError err) => err -> (a & (a & s)) :-> s
- assertGe :: (NiceComparable a, IsError err) => err -> (a & (a & s)) :-> s
- assertNone :: IsError err => err -> (Maybe a & s) :-> s
- assertSome :: IsError err => err -> (Maybe a & s) :-> (a & s)
- assertLeft :: IsError err => err -> (Either a b & s) :-> (a & s)
- assertRight :: IsError err => err -> (Either a b & s) :-> (b & s)
- assertUsing :: IsError a => a -> (Bool & s) :-> s
- type ConstraintDuupXLorentz (n :: Peano) (s :: [Type]) (a :: Type) (s1 :: [Type]) (tail :: [Type]) = (DuupXConstraint' T n (ToTs s) (ToT a) (ToTs s1) (ToTs tail), DuupXConstraint' Type n s a s1 tail)
- type ConstraintReplaceNLorentz (n :: Peano) (s :: [Type]) (a :: Type) (mid :: [Type]) (tail :: [Type]) = (ReplaceNConstraint' T n (ToTs s) (ToT a) (ToTs mid) (ToTs tail), ReplaceNConstraint' Type n s a mid tail)
- type ConstraintUpdateNLorentz (n :: Peano) (s :: [Type]) (a :: Type) (b :: Type) (mid :: [Type]) (tail :: [Type]) = (UpdateNConstraint' T n (ToTs s) (ToT a) (ToT b) (ToTs mid) (ToTs tail), UpdateNConstraint' Type n s a b mid tail)
- class DuupX (n :: Peano) (s :: [Type]) (a :: Type) s1 tail where
- class ReplaceN (n :: Peano) (s :: [Type]) (a :: Type) mid tail where
- replaceNImpl :: (a ': s) :-> s
- class UpdateN (n :: Peano) (s :: [Type]) (a :: Type) (b :: Type) mid tail where
- updateNImpl :: ('[a, b] :-> '[b]) -> (a ': s) :-> s
- dropX :: forall (n :: Nat) a inp out s s'. (ConstraintDIPNLorentz (ToPeano n) inp out s s', s ~ (a ': s')) => inp :-> out
- cloneX :: forall (n :: Nat) a s. CloneX (ToPeano n) a s => (a & s) :-> CloneXT (ToPeano n) a s
- duupX :: forall (n :: Nat) a (s :: [Type]) (s1 :: [Type]) (tail :: [Type]). (ConstraintDuupXLorentz (ToPeano (n - 1)) s a s1 tail, DuupX (ToPeano n) s a s1 tail) => s :-> (a ': s)
- framedN :: forall n nNat s i i' o o'. (nNat ~ ToPeano n, i' ~ Take nNat i, s ~ Drop nNat i, i ~ (i' ++ s), o ~ (o' ++ s), KnownList i', KnownList o') => (i' :-> o') -> i :-> o
- caar :: (((a, b1), b2) & s) :-> (a & s)
- cadr :: (((a, b1), b2) & s) :-> (b1 & s)
- cdar :: ((a1, (a2, b)) & s) :-> (a2 & s)
- cddr :: ((a1, (a2, b)) & s) :-> (b & s)
- ifRight :: ((b & s) :-> s') -> ((a & s) :-> s') -> (Either a b & s) :-> s'
- ifSome :: ((a & s) :-> s') -> (s :-> s') -> (Maybe a & s) :-> s'
- when_ :: (s :-> s) -> (Bool ': s) :-> s
- unless_ :: (s :-> s) -> (Bool ': s) :-> s
- whenSome :: ((a ': s) :-> s) -> (Maybe a ': s) :-> s
- whenNone :: (s :-> (a ': s)) -> (Maybe a ': s) :-> (a ': s)
- mapCar :: ((a & s) :-> (a1 & s)) -> ((a, b) & s) :-> ((a1, b) & s)
- mapCdr :: ((b & ((a, b) & s)) :-> (b1 & ((a, b) & s))) -> ((a, b) & s) :-> ((a, b1) & s)
- papair :: (a & (b & (c & s))) :-> (((a, b), c) & s)
- ppaiir :: (a & (b & (c & s))) :-> ((a, (b, c)) & s)
- unpair :: ((a, b) & s) :-> (a & (b & s))
- setCar :: ((a, b1) & (b2 & s)) :-> ((b2, b1) & s)
- setCdr :: ((a, b1) & (b2 & s)) :-> ((a, b2) & s)
- setInsert :: NiceComparable e => (e & (Set e & s)) :-> (Set e & s)
- mapInsert :: (MapInstrs map, NiceComparable k) => (k ': (v ': (map k v ': s))) :-> (map k v ': s)
- setInsertNew :: (NiceComparable e, KnownValue err) => (forall s0. (e ': s0) :-> (err ': s0)) -> (e & (Set e & s)) :-> (Set e & s)
- mapInsertNew :: (MapInstrs map, NiceComparable k, KnownValue e) => (forall s0. (k ': s0) :-> (e ': s0)) -> (k ': (v ': (map k v ': s))) :-> (map k v ': s)
- deleteMap :: forall k v s. (MapInstrs map, NiceComparable k, KnownValue v) => (k ': (map k v ': s)) :-> (map k v ': s)
- setDelete :: NiceComparable e => (e & (Set e & s)) :-> (Set e & s)
- replaceN :: forall (n :: Nat) a (s :: [Type]) (s1 :: [Type]) (tail :: [Type]). (ConstraintReplaceNLorentz (ToPeano (n - 1)) s a s1 tail, ReplaceN (ToPeano n) s a s1 tail) => (a ': s) :-> s
- updateN :: forall (n :: Nat) a b (s :: [Type]) (mid :: [Type]) (tail :: [Type]). (ConstraintUpdateNLorentz (ToPeano (n - 1)) s a b mid tail, UpdateN (ToPeano n) s a b mid tail) => ('[a, b] :-> '[b]) -> (a ': s) :-> s
- data View (a :: Type) (r :: Type) = View {
- viewParam :: a
- viewCallbackTo :: ContractRef r
- data Void_ (a :: Type) (b :: Type) = Void_ {
- voidParam :: a
- voidResProxy :: Lambda b b
- newtype VoidResult r = VoidResult {
- unVoidResult :: r
- view_ :: NiceParameter r => (forall s0. (a & (storage & s0)) :-> (r ': s0)) -> (View a r & (storage & s)) :-> ((List Operation, storage) & s)
- mkView :: ToContractRef r contract => a -> contract -> View a r
- wrapView :: ((a, ContractRef r) ': s) :-> (View a r ': s)
- unwrapView :: (View a r ': s) :-> ((a, ContractRef r) ': s)
- void_ :: forall a b s s' anything. (IsError (VoidResult b), KnownValue b) => ((a & s) :-> (b & s')) -> (Void_ a b & s) :-> anything
- mkVoid :: forall b a. a -> Void_ a b
- wrapVoid :: ((a, Lambda b b) ': s) :-> (Void_ a b ': s)
- unwrapVoid :: (Void_ a b ': s) :-> ((a, Lambda b b) ': s)
- voidResultTag :: MText
- buildView :: WellTypedIsoValue r => (a -> Builder) -> View a r -> Builder
- buildViewTuple :: (WellTypedIsoValue r, TupleF a) => View a r -> Builder
- addressToEpAddress :: (Address ': s) :-> (EpAddress ': s)
- pushContractRef :: NiceParameter arg => (forall s0. (FutureContract arg ': s) :-> s0) -> ContractRef arg -> s :-> (ContractRef arg ': s)
Compare
type NiceComparable n = (KnownValue n, Comparable (ToT n)) Source #
Fail
Warning: fail_
remains in code
Analog of the FAIL macro in Michelson. Its usage is discouraged because it doesn't carry any information about failure.
Assertion macros
They differ from the same macros in Michelson, because those
macros use FAIL macro which is not informative (fails with unit).
If you really want Michelson versions (maybe to produce exact
copy of an existing contract), you can pass UnspecifiedError
, then
FAILWITH will be called with unit.
Syntactic Conveniences
type ConstraintDuupXLorentz (n :: Peano) (s :: [Type]) (a :: Type) (s1 :: [Type]) (tail :: [Type]) = (DuupXConstraint' T n (ToTs s) (ToT a) (ToTs s1) (ToTs tail), DuupXConstraint' Type n s a s1 tail) Source #
Constraint for duupX that combines kind-agnostic constraint for Lorentz (Haskell) types and for our typed Michelson.
type ConstraintReplaceNLorentz (n :: Peano) (s :: [Type]) (a :: Type) (mid :: [Type]) (tail :: [Type]) = (ReplaceNConstraint' T n (ToTs s) (ToT a) (ToTs mid) (ToTs tail), ReplaceNConstraint' Type n s a mid tail) Source #
Constraint for replaceN that combines kind-agnostic constraint for Lorentz (Haskell) types and for our typed Michelson.
type ConstraintUpdateNLorentz (n :: Peano) (s :: [Type]) (a :: Type) (b :: Type) (mid :: [Type]) (tail :: [Type]) = (UpdateNConstraint' T n (ToTs s) (ToT a) (ToT b) (ToTs mid) (ToTs tail), UpdateNConstraint' Type n s a b mid tail) Source #
Constraint for updateN that combines kind-agnostic constraint for Lorentz (Haskell) types and for our typed Michelson.
class DuupX (n :: Peano) (s :: [Type]) (a :: Type) s1 tail where Source #
Instances
s ~ (a ': xs) => DuupX ('S 'Z) s a (s1 :: k1) (tail :: k2) Source # | |
Defined in Lorentz.Macro | |
DuupX ('S ('S 'Z)) (b ': (a ': xs)) a (s1 :: k1) (tail :: k2) Source # | |
Defined in Lorentz.Macro | |
ConstraintDuupXLorentz ('S ('S n)) s a s1 tail => DuupX ('S ('S ('S n))) s a (s1 :: [Type]) (tail :: [Type]) Source # | |
Defined in Lorentz.Macro |
class ReplaceN (n :: Peano) (s :: [Type]) (a :: Type) mid tail where Source #
replaceNImpl :: (a ': s) :-> s Source #
Instances
s ~ (a ': xs) => ReplaceN ('S 'Z) s a (mid :: k1) (tail :: k2) Source # | |
Defined in Lorentz.Macro replaceNImpl :: (a ': s) :-> s Source # | |
ConstraintReplaceNLorentz ('S n) s a mid tail => ReplaceN ('S ('S n)) s a (mid :: [Type]) (tail :: [Type]) Source # | |
Defined in Lorentz.Macro replaceNImpl :: (a ': s) :-> s Source # |
class UpdateN (n :: Peano) (s :: [Type]) (a :: Type) (b :: Type) mid tail where Source #
updateNImpl :: ('[a, b] :-> '[b]) -> (a ': s) :-> s Source #
Instances
s ~ (x ': (b ': tail)) => UpdateN ('S ('S 'Z)) s a b (mid :: k) (tail :: [Type]) Source # | |
Defined in Lorentz.Macro updateNImpl :: ('[a, b] :-> '[b]) -> (a ': s) :-> s Source # | |
s ~ (b ': tail) => UpdateN ('S 'Z) s a b (mid :: k) (tail :: [Type]) Source # | |
Defined in Lorentz.Macro updateNImpl :: ('[a, b] :-> '[b]) -> (a ': s) :-> s Source # | |
ConstraintUpdateNLorentz ('S ('S n)) s a b mid tail => UpdateN ('S ('S ('S n))) s a b (mid :: [Type]) (tail :: [Type]) Source # | |
Defined in Lorentz.Macro updateNImpl :: ('[a, b] :-> '[b]) -> (a ': s) :-> s Source # |
dropX :: forall (n :: Nat) a inp out s s'. (ConstraintDIPNLorentz (ToPeano n) inp out s s', s ~ (a ': s')) => inp :-> out Source #
Custom Lorentz macro that drops element with given index (starting from 0) from the stack.
cloneX :: forall (n :: Nat) a s. CloneX (ToPeano n) a s => (a & s) :-> CloneXT (ToPeano n) a s Source #
Duplicate the top of the stack n
times.
For example, `cloneX @3` has type `a & s :-> a & a & a & a & s`.
duupX :: forall (n :: Nat) a (s :: [Type]) (s1 :: [Type]) (tail :: [Type]). (ConstraintDuupXLorentz (ToPeano (n - 1)) s a s1 tail, DuupX (ToPeano n) s a s1 tail) => s :-> (a ': s) Source #
DUU+P
macro. For example, `duupX @3` is DUUUP
, it puts
the 3-rd (starting from 1) element to the top of the stack.
Note that it is implemented differently for `n ≤ 2` and for `n > 2`.
In the latter case it is implemented using dipN
, dig
and dup
.
In the former case it uses specialized versions.
There is also a minor difference with the implementation of `DUU*P` in
Michelson.
They implement DUUUUP
as `DIP 3 { DUP }; DIG 4`.
We implement it as `DIP 3 { DUP }; DIG 3`. These are equivalent.
Our version is supposedly cheaper, at least it should be packed
more efficiently due to the way numbers are packed.
framedN :: forall n nNat s i i' o o'. (nNat ~ ToPeano n, i' ~ Take nNat i, s ~ Drop nNat i, i ~ (i' ++ s), o ~ (o' ++ s), KnownList i', KnownList o') => (i' :-> o') -> i :-> o Source #
Version of framed
which accepts number of elements on input stack
which should be preserved.
You can treat this macro as calling a Michelson function with given number of arguments.
setInsert :: NiceComparable e => (e & (Set e & s)) :-> (Set e & s) Source #
Insert given element into set.
This is a separate function from updateMap
because stacks they operate with
differ in length.
mapInsert :: (MapInstrs map, NiceComparable k) => (k ': (v ': (map k v ': s))) :-> (map k v ': s) Source #
Insert given element into map.
setInsertNew :: (NiceComparable e, KnownValue err) => (forall s0. (e ': s0) :-> (err ': s0)) -> (e & (Set e & s)) :-> (Set e & s) Source #
Insert given element into set, ensuring that it does not overwrite any existing entry.
As first argument accepts container name.
mapInsertNew :: (MapInstrs map, NiceComparable k, KnownValue e) => (forall s0. (k ': s0) :-> (e ': s0)) -> (k ': (v ': (map k v ': s))) :-> (map k v ': s) Source #
Insert given element into map, ensuring that it does not overwrite any existing entry.
As first argument accepts container name (for error message).
deleteMap :: forall k v s. (MapInstrs map, NiceComparable k, KnownValue v) => (k ': (map k v ': s)) :-> (map k v ': s) Source #
Delete element from the map.
setDelete :: NiceComparable e => (e & (Set e & s)) :-> (Set e & s) Source #
Delete given element from the set.
replaceN :: forall (n :: Nat) a (s :: [Type]) (s1 :: [Type]) (tail :: [Type]). (ConstraintReplaceNLorentz (ToPeano (n - 1)) s a s1 tail, ReplaceN (ToPeano n) s a s1 tail) => (a ': s) :-> s Source #
Replace nth element (0-indexed) with the one on the top of the stack.
For example, `replaceN 3` replaces the 3rd element with the 0th one.
`replaceN
0` is not a valid operation (and it is not implemented).
`replaceN 1` is equivalent to `swap # drop` (and is the only one implemented
like this).
In all other cases `replaceN
n` will drop the nth element (`dipN n drop`)
and then put the 0th one in its place (`dug
(n-1)`).
updateN :: forall (n :: Nat) a b (s :: [Type]) (mid :: [Type]) (tail :: [Type]). (ConstraintUpdateNLorentz (ToPeano (n - 1)) s a b mid tail, UpdateN (ToPeano n) s a b mid tail) => ('[a, b] :-> '[b]) -> (a ': s) :-> s Source #
Replaces the nth element (0-indexed) with the result of the given "updating"
instruction (binary with the return type equal to the second argument) applied
to the 0th element and the nth element itself.
For example, `updateN 3 cons` replaces the 3rd element with the result of
0 instr` is not a valid operation (and it is not implemented).
`updateN cons
applied to the topmost element and the 3rd one.
`updateN 1 instr` is equivalent to
2 instr` is equivalent to `swap # dip instr` (and so is implemented).
In all other cases `updateN instr
(and so is implemented).
`updateN n instr` will put the topmost element right above
the nth one (`dug
(n-1)`) and then apply the function to them in place
(`dipN @(n-1) instr`).
Additional Morley macros
data View (a :: Type) (r :: Type) Source #
view
type synonym as described in A1.
View | |
|
Instances
data Void_ (a :: Type) (b :: Type) Source #
void
type synonym as described in A1.
Void_ | |
|
Instances
newtype VoidResult r Source #
Newtype over void result type used in tests to distinguish successful void result from other errors.
Usage example: lExpectFailWith (== VoidResult roleMaster)`
This error is special - it can contain arguments of different types depending on entrypoint which raises it.
VoidResult | |
|
Instances
view_ :: NiceParameter r => (forall s0. (a & (storage & s0)) :-> (r ': s0)) -> (View a r & (storage & s)) :-> ((List Operation, storage) & s) Source #
mkView :: ToContractRef r contract => a -> contract -> View a r Source #
Polymorphic version of View
constructor.
unwrapView :: (View a r ': s) :-> ((a, ContractRef r) ': s) Source #
void_ :: forall a b s s' anything. (IsError (VoidResult b), KnownValue b) => ((a & s) :-> (b & s')) -> (Void_ a b & s) :-> anything Source #
Buildable utils for additional Morley macros
buildViewTuple :: (WellTypedIsoValue r, TupleF a) => View a r -> Builder Source #
Macros for working with address
and contract
-like types
pushContractRef :: NiceParameter arg => (forall s0. (FutureContract arg ': s) :-> s0) -> ContractRef arg -> s :-> (ContractRef arg ': s) Source #
Push a value of contract
type.
Doing this via push
instruction is not possible, so we need to perform
extra actions here.
Aside from contract
value itself you will need to specify which error to
throw in case this value is not valid.