Skip to content

Commit

Permalink
rewrite pattern matching with type
Browse files Browse the repository at this point in the history
  • Loading branch information
remyhaemmerle-da committed Jun 5, 2020
1 parent 7bcd8a5 commit a9f6ec1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ final class Conversions(
lbk.optLocation.foreach(loc => builder.setLocation(convertLocation(loc)))
val lbkBuilder = Node.LookupByKey.newBuilder
.setTemplateId(convertIdentifier(lbk.templateId))
.setKeyWithMaintainers(convertKeyWithMaintainers(convertVersionnedValue, lbk.key))
.setKeyWithMaintainers(convertKeyWithMaintainers(convertVersionedValue, lbk.key))
lbk.result.foreach(cid => lbkBuilder.setContractId(coidToNodeId(cid)))
builder.setLookupByKey(lbkBuilder)

Expand Down Expand Up @@ -500,7 +500,7 @@ final class Conversions(
.setNodeId(NodeId.newBuilder.setId(nodeId.index.toString).build)
// FIXME(JM): consumedBy, parent, ...
node match {
case create @ N.NodeCreate(_, _, _, _, _, _) =>
case create: N.NodeCreate[V.ContractId, Val] =>
val createBuilder =
Node.Create.newBuilder
.setContractInstance(
Expand All @@ -515,7 +515,7 @@ final class Conversions(
createBuilder.setKeyWithMaintainers(convertKeyWithMaintainers(convertValue, key)))
create.optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setCreate(createBuilder.build)
case fetch @ N.NodeFetch(_, _, _, _, _, _, _) =>
case fetch: N.NodeFetch[V.ContractId, Val] =>
builder.setFetch(
Node.Fetch.newBuilder
.setContractId(coidToNodeId(fetch.coid))
Expand All @@ -524,7 +524,7 @@ final class Conversions(
.addAllStakeholders(fetch.stakeholders.map(convertParty).asJava)
.build,
)
case ex @ N.NodeExercises(_, _, _, _, _, _, _, _, _, _, _, _, _) =>
case ex: N.NodeExercises[V.NodeId, V.ContractId, Val] =>
ex.optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setExercise(
Node.Exercise.newBuilder
Expand All @@ -545,7 +545,7 @@ final class Conversions(
.build,
)

case lookup @ N.NodeLookupByKey(_, _, _, _) =>
case lookup: N.NodeLookupByKey[V.ContractId, Val] =>
lookup.optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setLookupByKey({
val builder = Node.LookupByKey.newBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ object Pretty {
// A minimal pretty-print of an update transaction node, without recursing into child nodes..
def prettyPartialTransactionNode(node: PartialTransaction.Node): Doc =
node match {
case create @ NodeCreate(_, _, _, _, _, _) =>
case create: NodeCreate[Value.ContractId, Value[Value.ContractId]] =>
"create" &: prettyContractInst(create.coinst)
case fetch @ NodeFetch(_, _, _, _, _, _, _) =>
case fetch: NodeFetch[Value.ContractId, Value[Value.ContractId]] =>
"fetch" &: prettyContractId(fetch.coid)
case ex @ NodeExercises(_, _, _, _, _, _, _, _, _, _, _, _, _) =>
case ex: NodeExercises[Value.NodeId, Value.ContractId, Value[Value.ContractId]] =>
intercalate(text(", "), ex.actingParties.map(p => text(p))) &
text("exercises") & text(ex.choiceId) + char(':') + prettyIdentifier(ex.templateId) &
text("on") & prettyContractId(ex.targetCoid) /
text("with") & prettyValue(false)(ex.chosenValue)
case lbk @ NodeLookupByKey(_, _, _, _) =>
case lbk: NodeLookupByKey[Value.ContractId, Value[Value.ContractId]] =>
text("lookup by key") & prettyIdentifier(lbk.templateId) /
text("key") & prettyKeyWithMaintainers(lbk.key) /
(lbk.result match {
Expand Down

0 comments on commit a9f6ec1

Please sign in to comment.