Skip to content

Commit

Permalink
LF: Remove PartialTransaction out from ScenarioRunner/IdeLedgerClient (
Browse files Browse the repository at this point in the history
…#11368)

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Oct 25, 2021
1 parent 79037c8 commit 5365d68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private[lf] object Speedy {
}
private[lf] def finish: PartialTransaction.Result = ptx.finish
private[lf] def ptxInternal: PartialTransaction = ptx //deprecated
private[lf] def incompleteTransaction(): IncompleteTransaction = ptx.finishIncomplete
private[lf] def incompleteTransaction: IncompleteTransaction = ptx.finishIncomplete

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private[lf] object PartialTransaction {
* @param actionNodeLocations The optional locations of create/exercise/fetch/lookup nodes in pre-order.
* Used by 'locationInfo()', called by 'finish()' and 'finishIncomplete()'
*/
private[lf] case class PartialTransaction(
private[speedy] case class PartialTransaction(
packageToTransactionVersion: Ref.PackageId => TxVersion,
contractKeyUniqueness: ContractKeyUniquenessMode,
submissionTime: Time.Timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ final class ScenarioRunner(
)
if (mustFail) {
submitResult match {
case Commit(result, _, ptx) =>
currentSubmission = Some(CurrentSubmission(location, ptx.finishIncomplete))
case Commit(result, _, tx) =>
currentSubmission = Some(CurrentSubmission(location, tx))
throw scenario.Error.MustFailSucceeded(result.richTransaction.transaction)
case _: SubmissionError =>
ledger = ledger.insertAssertMustFail(committers, Set.empty, location)
Expand All @@ -109,8 +109,8 @@ final class ScenarioRunner(
currentSubmission = None
ledger = result.newLedger
callback(value)
case SubmissionError(err, ptx) =>
currentSubmission = Some(CurrentSubmission(location, ptx.finishIncomplete))
case SubmissionError(err, tx) =>
currentSubmission = Some(CurrentSubmission(location, tx))
throw err
}
}
Expand Down Expand Up @@ -193,19 +193,15 @@ object ScenarioRunner {
}
}

sealed trait SubmissionResult[+R] {
// TODO (MK) Temporary to leak the ptx from the submission machine
// to the parent machine.
def ptx: PartialTransaction
}
sealed trait SubmissionResult[+R]

final case class Commit[R](
result: R,
value: SValue,
ptx: PartialTransaction,
tx: IncompleteTransaction,
) extends SubmissionResult[R]

final case class SubmissionError(error: Error, ptx: PartialTransaction)
final case class SubmissionError(error: Error, tx: IncompleteTransaction)
extends SubmissionResult[Nothing]

// The interface we need from a ledger during submission. We allow abstracting over this so we can play
Expand Down Expand Up @@ -437,18 +433,18 @@ object ScenarioRunner {
val tx = if (doEnrichment) enrich(tx0) else tx0
ledger.commit(committers, readAs, location, tx, locationInfo) match {
case Left(err) =>
SubmissionError(err, onLedger.ptxInternal)
SubmissionError(err, onLedger.incompleteTransaction)
case Right(r) =>
Commit(r, resultValue, onLedger.ptxInternal)
Commit(r, resultValue, onLedger.incompleteTransaction)
}
case PartialTransaction.IncompleteTransaction(ptx) =>
throw new RuntimeException(s"Unexpected abort: $ptx")
}
case SResultError(err) =>
SubmissionError(Error.RunnerException(err), onLedger.ptxInternal)
SubmissionError(Error.RunnerException(err), onLedger.incompleteTransaction)
case SResultNeedContract(coid, tid @ _, committers, callback) =>
ledger.lookupContract(coid, committers, readAs, callback) match {
case Left(err) => SubmissionError(err, onLedger.ptxInternal)
case Left(err) => SubmissionError(err, onLedger.incompleteTransaction)
case Right(_) => go()
}
case SResultNeedKey(keyWithMaintainers, committers, callback) =>
Expand All @@ -459,7 +455,7 @@ object ScenarioRunner {
readAs,
callback,
) match {
case Left(err) => SubmissionError(err, onLedger.ptxInternal)
case Left(err) => SubmissionError(err, onLedger.incompleteTransaction)
case Right(_) => go()
}
case SResultNeedTime(callback) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ class IdeLedgerClient(
}
}
Right(transaction.roots.toSeq.map(convRootEvent(_)))
case ScenarioRunner.SubmissionError(err, ptx) =>
_currentSubmission =
Some(ScenarioRunner.CurrentSubmission(optLocation, ptx.finishIncomplete))
case ScenarioRunner.SubmissionError(err, tx) =>
_currentSubmission = Some(ScenarioRunner.CurrentSubmission(optLocation, tx))
throw err
}

Expand All @@ -203,8 +202,7 @@ class IdeLedgerClient(
unsafeSubmit(actAs, readAs, commands, optLocation)
.map({
case commit: ScenarioRunner.Commit[_] =>
_currentSubmission =
Some(ScenarioRunner.CurrentSubmission(optLocation, commit.ptx.finishIncomplete))
_currentSubmission = Some(ScenarioRunner.CurrentSubmission(optLocation, commit.tx))
Left(())
case _: ScenarioRunner.SubmissionError =>
_currentSubmission = None
Expand Down Expand Up @@ -246,9 +244,8 @@ class IdeLedgerClient(
ScriptLedgerClient.TransactionTree(
transaction.roots.collect(Function.unlift(convEvent(_))).toList
)
case ScenarioRunner.SubmissionError(err, ptx) =>
_currentSubmission =
Some(ScenarioRunner.CurrentSubmission(optLocation, ptx.finishIncomplete))
case ScenarioRunner.SubmissionError(err, tx) =>
_currentSubmission = Some(ScenarioRunner.CurrentSubmission(optLocation, tx))
throw new IllegalStateException(err)
}
}
Expand Down

0 comments on commit 5365d68

Please sign in to comment.