forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sandbox classic: Emulate legacy contract ID scheme (digital-asset#5929)
CHANGELOG_BEGIN CHANGELOG_END
- Loading branch information
1 parent
b954361
commit 021f4af
Showing
9 changed files
with
130 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...src/main/scala/com/digitalasset/platform/sandbox/stores/ledger/TransactionCommitter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.lf.transaction | ||
|
||
import com.daml.ledger.participant.state.v1.{CommittedTransaction, SubmittedTransaction} | ||
import com.daml.lf.data.Ref | ||
import com.daml.lf.value.Value | ||
|
||
// Convert a SubmittedTransaction to CommittedTransaction | ||
abstract class TransactionCommitter { | ||
def commitTransaction( | ||
transactionId: Ref.LedgerString, | ||
transaction: SubmittedTransaction | ||
): CommittedTransaction | ||
} | ||
|
||
// Standard committer using Contract ID V1 | ||
object StandardTransactionCommitter extends TransactionCommitter { | ||
override def commitTransaction( | ||
transactionId: Ref.LedgerString, | ||
transaction: SubmittedTransaction | ||
): CommittedTransaction = | ||
transaction.assertNoRelCid(_ => "Unexpected relative contract ID") | ||
} | ||
|
||
// Committer emulating Contract ID legacy scheme | ||
object LegacyTransactionCommitter extends TransactionCommitter { | ||
|
||
def commitTransaction( | ||
transactionId: Ref.LedgerString, | ||
transaction: SubmittedTransaction, | ||
): CommittedTransaction = { | ||
|
||
val prefix = "#" + transactionId + ":" | ||
|
||
type AbsCoid = Value.AbsoluteContractId | ||
val contractMap: AbsCoid => AbsCoid = | ||
transaction.localContracts | ||
.collect[(AbsCoid, AbsCoid), Map[AbsCoid, AbsCoid]] { | ||
case (acoid: AbsCoid, nid) => | ||
acoid -> | ||
Value.AbsoluteContractId.V0( | ||
Ref.ContractIdString.assertFromString(prefix + nid.index.toString)) | ||
} | ||
.withDefault(identity) | ||
|
||
val contractMapping: Transaction.TContractId => Value.AbsoluteContractId = { | ||
case acoid: Value.AbsoluteContractId => | ||
contractMap(acoid) | ||
case _: Value.RelativeContractId => | ||
throw new RuntimeException("Unexpected relative contract ID") | ||
} | ||
|
||
GenTransaction.map3( | ||
identity[Transaction.NodeId], | ||
contractMapping, | ||
Value.VersionedValue.map1(contractMapping) | ||
)(transaction) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.