Skip to content

Commit

Permalink
DAML-LF: cleanup last refs to Absolute Contract IDs (#6126)
Browse files Browse the repository at this point in the history
follow up of #5991

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored May 27, 2020
1 parent ccb496e commit 3f29ac8
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ object Ordering extends scala.math.Ordering[SValue] {
private def compareText(text1: String, text2: String): Int =
Utf8.Ordering.compare(text1, text2)

private def compareAbsCid(cid1: ContractId, cid2: ContractId): Int =
private def compareCid(cid1: ContractId, cid2: ContractId): Int =
(cid1, cid2) match {
case (ContractId.V0(s1), ContractId.V0(s2)) =>
s1 compareTo s2
Expand Down Expand Up @@ -171,7 +171,7 @@ object Ordering extends scala.math.Ordering[SValue] {
}
case SContractId(coid1: ContractId) => {
case SContractId(coid2: ContractId) =>
compareAbsCid(coid1, coid2) -> ImmArray.empty
compareCid(coid1, coid2) -> ImmArray.empty
}
case STypeRep(t1) => {
case STypeRep(t2) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,6 @@ object Transaction {
byKeyNodes: ImmArray[Value.NodeId],
)

type AbsTransaction = GenTransaction.WithTxValue[NodeId, Value.ContractId]

type AbsNode = GenNode.WithTxValue[NodeId, Value.ContractId]

/** Errors that can happen during building transactions. */
sealed abstract class TransactionError extends Product with Serializable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ object domain {
type ApplicationId = Ref.LedgerString @@ ApplicationIdTag
val ApplicationId: Tag.TagOf[ApplicationIdTag] = Tag.of[ApplicationIdTag]

sealed trait AbsoluteNodeIdTag

case class Commands(
ledgerId: LedgerId,
workflowId: Option[WorkflowId],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ private[state] object Conversions {
Duration.ofSeconds(dur.getSeconds, dur.getNanos.toLong)
}

def encodeTransaction(tx: Transaction.AbsTransaction): TransactionOuterClass.Transaction = {
def encodeTransaction(tx: Transaction.Transaction): TransactionOuterClass.Transaction = {
TransactionCoder
.encodeTransaction(TransactionCoder.NidEncoder, ValueCoder.CidEncoder, tx)
.fold(err => throw Err.EncodeError("Transaction", err.errorMessage), identity)
}

def decodeTransaction(tx: TransactionOuterClass.Transaction): Transaction.AbsTransaction = {
def decodeTransaction(tx: TransactionOuterClass.Transaction): Transaction.Transaction = {
TransactionCoder
.decodeVersionedTransaction(
TransactionCoder.NidDecoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private[kvutils] object InputsAndEffects {
* and packages.
*/
def computeInputs(
tx: Transaction.AbsTransaction,
tx: Transaction.Transaction,
meta: TransactionMeta,
): List[DamlStateKey] = {
val inputs = mutable.LinkedHashSet[DamlStateKey]()
Expand Down Expand Up @@ -106,7 +106,7 @@ private[kvutils] object InputsAndEffects {
}

/** Compute the effects of a DAML transaction, that is, the created and consumed contracts. */
def computeEffects(tx: Transaction.AbsTransaction): Effects = {
def computeEffects(tx: Transaction.Transaction): Effects = {
// TODO(JM): Skip transient contracts in createdContracts/updateContractKeys. E.g. rewrite this to
// fold bottom up (with reversed roots!) and skip creates of archived contracts.
tx.fold(Effects.empty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KeyValueSubmission(metrics: Metrics) {
*
* @deprecated Use [[KeyValueCommitting.submissionOutputs]] instead. This function will be removed in later version.
*/
def transactionOutputs(tx: Transaction.AbsTransaction): List[DamlStateKey] =
def transactionOutputs(tx: Transaction.Transaction): List[DamlStateKey] =
metrics.daml.kvutils.submission.conversion.transactionOutputs.time { () =>
val effects = InputsAndEffects.computeEffects(tx)
effects.createdContracts.map(_._1) ++ effects.consumedContracts
Expand All @@ -42,7 +42,7 @@ class KeyValueSubmission(metrics: Metrics) {
def transactionToSubmission(
submitterInfo: SubmitterInfo,
meta: TransactionMeta,
tx: Transaction.AbsTransaction,
tx: Transaction.Transaction,
): DamlSubmission =
metrics.daml.kvutils.submission.conversion.transactionToSubmission.time { () =>
val inputDamlStateFromTx = InputsAndEffects.computeInputs(tx, meta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.daml.lf.data.Time.Timestamp
import com.daml.lf.engine.{Blinding, Engine}
import com.daml.lf.language.Ast
import com.daml.lf.transaction.{BlindingInfo, GenTransaction, Node}
import com.daml.lf.transaction.Transaction.AbsTransaction
import com.daml.lf.transaction.Transaction.Transaction
import com.daml.lf.value.Value
import com.daml.lf.value.Value.ContractId
import com.daml.metrics.Metrics
Expand Down Expand Up @@ -600,7 +600,7 @@ private[kvutils] object TransactionCommitter {
val submitterInfo: DamlSubmitterInfo = submission.getSubmitterInfo
val commandId: String = submitterInfo.getCommandId
val submitter: Party = Party.assertFromString(submitterInfo.getSubmitter)
lazy val absoluteTransaction: AbsTransaction =
lazy val absoluteTransaction: Transaction =
Conversions.decodeTransaction(submission.getTransaction)
val submissionTime: Timestamp = Conversions.parseTimestamp(submission.getSubmissionTime)
val submissionSeed: crypto.Hash = Conversions.parseHash(submission.getSubmissionSeed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ object ParticipantStateIntegrationSpecBase {

private val IdleTimeout: FiniteDuration = 5.seconds

private val emptyTransaction: Transaction.AbsTransaction =
private val emptyTransaction: Transaction.Transaction =
GenTransaction(HashMap.empty, ImmArray.empty)

private val participantId: ParticipantId = Ref.ParticipantId.assertFromString("test-participant")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ object KVTest {
submissionSeed: crypto.Hash,
additionalContractDataTy: String,
cmds: Command*,
): KVTest[(Transaction.AbsTransaction, Transaction.Metadata)] =
): KVTest[(Transaction.Transaction, Transaction.Metadata)] =
for {
s <- get[KVTestState]
(tx, meta) = engine
Expand Down Expand Up @@ -200,12 +200,12 @@ object KVTest {
submitter: Party,
submissionSeed: crypto.Hash,
cmds: Command*,
): KVTest[(Transaction.AbsTransaction, Transaction.Metadata)] =
): KVTest[(Transaction.Transaction, Transaction.Metadata)] =
runCommand(submitter, submissionSeed, defaultAdditionalContractDataTy, cmds: _*)

def submitTransaction(
submitter: Party,
transaction: (Transaction.AbsTransaction, Transaction.Metadata),
transaction: (Transaction.Transaction, Transaction.Metadata),
submissionSeed: crypto.Hash,
letDelta: Duration = Duration.ZERO,
commandId: CommandId = randomLedgerString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ object KeyValueParticipantStateWriterSpec {

private val aParty = Ref.Party.assertFromString("aParty")

private val anEmptyTransaction: Transaction.AbsTransaction =
private val anEmptyTransaction: Transaction.Transaction =
GenTransaction(HashMap.empty, ImmArray.empty)

private val aSubmissionId: SubmissionId =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TransactionTimeModelComplianceIT
}

private[this] def publishTxAt(ledger: Ledger, ledgerTime: Instant, commandId: String) = {
val dummyTransaction: Transaction.AbsTransaction =
val dummyTransaction: Transaction.Transaction =
GenTransaction(HashMap.empty, ImmArray.empty)

val submitterInfo = SubmitterInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,14 @@ case object LedgerApiV1 {
// ------------------------------------------------------------------------------------------------------------------

def writeArgument(value: Model.ApiValue): Result[V1.value.Value] =
wrapAbsContractId(value) flatMap (vac =>
wrapContractId(value) flatMap (vac =>
lfValueToApiValue(verbose = true, vac) leftMap GenericConversionError)

def writeRecordArgument(value: Model.ApiRecord): Result[V1.value.Record] =
wrapAbsContractId(value) flatMap (vac =>
wrapContractId(value) flatMap (vac =>
lfValueToApiRecord(verbose = true, vac) leftMap GenericConversionError)

private[this] def wrapAbsContractId(value: Model.ApiValue): Result[V[V.ContractId]] = {
private[this] def wrapContractId(value: Model.ApiValue): Result[V[V.ContractId]] = {
final class NotACoid(message: String) extends RuntimeException(message) with NoStackTrace
// this is 100% cheating as Value should have Traverse instead
try Right(value mapContractId { coid =>
Expand Down

0 comments on commit 3f29ac8

Please sign in to comment.