Skip to content

Commit

Permalink
LF: Add interface support to the Preprocessor
Browse files Browse the repository at this point in the history
This is part of #10810

We handle only the case of Exercise as Fetch is currenlty used only by
Canton

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da committed Sep 23, 2021
1 parent bf8b75d commit 7fa3a54
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,25 @@ private[lf] final class CommandPreprocessor(
speedy.Command.Create(templateId, arg)
}

@throws[Error.Preprocessing.Error]
def unsafePreprocessExercise(
templateId: Ref.Identifier,
identifier: Ref.Identifier,
contractId: Value.ContractId,
choiceId: Ref.ChoiceName,
argument: Value,
): speedy.Command.Exercise = {
val cid = valueTranslator.unsafeTranslateCid(contractId)
val choice = handleLookup(interface.lookupChoice(templateId, choiceId)).argBinder._2
val choice =
// TODO https://github.com/digital-asset/daml/issues/10810
// Push this lookup logic in PackageInterface and extend
// com.daml.lf.language.LookupError accordingly
interface.lookupInterfaceChoice(identifier, choiceId) match {
case Left(_) =>
handleLookup(interface.lookupChoice(identifier, choiceId)).argBinder._2
case Right(interfaceChoice) =>
interfaceChoice.argType
}
val arg = valueTranslator.unsafeTranslateValue(choice, argument)
speedy.Command.Exercise(templateId, cid, choiceId, arg)
speedy.Command.Exercise(identifier, cid, choiceId, arg)
}

@throws[Error.Preprocessing.Error]
Expand Down Expand Up @@ -119,6 +127,8 @@ private[lf] final class CommandPreprocessor(
choiceArgument,
)
case command.FetchCommand(templateId, coid) =>
// TODO https://github.com/digital-asset/daml/issues/10810
// -- handle the case where templateId is an interface
handleLookup(interface.lookupTemplate(templateId))
val cid = valueTranslator.unsafeTranslateCid(coid)
speedy.Command.Fetch(templateId, cid)
Expand Down

0 comments on commit 7fa3a54

Please sign in to comment.