Skip to content

Commit

Permalink
[LF] add packageVersion to Create Node, and Contract Instance (#19243)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyhaemmerle-da committed May 22, 2024
1 parent b04c7a1 commit b06a9e8
Show file tree
Hide file tree
Showing 52 changed files with 591 additions and 340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ object ActionDescription extends HasProtocolVersionedCompanion[ActionDescription
case LfNodeCreate(
contractId,
_packageName,
_packageVersion,
_templateId,
_arg,
_agreementText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object ProcessedDisclosedContract {
def apply(
templateId: Ref.Identifier,
packageName: Ref.PackageName,
packageVersion: Option[Ref.PackageVersion],
contractId: Value.ContractId,
argument: Value,
createdAt: Time.Timestamp,
Expand All @@ -41,6 +42,7 @@ object ProcessedDisclosedContract {
create = Node.Create(
templateId = templateId,
packageName = packageName,
packageVersion = packageVersion,
coid = contractId,
arg = argument,
signatories = signatories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ case class SerializableContract(
def toLf: LfNodeCreate = LfNodeCreate(
coid = contractId,
packageName = rawContractInstance.contractInstance.unversioned.packageName,
packageVersion = None,
templateId = rawContractInstance.contractInstance.unversioned.template,
arg = rawContractInstance.contractInstance.unversioned.arg,
signatories = metadata.signatories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ private[apiserver] final class StoreBackedCommandExecutor(
unusedTxVersion,
ContractInstance(
packageName = disclosedContract.packageName,
packageVersion = None,
template = disclosedContract.templateId,
arg = disclosedContract.argument,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private[platform] object InMemoryStateUpdater {
contractId = createdEvent.contractId,
contract = Contract(
packageName = createdEvent.packageName,
packageVersion = None,
template = createdEvent.templateId,
arg = createdEvent.createArgument,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private[dao] object ContractsReader {
)
Contract(
packageName = PackageName.assertFromString(packageName),
packageVersion = None,
template = Identifier.assertFromString(templateId),
arg = deserialized,
)
Expand All @@ -178,6 +179,7 @@ private[dao] object ContractsReader {
): Contract =
Contract(
packageName = PackageName.assertFromString(packageName),
packageVersion = None,
template = Identifier.assertFromString(templateId),
arg = createArgument,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ final class LfValueTranslation(
coid = contractId,
templateId = templateId,
packageName = packageName,
packageVersion = None,
arg = createArgument.unversioned,
signatories = signatories,
stakeholders = signatories ++ observers,
Expand Down Expand Up @@ -415,6 +416,7 @@ final class LfValueTranslation(
coid = contractId,
templateId = createdEvent.templateId,
packageName = createdEvent.packageName,
packageVersion = None,
arg = createArgument.unversioned,
signatories = signatories,
stakeholders = signatories ++ observers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ private[events] object TransactionLogUpdatesConversions {
coid = createdEvent.contractId,
templateId = createdEvent.templateId,
packageName = createdEvent.packageName,
packageVersion = None,
arg = createdEvent.createArgument.unversioned,
signatories = createdEvent.createSignatories,
stakeholders = createdEvent.createSignatories ++ createdEvent.createObservers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ object RepairService {

lfContractInst = LfContractInst(
packageName = packageName,
packageVersion = None,
template = template,
arg = argsVersionedValue,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ private[transfer] class TransferInProcessingSteps(
coid = contract.contractId,
templateId = contractInst.template,
packageName = contractInst.packageName,
packageVersion = None,
arg = contractInst.arg,
signatories = contract.metadata.signatories,
stakeholders = contract.metadata.stakeholders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,10 @@ object ModelConformanceChecker {
// The contract id is already validated by SerializableContractAuthenticator,
// as contract is an input contract of the underlying transaction.
coid = actual.coid,
packageName = unversioned.packageName,
templateId = unversioned.template,
arg = unversioned.arg,
contract = instance.contractInstance,
signatories = metadata.signatories,
stakeholders = metadata.stakeholders,
keyOpt = metadata.maybeKeyWithMaintainers,
version = instance.contractInstance.version,
key = metadata.maybeKeyWithMaintainers,
)
_ <- EitherT.cond[Future](
actual == expected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class DAMLe(
template = nc.templateId,
arg = Versioned(nc.version, nc.arg),
packageName = nc.packageName,
packageVersion = None,
),
nc.signatories,
nc.stakeholders,
Expand Down
12 changes: 10 additions & 2 deletions sdk/daml-lf/data/src/main/scala/com/daml/lf/data/Ref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ object Ref {

object PackageVersion {
private val MaxPackageVersionLength = 255
final def fromString(s: String): Either[String, PackageVersion] = for {
def fromString(s: String): Either[String, PackageVersion] = for {
_ <- Either.cond(
s.length <= MaxPackageVersionLength,
(),
Expand All @@ -402,6 +402,14 @@ object Ref {
} yield PackageVersion(ImmArray.from(segments))

@throws[IllegalArgumentException]
final def assertFromString(s: String): PackageVersion = assertRight(fromString(s))
def assertFromString(s: String): PackageVersion = assertRight(fromString(s))

def fromInts(s: Seq[Int]): Either[String, PackageVersion] = {
val ver = PackageVersion(ImmArray.from(s))
fromString(ver.toString)
}

@throws[IllegalArgumentException]
def assertFromInts(s: Seq[Int]): PackageVersion = assertRight(fromInts(s))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class NodeSeedsTest(majorLanguageVersion: LanguageMajorVersion) extends AnyWordS
Versioned(
transaction.TransactionVersion.VDev,
Value.ContractInstance(
mainPkg.name,
mainPkg.pkgName,
mainPkg.pkgVersion,
requestTmplId,
Value.ValueRecord(
None,
Expand All @@ -67,7 +68,8 @@ class NodeSeedsTest(majorLanguageVersion: LanguageMajorVersion) extends AnyWordS
val roleContract = Versioned(
transaction.TransactionVersion.VDev,
Value.ContractInstance(
mainPkg.name,
mainPkg.pkgName,
mainPkg.pkgVersion,
roleTmplId,
Value.ValueRecord(None, ImmArray(None -> Value.ValueParty(operator))),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class AuthPropagationSpec(majorLanguageVersion: LanguageMajorVersion)
Versioned(
TransactionVersion.VDev,
ContractInstance(
pkg.name,
pkg.pkgName,
pkg.pkgVersion,
"T1",
ValueRecord(
Some("T1"),
Expand All @@ -83,7 +84,8 @@ class AuthPropagationSpec(majorLanguageVersion: LanguageMajorVersion)
Versioned(
TransactionVersion.VDev,
ContractInstance(
pkg.name,
pkg.pkgName,
pkg.pkgVersion,
"X1",
ValueRecord(
Some("X1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ class ContractKeySpec(majorLanguageVersion: LanguageMajorVersion)
val withKeyContractInst: VersionedContractInstance =
assertAsVersionedContract(
ContractInstance(
basicTestsPkg.name,
TypeConName(basicTestsPkgId, withKeyTemplate),
ValueRecord(
packageName = basicTestsPkg.pkgName,
packageVersion = basicTestsPkg.pkgVersion,
template = TypeConName(basicTestsPkgId, withKeyTemplate),
arg = ValueRecord(
Some(BasicTests_WithKey),
ImmArray(
(Some[Ref.Name]("p"), ValueParty(alice)),
Expand All @@ -98,9 +99,10 @@ class ContractKeySpec(majorLanguageVersion: LanguageMajorVersion)
toContractId("BasicTests:Simple:1") ->
assertAsVersionedContract(
ContractInstance(
basicTestsPkg.name,
TypeConName(basicTestsPkgId, "BasicTests:Simple"),
ValueRecord(
packageName = basicTestsPkg.pkgName,
packageVersion = basicTestsPkg.pkgVersion,
template = TypeConName(basicTestsPkgId, "BasicTests:Simple"),
arg = ValueRecord(
Some(Identifier(basicTestsPkgId, "BasicTests:Simple")),
ImmArray((Some[Name]("p"), ValueParty(party))),
),
Expand All @@ -109,9 +111,10 @@ class ContractKeySpec(majorLanguageVersion: LanguageMajorVersion)
toContractId("BasicTests:CallablePayout:1") ->
assertAsVersionedContract(
ContractInstance(
basicTestsPkg.name,
TypeConName(basicTestsPkgId, "BasicTests:CallablePayout"),
ValueRecord(
packageName = basicTestsPkg.pkgName,
packageVersion = basicTestsPkg.pkgVersion,
template = TypeConName(basicTestsPkgId, "BasicTests:CallablePayout"),
arg = ValueRecord(
Some(Identifier(basicTestsPkgId, "BasicTests:CallablePayout")),
ImmArray(
(Some[Ref.Name]("giver"), ValueParty(alice)),
Expand All @@ -128,7 +131,7 @@ class ContractKeySpec(majorLanguageVersion: LanguageMajorVersion)
GlobalKey.assertBuild(
TypeConName(basicTestsPkgId, withKeyTemplate),
ValueRecord(None, ImmArray((None, ValueParty(alice)), (None, ValueInt64(42)))),
basicTestsPkg.name,
basicTestsPkg.pkgName,
)
->
toContractId("BasicTests:WithKey:1")
Expand Down Expand Up @@ -288,9 +291,10 @@ class ContractKeySpec(majorLanguageVersion: LanguageMajorVersion)
val cid2 = toContractId("2")
val keyedInst = assertAsVersionedContract(
ContractInstance(
multiKeysPkg.name,
TypeConName(multiKeysPkgId, "MultiKeys:Keyed"),
ValueRecord(None, ImmArray((None, ValueParty(party)))),
packageName = multiKeysPkg.pkgName,
packageVersion = multiKeysPkg.pkgVersion,
template = TypeConName(multiKeysPkgId, "MultiKeys:Keyed"),
arg = ValueRecord(None, ImmArray((None, ValueParty(party)))),
)
)
val contracts = Map(cid1 -> keyedInst, cid2 -> keyedInst)
Expand Down
Loading

0 comments on commit b06a9e8

Please sign in to comment.