Skip to content

Commit

Permalink
DAML-LF: deprecate Transaction.TContractId (digital-asset#6223)
Browse files Browse the repository at this point in the history
CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Jun 4, 2020
1 parent 322b93c commit bffc289
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class LargeTransactionTest extends WordSpec with Matchers with BazelRunfiles {

val listValue = extractResultFieldFromExerciseTransaction(exerciseCmdTx, "list")

val list: FrontStack[Value[Tx.TContractId]] = listValue match {
val list: FrontStack[Value[Value.ContractId]] = listValue match {
case ValueList(x) => x
case f @ _ => fail(s"Unexpected match: $f")
}
Expand All @@ -181,7 +181,7 @@ class LargeTransactionTest extends WordSpec with Matchers with BazelRunfiles {
exerciseCmdTx: Transaction,
expectedNumberOfContracts: Int): Assertion = {

val newContracts: List[N.GenNode.WithTxValue[Tx.NodeId, Tx.TContractId]] =
val newContracts: List[N.GenNode.WithTxValue[Tx.NodeId, Value.ContractId]] =
firstRootNode(exerciseCmdTx) match {
case ne: N.NodeExercises[_, _, _] => ne.children.toList.map(nid => exerciseCmdTx.nodes(nid))
case n @ _ => fail(s"Unexpected match: $n")
Expand Down Expand Up @@ -266,7 +266,7 @@ class LargeTransactionTest extends WordSpec with Matchers with BazelRunfiles {
exerciseCmdTx: Transaction,
expected: Long): Assertion = {

val value: Value[Tx.TContractId] =
val value: Value[ContractId] =
extractResultFieldFromExerciseTransaction(exerciseCmdTx, "value")

val actual: Long = value match {
Expand All @@ -279,18 +279,18 @@ class LargeTransactionTest extends WordSpec with Matchers with BazelRunfiles {

private def extractResultFieldFromExerciseTransaction(
exerciseCmdTx: Transaction,
fieldName: String): Value[Tx.TContractId] = {
fieldName: String): Value[ContractId] = {

val contractInst: ContractInst[Tx.Value[Tx.TContractId]] = extractResultFromExerciseTransaction(
exerciseCmdTx)
val contractInst: ContractInst[Tx.Value[ContractId]] =
extractResultFromExerciseTransaction(exerciseCmdTx)

val fields: ImmArray[(Option[String], Value[Tx.TContractId])] =
val fields: ImmArray[(Option[String], Value[ContractId])] =
contractInst.arg.value match {
case ValueRecord(_, x: ImmArray[_]) => x
case v @ _ => fail(s"Unexpected match: $v")
}

val valueField: Option[(Option[String], Value[Tx.TContractId])] = fields.find {
val valueField: Option[(Option[String], Value[ContractId])] = fields.find {
case (n, _) => n.contains(fieldName)
}

Expand All @@ -301,13 +301,14 @@ class LargeTransactionTest extends WordSpec with Matchers with BazelRunfiles {
}

private def extractResultFromExerciseTransaction(
exerciseCmdTx: Transaction): ContractInst[Tx.Value[Tx.TContractId]] = {
exerciseCmdTx: Transaction,
): ContractInst[Tx.Value[ContractId]] = {

exerciseCmdTx.roots.length shouldBe 1
exerciseCmdTx.nodes.size shouldBe 2

val createNode
: N.GenNode.WithTxValue[Tx.NodeId, Tx.TContractId] = firstRootNode(exerciseCmdTx) match {
: N.GenNode.WithTxValue[Tx.NodeId, ContractId] = firstRootNode(exerciseCmdTx) match {
case ne: N.NodeExercises[_, _, _] => exerciseCmdTx.nodes(ne.children.head)
case n @ _ => fail(s"Unexpected match: $n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ object ValueGenerators {
@deprecated("use genNonEmptyParties instead", since = "100.11.17")
private[lf] def genParties = genNonEmptyParties

val contractInstanceGen: Gen[ContractInst[Tx.Value[Tx.TContractId]]] = {
val contractInstanceGen: Gen[ContractInst[Tx.Value[Value.ContractId]]] = {
for {
template <- idGen
arg <- versionedValueGen
agreement <- Arbitrary.arbitrary[String]
} yield ContractInst(template, arg, agreement)
}

val keyWithMaintainersGen: Gen[KeyWithMaintainers[Tx.Value[Tx.TContractId]]] = {
val keyWithMaintainersGen: Gen[KeyWithMaintainers[Tx.Value[Value.ContractId]]] = {
for {
key <- versionedValueGen
maintainers <- genNonEmptyParties
Expand All @@ -267,7 +267,7 @@ object ValueGenerators {
* 1. stakeholders may not be a superset of signatories
* 2. key's maintainers may not be a subset of signatories
*/
val malformedCreateNodeGen: Gen[NodeCreate.WithTxValue[Tx.TContractId]] = {
val malformedCreateNodeGen: Gen[NodeCreate.WithTxValue[Value.ContractId]] = {
for {
coid <- coidGen
coinst <- contractInstanceGen
Expand All @@ -290,7 +290,7 @@ object ValueGenerators {

/** Makes exercise nodes with some random child IDs. */
val danglingRefExerciseNodeGen
: Gen[NodeExercises[Tx.NodeId, Tx.TContractId, Tx.Value[Tx.TContractId]]] = {
: Gen[NodeExercises[Tx.NodeId, Value.ContractId, Tx.Value[Value.ContractId]]] = {
for {
targetCoid <- coidGen
templateId <- idGen
Expand Down Expand Up @@ -390,7 +390,7 @@ object ValueGenerators {
2 -> fetchNodeGen
)
nodeWithChildren <- node match {
case node: NodeExercises.WithTxValue[Tx.NodeId, Tx.TContractId] =>
case node: NodeExercises.WithTxValue[Tx.NodeId, Value.ContractId] =>
for {
depth <- Gen.choose(0, maxDepth - 1)
nodeWithChildren <- nonDanglingRefNodeGen(depth, nodeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,16 @@ object Transaction {
type NodeId = Value.NodeId
val NodeId = Value.NodeId

@deprecated("Use daml.lf.value.Value.ContractId directly", since = "1.4.0")
type TContractId = Value.ContractId

type Value[+Cid] = Value.VersionedValue[Cid]

type ContractInst[+Cid] = Value.ContractInst[Value[Cid]]

/** Transaction nodes */
type Node = GenNode.WithTxValue[NodeId, TContractId]
type LeafNode = LeafOnlyNode.WithTxValue[TContractId]
type Node = GenNode.WithTxValue[NodeId, Value.ContractId]
type LeafNode = LeafOnlyNode.WithTxValue[Value.ContractId]

/** (Complete) transactions, which are the result of interpreting a
* ledger-update. These transactions are consumed by either the
Expand All @@ -442,7 +443,7 @@ object Transaction {
* divulgence of contracts.
*
*/
type Transaction = GenTransaction.WithTxValue[NodeId, TContractId]
type Transaction = GenTransaction.WithTxValue[NodeId, Value.ContractId]

/** Transaction meta data
* @param submissionSeed: the submission seed used to derive the contract IDs.
Expand Down Expand Up @@ -481,7 +482,10 @@ object Transaction {
/** Signals that the contract-id `coid` was expected to be active, but
* is not.
*/
final case class ContractNotActive(coid: TContractId, templateId: TypeConName, consumedBy: NodeId)
final case class ContractNotActive(
coid: Value.ContractId,
templateId: TypeConName,
consumedBy: NodeId)
extends TransactionError

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TransactionCoderSpec

"encode-decode" should {
"do contractInstance" in {
forAll(contractInstanceGen) { coinst: ContractInst[Tx.Value[Tx.TContractId]] =>
forAll(contractInstanceGen) { coinst: ContractInst[Tx.Value[Value.ContractId]] =>
Right(coinst) shouldEqual TransactionCoder.decodeContractInstance(
ValueCoder.CidDecoder,
TransactionCoder.encodeContractInstance(ValueCoder.CidEncoder, coinst).toOption.get,
Expand All @@ -47,7 +47,7 @@ class TransactionCoderSpec

"do NodeCreate" in {
forAll(malformedCreateNodeGen, valueVersionGen()) {
(node: NodeCreate[Tx.TContractId, Tx.Value[Tx.TContractId]], _: ValueVersion) =>
(node: NodeCreate[Value.ContractId, Tx.Value[Value.ContractId]], _: ValueVersion) =>
val encodedNode = TransactionCoder
.encodeNode(
TransactionCoder.NidEncoder,
Expand All @@ -74,7 +74,7 @@ class TransactionCoderSpec

"do NodeFetch" in {
forAll(fetchNodeGen, valueVersionGen()) {
(node: NodeFetch.WithTxValue[Tx.TContractId], _: ValueVersion) =>
(node: NodeFetch.WithTxValue[Value.ContractId], _: ValueVersion) =>
val encodedNode =
TransactionCoder
.encodeNode(
Expand All @@ -101,7 +101,7 @@ class TransactionCoderSpec

"do NodeExercises" in {
forAll(danglingRefExerciseNodeGen) {
node: NodeExercises[Tx.NodeId, Tx.TContractId, Tx.Value[Tx.TContractId]] =>
node: NodeExercises[Tx.NodeId, Value.ContractId, Tx.Value[Value.ContractId]] =>
val encodedNode =
TransactionCoder
.encodeNode(
Expand Down Expand Up @@ -135,7 +135,7 @@ class TransactionCoderSpec
.encodeTransaction(TransactionCoder.NidEncoder, ValueCoder.CidEncoder, t),
)

val decodedVersionedTx: VersionedTransaction[Tx.NodeId, Tx.TContractId] =
val decodedVersionedTx: VersionedTransaction[Tx.NodeId, Value.ContractId] =
assertRight(
TransactionCoder
.decodeVersionedTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.daml.ledger.api.domain.Commands
import com.daml.ledger.participant.state.index.v2.ContractStore
import com.daml.lf.crypto
import com.daml.lf.data.Time
import com.daml.lf.transaction.Transaction
import com.daml.lf.value.Value.ContractId
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.metrics.Metrics
Expand Down Expand Up @@ -58,7 +57,7 @@ final class LedgerTimeAwareCommandExecutor(
// Check whether the ledger time used for input is consistent with the output,
// and advance output time or re-execute the command if necessary.
val usedContractIds: Set[ContractId] = cer.transaction
.inputContracts[Transaction.TContractId]
.inputContracts[ContractId]
.collect[ContractId, Set[ContractId]] {
case id: ContractId => id
}
Expand Down

0 comments on commit bffc289

Please sign in to comment.