Skip to main content

Interfaces

Interface enables the logic to access data and invoke endpoints on other logics during the same interaction. If the other logic is an asset logic, asset endpoints should be listed in the assets section of the interface.

A logic can have multiple interfaces, one for each kind of logic. Interface is bound to a logic by using external logic's identifier and only then calls can be made and data accessed.

Cross-logic call: question → answer, with logic and actor state

In this example, the logic question accesses another logic, called answer.

coco question

interface Answer:
state actor:
ActorAnswer U64
endpoint:
dynamic SetActorAnswer(actorId Identifier, new_answer U64) -> (set_answer U64)

// sets the actor answer on Sender
endpoint dynamic SetActorAnswer(answerLogicId Identifier, new_answer U64) -> (set_answer U64):
memory answer_iface = Answer(answerLogicId)
set_answer = answer_iface.SetActorAnswer(actorId: Sender, new_answer)

// sets the actor answer on this logic (question)
endpoint dynamic SetMyAnswer(answerLogicId Identifier, new_answer U64):
memory answer_iface = Answer(answerLogicId)
answer_iface.SetActorAnswer(actorId: Identifier(question), new_answer)
coco answer

state actor:
ActorAnswer U64

endpoint dynamic SetActorAnswer(actorId Identifier, new_answer U64) -> (set_answer U64):
mutate new_answer -> answer.Actor(actorId).ActorAnswer
observe set_answer <- answer.Actor(actorId).ActorAnswer