[#282] Add safe initial values for mutez

Problem: It would be nice to have safe initial values for mutez like zero and one,
available directly from the library and they are pretty common things to have for
Natural-like numbers.

Solution: Add `zeroMutez` and `oneMutez`.
parent 99466a49
Pipeline #168406836 passed with stages
in 18 minutes and 42 seconds
......@@ -117,7 +117,7 @@ contractDocLorentz = compileIndigoContract $ \param -> do
contractOpsLorentz :: ContractCode (Maybe KeyHash) Address
contractOpsLorentz = compileIndigoContract $ \param -> do
setDelegate param
m <- new$ 0 mutez
m <- new$ zeroMutez
is <- new$ 0 int
addr <- createLorentzContract ifTest param m is
storageVar =: addr
......
......@@ -44,7 +44,7 @@ lambdaCreateContract ::
, HasSideEffects, HasStorage Integer
) => ex -> IndigoM ()
lambdaCreateContract = defNamedEffLambda1 @Integer "create storage" $ \paramSt -> do
m <- new$ 0 mutez
m <- new$ zeroMutez
_addr <- createLorentzContract dummyContract (fst paramSt) m (snd paramSt)
storageVar @Integer += 1 int
......
......@@ -12,7 +12,7 @@ import Indigo
sideEffectsContract :: IndigoContract (Maybe MText) Address
sideEffectsContract param = defContract do
deleg <- new$ none
mtz <- new$ 0 mutez
mtz <- new$ zeroMutez
notInit <- new$ [mt|not initialized|]
addr <- createContract textKeeper deleg mtz notInit
ifSome param (initializeContract addr) (return ())
......@@ -24,7 +24,7 @@ textKeeper param = defContract do
initializeContract :: HasSideEffects => Var Address -> Var MText -> IndigoProcedure
initializeContract addr msg = defFunction do
mtz <- new$ 0 mutez
mtz <- new$ zeroMutez
ifSome (contract addr)
(\cRef -> transferTokens msg mtz cRef)
failForRef
......
......@@ -41,6 +41,8 @@ module Lorentz.Value
-- * Constructors
, toMutez
, zeroMutez
, oneMutez
, mt
, timestampFromSeconds
, timestampFromUTCTime
......@@ -71,7 +73,8 @@ import Michelson.Text
import Michelson.Typed (EntryPointCall, IsoValue(..), SomeEntryPointCall, Value, WellTypedIsoValue)
import qualified Michelson.Typed as M
import Tezos.Core
(ChainId, Mutez, Timestamp, timestampFromSeconds, timestampFromUTCTime, timestampQuote, toMutez)
(ChainId, Mutez, Timestamp, timestampFromSeconds, timestampFromUTCTime, timestampQuote, toMutez,
zeroMutez, oneMutez)
import Tezos.Crypto (KeyHash, PublicKey, Signature)
import Util.CustomGeneric as ReExports
import Util.Label (Label(..))
......
......@@ -35,7 +35,7 @@ assertNoTokensSent :: forall (e :: ErrorsKind) s. (ErrorHandler e) => s :-> s
assertNoTokensSent = do
-- # Assert no token was sent:
-- # to send tokens, the default entry point should be used
push (toMutez 0 :: Mutez) >> amount >> (ifEq nop (handleNonZeroTransfer @e))
push zeroMutez >> amount >> (ifEq nop (handleNonZeroTransfer @e))
type MultisigParamConstrains a mainparam =
( NicePackedValue (GenericMultisigAction a mainparam)
......
Unreleased
==========
<!-- Append new entries here -->
* [!511](https://gitlab.com/morley-framework/morley/-/merge_requests/511)
Add `zeroMutez` and `oneMutez` for safe initial values.
* [!500](https://gitlab.com/morley-framework/morley/-/merge_requests/500)
Add ability to parse optimized formats of `signature`, `contract`, `key`, and `key_hash`.
* [!486](https://gitlab.com/morley-framework/morley/-/merge_requests/486)
......
......@@ -18,6 +18,8 @@ module Tezos.Core
, mulMutez
, divModMutez
, divModMutezInt
, zeroMutez
, oneMutez
-- * Timestamp
, Timestamp (..)
......@@ -164,6 +166,12 @@ divModMutezInt (toInteger . unMutez -> a) (toInteger -> b)
toMutez' :: Integer -> Mutez
toMutez' = Mutez . fromInteger
zeroMutez :: Mutez
zeroMutez = Mutez minBound
oneMutez :: Mutez
oneMutez = Mutez 1
----------------------------------------------------------------------------
-- Timestamp
----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment