-- Setup some domain specific types to use when creating DIDO objects --- PersonNameType DEDFINE TYPE PersonNameType ( value : IN Text NOT NULL NOT EMPTY ) AS TEXT WITH CONSTRAINTS ( DEFAULT = NULL, COMPRESION = ONE, CASE = TITLE, MAX_LENGTH = 30, VALUE = value ); --- IdType DEFINE TYPE IdType ( algorithm : IN Text NOT NULL NOT EMPTY := DEFAULT_ALGORITHM message : IN Text NOT NULL NOT EMPTY := CURRENT_DATE, options : IN Text := "Hex" ) AS HASH WITH CONSTRAINTS ( DEFAULT = algorithm, MESSAGE = message, OPTIONS = options ); --- Create an object that doesn't have any tokens in it DEFINE OBJECT MyDido.Student ( firstName : IN PersonNameType NOT NULL NOT EMPTY, lastName : IN PersonNameType NOT NULL NOT EMPTY ) RETURN IdType AS ( StudentId : IdType RETURN := NEW IdType ( message = FirstName + LastName), FirstName : PersonNameType := firstName, LastName : PersonNameType := lastName ); --- Setup some domain specific constants to use when creating objects DEFINE CONSTANT DEFAULT_CURRENCY_SYMBOL AS 'ยง'; DEFINE CONSTANT DEFAULT_CURRENCY_NAME AS "StudentCoin"; --- Create a type that describes the Student Coin DEFINE TYPE SudentCoinType ( initialBalance : IN FIXED NOT NULL := 0.00, currencyName : IN Text NOT NULL NOT EMPTY := DEFAULT_CURRENCY_NAME, currencySymbol : IN Text NOT NULL NOT EMPTY := DEFAULT_CURRENCY_SYMBOL, precision : IN Text NOT NULL NOT EMPTY := "5,2", min : IN FIXED NOT NULL := -50.00, max : IN FIXED NOT NULL := 1000.00 ) AS FIXED ALLOWING NONULL WITH CONSTRAINTS ( MIN = min, MAX = max, VALUE = initialBalance, UNITS = currencyName, SYMBOL = currencySymbol, PRECISION = precision ); --- Create a Student Account that uses the StudentCoinType to track a balance. --- The Balance is also a TOKEN which marks the value as requiring a Transaction --- to prevent "Double Spend" CREATE OBJECT OurDido.StudentAccount ( studentId : IdType NOT NULL, balance : SudentCoinType NOT NULL ) RETURN AS IdType AS ( AccountId : IdType RETURN := NEW IdType ( message = studentId + balance), StudentId : IdType := studentId, Balance : SudentCoinType TOKEN := balance );