All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.digitalasset.ledger.client.binding.offset.LedgerOffsetOrdering.scala Maven / Gradle / Ivy

There is a newer version: 1.18.2
Show newest version
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.client.binding.offset

import com.daml.ledger.api.v1.ledger_offset.LedgerOffset
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset.LedgerBoundary.{LEDGER_BEGIN, LEDGER_END}
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset.Value.{Absolute, Boundary, Empty}

object LedgerOffsetOrdering {

  val ledgerBegin = LedgerOffset(Boundary(LEDGER_BEGIN))
  val ledgerEnd = LedgerOffset(Boundary(LEDGER_END))

  implicit val offsetOrdering: Ordering[LedgerOffset] = Ordering.fromLessThan { (a, b) =>
    a.value match {
      case Boundary(LEDGER_BEGIN) => true
      case Boundary(LEDGER_END) => false
      case Boundary(_) => emptyOffset(a)
      case Empty => emptyOffset(a)
      case Absolute(strA) =>
        b.value match {
          case Boundary(LEDGER_BEGIN) => false
          case Boundary(LEDGER_END) => true
          case Boundary(_) => emptyOffset(b)
          case Empty => emptyOffset(b)
          case Absolute(strB) => BigInt(strA) < BigInt(strB) // TODO this is not compatible with LS
        }
    }
  }

  private def emptyOffset(o: LedgerOffset): Boolean =
    throw new RuntimeException(s"Offset '$o' is empty")

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy