Add functions to compute disclosure for different stream types (#4970)

* Add functions to compute disclosure for different stream types

CHANGELOG_BEGIN
CHANGELOG_END

* Address https://github.com/digital-asset/daml/pull/4970#pullrequestreview-373708955

* Optimize imports
This commit is contained in:
Stefano Baghino 2020-03-12 18:44:10 +01:00 committed by GitHub
parent f69100a4d4
commit cc2e97ee51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,32 @@
// Copyright (c) 2020 The DAML Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.digitalasset.platform.index
import com.digitalasset.daml.lf.data.Ref.Party
import com.digitalasset.daml.lf.data.Relation.Relation
import com.digitalasset.daml.lf.engine.Blinding
import com.digitalasset.daml.lf.transaction.Transaction.{NodeId, Transaction}
import com.digitalasset.daml.lf.transaction.{GenTransaction, NodeInfo}
object Disclosure {
def forFlatTransaction[Nid, Cid, Val](tx: GenTransaction[Nid, Cid, Val]): Relation[Nid, Party] =
tx.nodes.collect {
case (nodeId, c: NodeInfo.Create) =>
nodeId -> c.stakeholders
case (nodeId, e: NodeInfo.Exercise) if e.consuming =>
nodeId -> e.stakeholders
}
def forTransactionTree(tx: Transaction): Relation[NodeId, Party] = {
val createAndExercise: Set[NodeId] =
tx.nodes.collect {
case p @ (_, _: NodeInfo.Create) => p
case p @ (_, _: NodeInfo.Exercise) => p
}.keySet
Blinding.blind(tx).disclosure.filterKeys(createAndExercise)
}
}