Skip to content

Transformer operations

ProtocolTransformer and StructTransformer methods

get

Obtain a property or argument value.

Usage
get<Value>("propertyName")

delete

Delete properties.

Usage
delete("propertyName", "propertyName", ...)

Example here.

replace

Update a property.

Usage
replace("propertyName") { oldValue -> newValue }

Example here.

put

Add a property.

Usage
put("propertyName") { value }

Example here.

putAll

Add multiple properties.

Usage
putAll { mapOf("propertyName" to value) }

withTransformations

Apply registered transformation to this type. Further details here.

Usage
withTransformations(Value, ListType(NumberType)) { oldValue -> newValue }

type

Obtain the type for a protocol, struct, identifier, or union typeId. Further details here.

Usage
type("/package/Example")

Example here.

createStruct

Create a new struct.

Usage
createStruct("structTypeId", mapOf("property" to value))

createIdentifier

Create a new identifier (ID).

Usage
createIdentifier("identifierTypeId")

Example here.

createUnion

Create a new union.

Usage
createUnion("unionTypeId", value)

createEnum

Create a new enum.

Usage
createEnum("enumTypeId", "variant")

createProtocol

Create a new protocol with an optional transformation

Usage
createProtocol("protocolTypeId", listOf(PartyValue("p")), listOf(argumentValue))
createProtocol("protocolTypeId", listOf(PartyValue("p")), listOf(argumentValue)) {
    put("name") { TextValue("my name") }
}

createList

Create a new list.

Usage
// With type inference
createList(listOf(value))
// With explicitly specified element type
createList(listOf(value), elementType)

createMap

Create a new map.

Usage
// With type inference
createMap(linkedMapOf(someKeyValue to value))
// With explicitly specified key and value types
createMap(linkedMapOf(someKeyValue to value), keyType, valueType)

createSet

Create a new set.

Usage
// With type inference
createSet(linkedSetOf(value))
// With explicitly specified element type
createSet(linkedSetOf(value), elementType)

createOptional

Create a new optional.

Usage
createOptional(value) // results in Some wrapping value
createOptional(value, type) // results in Some wrapping value
createOptional(null, type) // results in None but with type `type`
createOptional(type) // results in None but with type `type`

createBlob

Create a new blob.

Usage
createBlob("data:/;base64,")

createSuccess

Create a new success result.

Usage
// With type inference
createSuccess(value)
// With explicitly specified type
createSuccess(value, type)

createFail

Create a fail result.

Usage
createFail()

createAmount

Create a new specified symbol with given amount.

Usage
createAmount(13, "/package/chf")

createText

Create a new text.

Usage
createText("Hello!")

createNumber

Create a new number.

Usage
createNumber(1)

createBoolean

Create a new boolean.

Usage
createBolean(true)

createDateTime

Create a new datetime.

Usage
createDateTime(ZonedDateTime.of(2012, 12, 21, 13, 37, 0, 0, ZoneId.of("GMT+1")))
createDateTime(ZonedDateTime.parse("2019-01-01T00:00+01:00"))

createDuration

Create a new duration.

Usage
createDuration(Duration.ofHours(15))

createLocalDate

Create a new localdate.

Usage
createLocalDate(LocalDate.of(2022, 11, 11))

createPeriod

Create a new period.

Usage
createPeriod(Period.ofDays(3))

createUnit

Create a new unit.

Usage
createUnit()

createParty

Create a new party.

Usage
createParty("partyName")

Example here.

ProtocolTransformer methods

parties

Set protocol parties (in provided order).

Usage
parties(PartyValue(party1), PartyValue(party2), ...)

Example here.

observers

Set protocol observers.

observers(mapOf("eve" to PartyValue("eveParty")))

state

There are two variants of this method: state(), which maps available states to new states, and state { }, which allows for arbitrary state transformations.

If the new states do not directly correspond to the old states, state {...} should be used.

Adding a new state during a migration is a typical situation in which the new states do not correspond to the old states, so it follows that state {...} should then be used.

State transformations can also be achieved with transformEnum, which is usually the preferred procedure.

Usage
// map available states to new states
state("old1" to "new1", "old2" to "new2", ...)
// arbitrary state mappings
state { oldState -> "someState" }
state { oldState ->
    when (oldState) {
        "stateA" -> "stateB"
        "stateX" -> "stateY"
        else -> "stateZ"
    }
}

ProtocolTransformer fields

id

Protocol instance identifier.

reference

Protocol instance reference value.

parties

Protocol parties (in provided order).

observers

Map of names to protocol observers.

oldStates

Names of all available states in the old protocol.

newStates

Names of all available states in the new protocol.

activeState

Current protocol state.

currentState (deprecated)

Deprecated field (since 2021.1.46, to be removed in 2025.1.0)

Use activeState instead.