Skip to content

Commit

Permalink
LF: Add interface support to the Preprocessor (#11013)
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 authored Sep 23, 2021
1 parent c33297c commit cb0e41f
Show file tree
Hide file tree
Showing 2 changed files with 17 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class PackageInterfaceSpec
import com.daml.lf.testing.parser.Implicits._
import com.daml.lf.transaction.test.TransactionBuilder.Implicits.{defaultPackageId => _, _}

// TODO https://github.com/digital-asset/daml/issues/10810
// test interfaces

private[this] implicit val defaultPackageId: Ref.PackageId =
defaultParserParameters.defaultPackageId

Expand Down

0 comments on commit cb0e41f

Please sign in to comment.