Skip to content

Commit

Permalink
Simplified PBSince
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Nov 7, 2023
1 parent c73b0e8 commit d5b9aa3
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions node/src/main/scala/com/wavesplatform/transaction/PBSince.scala
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package com.wavesplatform.transaction

import com.wavesplatform.protobuf.transaction.PBTransactions
import com.wavesplatform.transaction.PBSince.*

trait PBSince { self: Transaction with VersionedTransaction =>
def protobufVersion: TxVersion
final def isProtobufVersion: Boolean = self.version >= protobufVersion
import scala.annotation.nowarn

override def bytesSize: Int =
if (isProtobufVersion) PBTransactions.protobuf(self).serializedSize else bytes().length
sealed trait PBSince { self: Transaction & VersionedTransaction =>
lazy val protobufVersion: TxVersion = this match {
case _: V1 => TxVersion.V1
case _: V2 => TxVersion.V2: @nowarn // scalac: unreachable code
case _: V3 => TxVersion.V3
}
final def isProtobufVersion: Boolean = self.version >= protobufVersion
}

object PBSince {
trait V1 extends PBSince { self: Transaction with VersionedTransaction =>
override def protobufVersion: TxVersion = TxVersion.V1
}

trait V2 extends PBSince { self: Transaction with VersionedTransaction =>
override def protobufVersion: TxVersion = TxVersion.V2
}

trait V3 extends PBSince { self: Transaction with VersionedTransaction =>
override def protobufVersion: TxVersion = TxVersion.V3
}
trait V1 extends PBSince { self: Transaction & VersionedTransaction => }
trait V2 extends PBSince { self: Transaction & VersionedTransaction => }
trait V3 extends PBSince { self: Transaction & VersionedTransaction => }
}

0 comments on commit d5b9aa3

Please sign in to comment.