Skip to content

Commit

Permalink
code compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gabor-aranyossy committed Jun 5, 2019
1 parent e43cb40 commit 827af11
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ final case class SubmitterInfo(
submitter: Party,
applicationId: ApplicationId,
commandId: CommandId,
maxRecordTime: Timestamp,
maxRecordTime: Timestamp, //TODO: this should be a regular Instant
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import com.daml.ledger.participant.state.v1.{
WriteService
}
import com.digitalasset.api.util.TimeProvider
import com.digitalasset.daml.lf.data.Ref
import com.digitalasset.daml.lf.data.Time.Timestamp
import com.digitalasset.daml.lf.engine.{Error => LfError}
import com.digitalasset.daml.lf.transaction.BlindingInfo
import com.digitalasset.daml.lf.transaction.{BlindingInfo, Transaction}
import com.digitalasset.daml.lf.transaction.Transaction.Transaction
import com.digitalasset.grpc.adapter.utils.DirectExecutionContext
import com.digitalasset.ledger.api.domain.{LedgerId, Commands => ApiCommands}
Expand Down Expand Up @@ -135,19 +133,15 @@ class ApiSubmissionService private (
submissionResult <- handleResult(res)
} yield submissionResult

private def handleResult(res: scala.Either[ErrorCause, TransactionSubmission]) =
private def handleResult(
res: scala.Either[ErrorCause, (SubmitterInfo, TransactionMeta, Transaction.Transaction)]) =
res match {
case Right(ts) =>
case Right((submitterInfo, transactionMeta, transaction)) =>
FutureConverters.toScala(
writeService.submitTransaction(
SubmitterInfo(
Ref.Party.assertFromString(ts.submitter),
ts.applicationId,
ts.commandId,
Timestamp.assertFromInstant(ts.maximumRecordTime)
),
TransactionMeta(Timestamp.assertFromInstant(ts.ledgerEffectiveTime), ts.workflowId),
ts.transaction
submitterInfo,
transactionMeta,
transaction
))
case Left(err) => Future.failed(grpcError(toStatus(err)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.digitalasset.platform.sandbox.stores.ledger
import com.daml.ledger.participant.state.v1.{SubmitterInfo, TransactionMeta}
import com.digitalasset.daml.lf.command._
import com.digitalasset.daml.lf.data.Ref.Party
import com.digitalasset.daml.lf.data.Time.Timestamp
import com.digitalasset.daml.lf.engine.{Blinding, Engine}
import com.digitalasset.daml.lf.transaction.Node.GlobalKey
import com.digitalasset.daml.lf.transaction.Transaction
Expand Down Expand Up @@ -44,10 +45,10 @@ class CommandExecutorImpl(engine: Engine, packageContainer: DamlPackageContainer
submitted.submitter,
submitted.applicationId.unwrap,
submitted.commandId.unwrap,
submitted.maximumRecordTime
Timestamp.assertFromInstant(submitted.maximumRecordTime)
),
TransactionMeta(
submitted.ledgerEffectiveTime,
Timestamp.assertFromInstant(submitted.ledgerEffectiveTime),
submitted.workflowId.map(_.unwrap)
),
updateTx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import java.time.Instant

import akka.NotUsed
import akka.stream.scaladsl.Source
import com.daml.ledger.participant.state.v1.{
SubmissionResult,
SubmittedTransaction,
SubmitterInfo,
TransactionMeta
}
import com.digitalasset.daml.lf.data.Ref.TransactionIdString
import com.daml.ledger.participant.state.v1.SubmissionResult
import com.digitalasset.daml.lf.transaction.Node.GlobalKey
import com.digitalasset.daml.lf.value.Value
import com.digitalasset.daml.lf.value.Value.AbsoluteContractId
import com.digitalasset.ledger.api.domain.LedgerId
import com.digitalasset.ledger.backend.api.v1.TransactionSubmission
import com.digitalasset.platform.sandbox.metrics.MetricsManager
import com.digitalasset.platform.sandbox.stores.ActiveContracts.ActiveContract

Expand Down Expand Up @@ -42,8 +46,12 @@ private class MeteredLedger(ledger: Ledger, mm: MetricsManager) extends Ledger {
mm.timedFuture("Ledger:publishHeartbeat", ledger.publishHeartbeat(time))

override def publishTransaction(
transactionSubmission: TransactionSubmission): Future[SubmissionResult] =
mm.timedFuture("Ledger:publishTransaction", ledger.publishTransaction(transactionSubmission))
submitterInfo: SubmitterInfo,
transactionMeta: TransactionMeta,
transaction: SubmittedTransaction): Future[SubmissionResult] =
mm.timedFuture(
"Ledger:publishTransaction",
ledger.publishTransaction(submitterInfo, transactionMeta, transaction))

override def lookupTransaction(
transactionId: TransactionIdString): Future[Option[(Long, LedgerEntry.Transaction)]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.daml.ledger.participant.state.v1.SubmittedTransaction
import com.daml.ledger.participant.state.{v1 => ParticipantState}
import com.digitalasset.daml.lf.data.Ref
import com.digitalasset.daml.lf.data.Ref.{LedgerString, PackageId, Party, TransactionIdString}
import com.digitalasset.daml.lf.engine.Blinding
import com.digitalasset.daml.lf.transaction.Node.GlobalKey
import com.digitalasset.daml.lf.value.Value
import com.digitalasset.daml.lf.value.Value.{AbsoluteContractId, ContractInst}
Expand All @@ -33,7 +32,7 @@ import com.digitalasset.platform.services.time.TimeModel
import scalaz.syntax.tag._

import scala.compat.java8.FutureConverters
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.{Future, Promise}

class SandboxIndexService(
ledger: Ledger,
Expand Down Expand Up @@ -92,47 +91,28 @@ class SandboxIndexService(
override def submitTransaction(
submitterInfo: ParticipantState.SubmitterInfo,
transactionMeta: ParticipantState.TransactionMeta,
transaction: SubmittedTransaction): CompletionStage[ParticipantState.SubmissionResult] = {

implicit val ec: ExecutionContext = mat.executionContext

//note, that this cannot fail as it's already validated
val blindingInfo = Blinding
.checkAuthorizationAndBlind(transaction, Set(submitterInfo.submitter))
.fold(authorisationError => sys.error(authorisationError.detailMsg), identity)

val transactionSubmission =
TransactionSubmission(
submitterInfo.commandId,
transactionMeta.workflowId,
submitterInfo.submitter,
transactionMeta.ledgerEffectiveTime.toInstant,
submitterInfo.maxRecordTime.toInstant,
submitterInfo.applicationId,
blindingInfo,
transaction
)

val resultF = ledger.publishTransaction(transactionSubmission)

FutureConverters.toJava(resultF)
}
transaction: SubmittedTransaction): CompletionStage[ParticipantState.SubmissionResult] =
FutureConverters.toJava(ledger.publishTransaction(submitterInfo, transactionMeta, transaction))

override def transactionTrees(
begin: LedgerOffset,
endAt: Option[LedgerOffset],
filter: domain.TransactionFilter): Source[domain.TransactionTree, NotUsed] = {
filter: domain.TransactionFilter): Source[domain.TransactionTree, NotUsed] =
acceptedTransactions(begin, endAt)
.mapConcat(TransactionConversion.acceptedToDomainTree(_, filter).toList)
}
.mapConcat {
case (offset, transaction) =>
TransactionConversion.acceptedToDomainTree(offset, transaction, filter).toList
}

override def transactions(
begin: domain.LedgerOffset,
endAt: Option[domain.LedgerOffset],
filter: domain.TransactionFilter): Source[domain.Transaction, NotUsed] = {
filter: domain.TransactionFilter): Source[domain.Transaction, NotUsed] =
acceptedTransactions(begin, endAt)
.mapConcat(TransactionConversion.acceptedToDomainFlat(_, filter).toList)
}
.mapConcat {
case (offset, transaction) =>
TransactionConversion.acceptedToDomainFlat(offset, transaction, filter).toList
}

private class OffsetConverter {
lazy val currentEndF = currentLedgerEnd()
Expand All @@ -146,7 +126,7 @@ class SandboxIndexService(
}

private def acceptedTransactions(begin: domain.LedgerOffset, endAt: Option[domain.LedgerOffset])
: Source[(LedgerOffset, LedgerEntry.Transaction), NotUsed] = {
: Source[(LedgerOffset.Absolute, LedgerEntry.Transaction), NotUsed] = {
val converter = new OffsetConverter()

converter.toAbsolute(begin).flatMapConcat {
Expand Down Expand Up @@ -184,8 +164,8 @@ class SandboxIndexService(
// If we don't do this, the response stream will linger until a transaction is committed AFTER the end offset.
// The immediate effect is that integration tests will not complete within the timeout.
finalStream.collect {
case (offset, t @ LedgerEntry.Transaction) =>
(domain.LedgerOffsetAbsolute(LedgerString.assertFromString(offset + 1)), t)
case (offset, t: LedgerEntry.Transaction) =>
(LedgerOffset.Absolute(LedgerString.assertFromString((offset + 1).toString)), t)
}
}
}
Expand All @@ -200,7 +180,13 @@ class SandboxIndexService(
val filter =
domain.TransactionFilter(requestingParties.map(p => p -> domain.Filters.noFilter).toMap)
getTransactionById(transactionId.unwrap)
.map(_.flatMap(TransactionConversion.acceptedToDomainFlat(_, filter)))(DEC)
.map(_.flatMap {
case (offset, transaction) =>
TransactionConversion.acceptedToDomainFlat(
LedgerOffset.Absolute(LedgerString.assertFromString(offset.toString)),
transaction,
filter)
})(DEC)
}

override def getTransactionTreeById(
Expand All @@ -209,7 +195,13 @@ class SandboxIndexService(
val filter =
domain.TransactionFilter(requestingParties.map(p => p -> domain.Filters.noFilter).toMap)
getTransactionById(transactionId.unwrap)
.map(_.flatMap(TransactionConversion.acceptedToDomainTree(_, filter)))(DEC)
.map(_.flatMap {
case (offset, transaction) =>
TransactionConversion.acceptedToDomainTree(
LedgerOffset.Absolute(LedgerString.assertFromString(offset.toString)),
transaction,
filter)
})(DEC)
}

override def getCompletions(
Expand All @@ -220,24 +212,25 @@ class SandboxIndexService(
val converter = new OffsetConverter()
converter.toAbsolute(begin).flatMapConcat {
case LedgerOffset.Absolute(absBegin) =>
ledger.ledgerEntries(Some(absBegin)).collect {
case (offset, t @ LedgerEntry.Transaction)
if (t.applicationId == applicationId.unwrap && parties.contains(t.submitter)) =>
ledger.ledgerEntries(Some(absBegin.toLong)).collect {
case (offset, t: LedgerEntry.Transaction)
if (t.applicationId == applicationId.unwrap && parties.contains(t.submittingParty)) =>
CommandAccepted(
domain.LedgerOffset.Absolute(Ref.LedgerString.assertFromString(offset.toString)),
recordTime,
domain.CommandId(commandId),
domain.TransactionId(transactionId)
t.recordedAt,
domain.CommandId(t.commandId),
domain.TransactionId(t.transactionId)
)
case (offset, c @ LedgerEntry.Checkpoint) =>

case (offset, c: LedgerEntry.Checkpoint) =>
Checkpoint(
domain.LedgerOffset.Absolute(Ref.LedgerString.assertFromString(offset.toString)),
c.recordedAt)
case (offset, r @ LedgerEntry.Rejection) =>
case (offset, r: LedgerEntry.Rejection) =>
CommandRejected(
domain.LedgerOffset.Absolute(Ref.LedgerString.assertFromString(offset.toString)),
r.recordedAt,
r.commandId,
domain.CommandId(r.commandId),
r.rejectionReason)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.digitalasset.platform.sandbox.stores.ActiveContractsInMemory
import org.slf4j.LoggerFactory
import com.digitalasset.daml.lf.transaction.GenTransaction
import com.digitalasset.daml.lf.types.Ledger.ScenarioTransactionId
import com.digitalasset.ledger.backend.api.v1.NodeId
import com.digitalasset.platform.sandbox.stores.ledger.LedgerEntry.Transaction

import scala.collection.breakOut
Expand Down Expand Up @@ -271,6 +270,7 @@ object ScenarioLoader {
private def absCidWithHash(a: AbsoluteContractId): AbsoluteContractId =
AbsoluteContractId(Ref.ContractIdString.concat(`#`, a.coid))

private def nodeIdWithHash(nid: L.ScenarioNodeId): NodeId = Ref.ContractIdString.concat(`#`, nid)
private def nodeIdWithHash(nid: L.ScenarioNodeId): com.digitalasset.ledger.EventId =
Ref.ContractIdString.concat(`#`, nid)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.digitalasset.platform.sandbox.stores.ledger

import com.digitalasset.daml.lf.data.{Ref => LfRef}
import com.digitalasset.daml.lf.engine
import com.digitalasset.daml.lf.value.Value.{AbsoluteContractId, VersionedValue}
import com.digitalasset.daml.lf.value.{Value => Lf}
Expand All @@ -23,6 +22,7 @@ import scala.collection.breakOut
trait TransactionConversion {

def acceptedToDomainFlat(
offset: domain.LedgerOffset.Absolute,
trans: LedgerEntry.Transaction,
filter: domain.TransactionFilter
): Option[domain.Transaction] = {
Expand All @@ -40,24 +40,24 @@ trait TransactionConversion {
.flatMap(eventFilter.filterCreateOrArchiveWitnesses(_).toList)

val submitterIsSubscriber =
trans.submitter
.map(LfRef.Party.assertFromString)
.exists(eventFilter.isSubmitterSubscriber)
eventFilter.isSubmitterSubscriber(trans.submittingParty)

if (filteredEvents.nonEmpty || submitterIsSubscriber) {
Some(
domain.Transaction(
domain.TransactionId(trans.transactionId),
Tag.subst(trans.commandId).filter(_ => submitterIsSubscriber),
Tag.subst(trans.workflowId),
trans.recordTime,
Some(domain.CommandId(trans.commandId)),
trans.workflowId.map(domain.WorkflowId(_)),
trans.recordedAt,
filteredEvents,
domain.LedgerOffset.Absolute(trans.offset),
offset,
None
))
} else None
}

def acceptedToDomainTree(
offset: domain.LedgerOffset.Absolute,
trans: LedgerEntry.Transaction,
filter: domain.TransactionFilter): Option[domain.TransactionTree] = {

Expand All @@ -80,16 +80,16 @@ trait TransactionConversion {
events,
allEvents.roots.toList
.sortBy(evid => getEventIndex(evid.unwrap)))
val subscriberIsSubmitter = trans.submitter
.map(LfRef.Party.assertFromString)
.exists(TemplateAwareFilter(filter).isSubmitterSubscriber(_))

val subscriberIsSubmitter =
TemplateAwareFilter(filter).isSubmitterSubscriber(trans.submittingParty)

domain.TransactionTree(
domain.TransactionId(trans.transactionId),
Tag.subst(trans.commandId).filter(_ => subscriberIsSubmitter),
if (subscriberIsSubmitter) Some(domain.CommandId(trans.commandId)) else None,
Tag.subst(trans.workflowId),
trans.recordTime,
domain.LedgerOffset.Absolute(trans.offset),
trans.recordedAt,
offset,
byId,
roots,
None
Expand Down
Loading

0 comments on commit 827af11

Please sign in to comment.