Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAML-LF: factorize ScenarioNodeId and EventId #6256

Merged
merged 4 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ final class Conversions(
private val ptxCoidToNodeId = machine.ptx.nodes
.collect {
case (nodeId, node: N.NodeCreate[V.ContractId, _]) =>
node.coid -> ledger.ptxNodeId(nodeId)
node.coid -> ledger.ptxEventId(nodeId)
}

private val coidToNodeId = ledger.ledgerData.coidToNodeId ++ ptxCoidToNodeId
private val coidToEventId = ledger.ledgerData.coidToNodeId ++ ptxCoidToNodeId

private val nodes =
ledger.ledgerData.nodeInfos.map(Function.tupled(convertNode))
Expand Down Expand Up @@ -307,7 +307,7 @@ final class Conversions(
def mkContractRef(coid: V.ContractId, templateId: Ref.Identifier): ContractRef =
ContractRef.newBuilder
.setRelative(false)
.setContractId(coidToNodeId(coid))
.setContractId(coidToEventId(coid).toLedgerString)
.setTemplateId(convertIdentifier(templateId))
.build

Expand Down Expand Up @@ -352,7 +352,7 @@ final class Conversions(
rtx: Ledger.RichTransaction,
): Transaction = {
val convertedGlobalImplicitDisclosure = rtx.globalImplicitDisclosure.map {
case (coid, parties) => coidToNodeId(coid) -> parties
case (coid, parties) => coidToEventId(coid) -> parties
}
Transaction.newBuilder
.setCommitter(convertParty(rtx.committer))
Expand Down Expand Up @@ -392,13 +392,13 @@ final class Conversions(
builder.build
}

def convertNodeId(nodeId: Ledger.ScenarioNodeId): NodeId =
NodeId.newBuilder.setId(nodeId).build
def convertNodeId(nodeId: Ledger.EventId): NodeId =
NodeId.newBuilder.setId(nodeId.toLedgerString).build

def convertTxNodeId(nodeId: Tx.NodeId): NodeId =
NodeId.newBuilder.setId(nodeId.index.toString).build

def convertNode(nodeId: Ledger.ScenarioNodeId, nodeInfo: Ledger.LedgerNodeInfo): Node = {
def convertNode(nodeId: Ledger.EventId, nodeInfo: Ledger.LedgerNodeInfo): Node = {
val builder = Node.newBuilder
builder
.setNodeId(convertNodeId(nodeId))
Expand Down Expand Up @@ -435,22 +435,22 @@ final class Conversions(
case fetch: N.NodeFetch.WithTxValue[V.ContractId] =>
builder.setFetch(
Node.Fetch.newBuilder
.setContractId(coidToNodeId(fetch.coid))
.setContractId(coidToEventId(fetch.coid).toLedgerString)
.setTemplateId(convertIdentifier(fetch.templateId))
.addAllSignatories(fetch.signatories.map(convertParty).asJava)
.addAllStakeholders(fetch.stakeholders.map(convertParty).asJava)
.build,
)
case ex: N.NodeExercises[
Ledger.ScenarioNodeId,
Ledger.EventId,
V.ContractId,
Tx.Value[
V.ContractId,
]] =>
ex.optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setExercise(
Node.Exercise.newBuilder
.setTargetContractId(coidToNodeId(ex.targetCoid))
.setTargetContractId(coidToEventId(ex.targetCoid).toLedgerString)
.setTemplateId(convertIdentifier(ex.templateId))
.setChoiceId(ex.choiceId)
.setConsuming(ex.consuming)
Expand All @@ -460,7 +460,7 @@ final class Conversions(
.addAllStakeholders(ex.stakeholders.map(convertParty).asJava)
.addAllChildren(
ex.children
.map(nid => NodeId.newBuilder.setId(nid).build)
.map(nid => NodeId.newBuilder.setId(nid.toLedgerString).build)
.toSeq
.asJava,
)
Expand All @@ -472,7 +472,7 @@ final class Conversions(
val lbkBuilder = Node.LookupByKey.newBuilder
.setTemplateId(convertIdentifier(lbk.templateId))
.setKeyWithMaintainers(convertKeyWithMaintainers(convertVersionedValue, lbk.key))
lbk.result.foreach(cid => lbkBuilder.setContractId(coidToNodeId(cid)))
lbk.result.foreach(cid => lbkBuilder.setContractId(coidToEventId(cid).toLedgerString))
builder.setLookupByKey(lbkBuilder)

}
Expand Down Expand Up @@ -518,7 +518,7 @@ final class Conversions(
case fetch: N.NodeFetch[V.ContractId, Val] =>
builder.setFetch(
Node.Fetch.newBuilder
.setContractId(coidToNodeId(fetch.coid))
.setContractId(coidToEventId(fetch.coid).toLedgerString)
.setTemplateId(convertIdentifier(fetch.templateId))
.addAllSignatories(fetch.signatories.map(convertParty).asJava)
.addAllStakeholders(fetch.stakeholders.map(convertParty).asJava)
Expand All @@ -528,7 +528,7 @@ final class Conversions(
ex.optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setExercise(
Node.Exercise.newBuilder
.setTargetContractId(coidToNodeId(ex.targetCoid))
.setTargetContractId(coidToEventId(ex.targetCoid).toLedgerString)
.setTemplateId(convertIdentifier(ex.templateId))
.setChoiceId(ex.choiceId)
.setConsuming(ex.consuming)
Expand All @@ -550,7 +550,7 @@ final class Conversions(
builder.setLookupByKey({
val builder = Node.LookupByKey.newBuilder
.setKeyWithMaintainers(convertKeyWithMaintainers(convertValue, lookup.key))
lookup.result.foreach(cid => builder.setContractId(coidToNodeId(cid)))
lookup.result.foreach(cid => builder.setContractId(coidToEventId(cid).toLedgerString))
builder.build
})
}
Expand Down Expand Up @@ -635,7 +635,7 @@ final class Conversions(
tycon.foreach(x => eBuilder.setEnumId(convertIdentifier(x)))
builder.setEnum(eBuilder.build)
case V.ValueContractId(coid) =>
builder.setContractId(coidToNodeId(coid))
builder.setContractId(coidToEventId(coid).toLedgerString)
case V.ValueList(values) =>
builder.setList(
v1.List.newBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,16 @@ object Pretty {
text("mustFailAt") & prettyParty(amf.actor) & prettyLoc(amf.optLocation)
}

def prettyKeyWithMaintainers(key: KeyWithMaintainers[Value[ContractId]]): Doc =
// the maintainers are induced from the key -- so don't clutter
prettyValue(false)(key.key)

def prettyVersionedKeyWithMaintainers(
key: KeyWithMaintainers[Transaction.Value[ContractId]]): Doc =
// the maintainers are induced from the key -- so don't clutter
prettyVersionedValue(false)(key.key)

def prettyKeyWithMaintainers(key: KeyWithMaintainers[Value[ContractId]]): Doc =
// the maintainers are induced from the key -- so don't clutter
prettyValue(false)(key.key)

def prettyNodeInfo(l: L.Ledger)(nodeId: L.ScenarioNodeId): Doc = {
def prettyNodeInfo(l: L.Ledger)(nodeId: L.EventId): Doc = {
def arrowRight(d: Doc) = text("└─>") & d
def meta(d: Doc) = text("│ ") & d

Expand All @@ -272,11 +272,10 @@ object Pretty {
case ea: NodeFetch[ContractId, Transaction.Value[ContractId]] =>
"ensure active" &: prettyContractId(ea.coid)
case ex: NodeExercises[
L.ScenarioNodeId,
L.EventId,
ContractId,
Transaction.Value[
ContractId
]] =>
Transaction.Value[ContractId]
] =>
val children =
if (ex.children.nonEmpty)
text("children:") / stack(ex.children.toList.map(prettyNodeInfo(l)))
Expand Down Expand Up @@ -334,8 +333,8 @@ object Pretty {
)
}

def prettyLedgerNodeId(n: L.ScenarioNodeId): Doc =
text(n)
def prettyLedgerNodeId(n: L.EventId): Doc =
text(n.toLedgerString)

def prettyContractInst(coinst: ContractInst[Value[ContractId]]): Doc =
(prettyIdentifier(coinst.template) / text("with:") &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object SError {
final case class ScenarioErrorContractNotActive(
coid: ContractId,
templateId: Identifier,
consumedBy: Ledger.ScenarioNodeId,
consumedBy: Ledger.EventId,
) extends SErrorScenario

/** We tried to fetch / exercise a contract of the wrong type --
Expand Down
Loading