Skip to content

Functions

Logging

debug

<function> Logs a debug statement. Produces the equivalent of toText() for any value.

Type Arguments

T

Arguments

any - T - log text or raw value

Usage
debug("This is a debug statement");
debug(5.2 + 7.3);
debug(listOf(2, 3, 4));

info

<function> Logs an info statement. Produces the equivalent of toText() for any value.

Type Arguments

T

Arguments

any - T - log text or raw value

Usage
info("This is an info statement");
info(5.2 + 7.3);
info(listOf(2, 3, 4));

error

<function> Logs an error statement. Produces the equivalent of toText() for any value.

Type Arguments

T

Arguments

any - T - log text or raw value

Usage
error("This is an error statement");
error(5.2 + 7.3);
error(listOf(2, 3, 4));

Constructors

blobOf

<function> Creates a Blob from a valid data URI. This method is primarily intended for testing.

Arguments

dataUri - Text - valid data URI

Returns

Blob - blob created from text

Usage
var foo = blobOf("data:filename=foo.txt;base64,SGVsbG8=");

dateTimeOf

<function> Creates a DateTime with the given year, month, day, hour and minute in the time zone specified by zoneId. All Number values must be integers and be within the expected range for the given value, e.g. 1 to 12 for month.

Arguments

year - Number - the year

month - Number - the month (1-12)

day - Number - the day (1-31)

hour - Number - the hour (0-23)

minute - Number - the minute (0-59)

zoneId - Text - the time zone

Returns

DateTime - a DateTime value

Usage

The zoneId text argument must correspond to a valid ZoneId enum member, as obtained via valueOfZoneId.

dateTimeOf(2020, 12, 30, 12, 00, valueOfZoneId(ZoneId.AMERICA_NEW_YORK)) ==
    2020-12-30T12:00Z.withZoneSameLocal(valueOfZoneId(ZoneId.AMERICA_NEW_YORK))
// The `dateTimeOf` function does not take seconds and millis,
// but you can add them afterward if needed:
var d = dateTimeOf(2020, 12, 31, 23, 59, valueOfZoneId(ZoneId.AMERICA_NEW_YORK)) + seconds(30) + millis(987);

filledList (deprecated)

Deprecated: Use listOfSize

<function> Creates a filled list.

Type Arguments

T

Arguments

count - Number - number of elements that the list should contain

fill - T - element to fill the list with

Returns

List<T> - a list with containing count elements, all of which are set to the value fill.

Usage
filledList<Text>(3, "a") == listOf("a", "a", "a")

listOf

<function> Creates a List containing values.

Type Arguments

T

Arguments

vararg values - T

Returns

List<T>

Usage
listOf<Number>(); // empty list of numbers
listOf(1, 2); // list containing numbers 1 and 2

listOfSize

<function> Creates a list of specified size, where each element is calculated with specified fn function. The function fn is called for each list element sequentially starting from the first one. It should return the value for a list element given its index. If specified size is smaller than 1, an empty list is returned. Specified size must be an integer value.

Type Arguments

T - the element type

Arguments

size - Number - number of elements that the list should contain

fn - (Number) -> T - the function that takes index (starting at 0) and generates an element to fill the list at the index with

Returns

List<T> - a list containing size elements, where each element is calculated with specified fn function.

Usage
listOfSize(3, function(idx: Number) -> idx + 1) == listOf(1, 2, 3)

localDateOf

<function> Creates a LocalDate with the given year, month and day. All values must be integers and within the expected range for the given value.

Arguments

year - Number - the year

month - Number - the month (1-12)

day - Number - the day (1-31)

Returns

LocalDate - a LocalDate value

mapOf

<function> Creates a Map.

Type Arguments

K - map key type

V - map value type

Arguments

vararg pairs - Pair<K, V> - to populate the Map with

Returns

Map<K, V>

Usage
mapOf<Text, Number>(); // empty map of Text to Number
mapOf(Pair(first = "a", second = 10)); // map with "a" mapped to 10
mapOf(Pair("a", 10), Pair("b", 20), Pair("c", 30)); // map with 3 items

optionalOf

<function> Create an Optional of item, or an empty optional if no argument is provided.

Type Arguments

T

Arguments

optional item - T - item to create the optional of

Returns

Optional<T>

Usage
optionalOf<Number>(); // empty optional of type Number
optionalOf<Number>(3); // optional containing the number 3

partyOf

<function> Construct a party from entity and access claims, respectively. Claims are typically set by the authentication layer through mechanisms like JWT or LDAP. Both entity and access claims maps can be empty but cannot contain a key with no values.

Arguments

entityClaims - Map<Text, Set<Text>>

accessClaims - Map<Text, Set<Text>>

Returns

Party - an object representing the responsible party as described by the provided claims

Usage
// create party containing given entity and access claims
partyOf(
    entityClaims = mapOf(Pair("entityKey", setOf("entityValue"))),
    accessClaims = mapOf(Pair("accessKey", setOf("value1", "value2")))
);

// create party containing given entity and no access claims
partyOf(
    entityClaims = mapOf(Pair("entityKey", setOf("entityValue"))),
    accessClaims = mapOf<Text, Set<Text>>() // claim can be empty
);

// create party containing no entity or access claims
partyOf(
    entityClaims = mapOf<Text, Set<Text>>(),
    accessClaims = mapOf<Text, Set<Text>>()
);

// illegal - entity cannot contain key with empty set of values
partyOf(
    entityClaims = mapOf(Pair("entityKey", setOf<Text>())),
    accessClaims = mapOf(Pair("accessKey", setOf("accessValue")))
);

// illegal - access cannot contain key with empty set of values
partyOf(
    entityClaims = mapOf(Pair("entityKey", setOf("entityValue"))),
    accessClaims = mapOf(Pair("accessKey", setOf<Text>()))
);

setOf

<function> Creates a Set containing values.

Type Arguments

T

Arguments

vararg values - T

Returns

Set<T>

Usage
setOf<Number>(); // empty set of numbers
setOf(1, 2); // set containing numbers 1 and 2

Datetime methods

now

<function> Obtains the start of the current transaction in UTC (i.e. at the processing of a top-level protocol creation, selection of a permission or obligation, triggering of an otherwise block of an obligation). Calling now() at different moments in a transaction will return the same value. Calling now() in any guard related to this single transaction will also return the same value.

Returns

DateTime - a DateTime value representing the start of the current transaction in UTC

millis

<function> Obtain a Duration of milliseconds.

Arguments

millis - Number - number of milliseconds to use, must be an integer value

Returns

Duration

seconds

<function> Obtain a Duration of seconds.

Arguments

seconds - Number - number of seconds to use, must be an integer value

Returns

Duration

minutes

<function> Obtain a Duration of minutes.

Arguments

minutes - Number - number of minutes to use, must be an integer value

Returns

Duration

hours

<function> Obtain a Duration of hours.

Arguments

hours - Number - number of hours to use, must be an integer value

Returns

Duration

days

<function> Obtain a Period of days.

Arguments

days - Number - number of days to create Period of, must be an integer value

Returns

Period - period containing days number of days

Usage
var desert_days = days(40);

weeks

<function> Obtain a Period of weeks.

Arguments

weeks - Number - number of weeks to create Period of, must be an integer value

Returns

Period - period containing weeks number of weeks

Usage
var fortnite = weeks(2);

months

<function> Obtain a Period of months.

Arguments

months - Number - number of months to create Period of, must be an integer value

Returns

Period - period containing months number of months

Usage
var swedish_summer = months(2);

years

<function> Obtain a Period of years.

Arguments

years - Number - number of years to create Period of, must be an integer value

Returns

Period - period containing years number of years

Usage
var war_duration = years(30);

valueOfZoneId

<function> Convert a member of the ZoneId enum to its Text representation

Arguments

zoneId - ZoneId - a member of the ZoneId enum

Returns

Text - The Text representation of zoneId

Usage

valueOfZoneId(ZoneId.AFRICA_ABIDJAN) == "Africa/Abidjan"
// Useful in conjunction with `dateTimeOf`:
var newYearOnWallis = dateTimeOf(2020, 01, 01, 00, 00, valueOfZoneId(ZoneId.PACIFIC_WALLIS));