Skip to content

Commit

Permalink
Adapted to new model
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Oct 30, 2023
1 parent d1a035b commit a4304b7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
57 changes: 33 additions & 24 deletions node/src/main/scala/com/wavesplatform/state/StateSnapshot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import cats.data.Ior
import cats.implicits.{catsSyntaxEitherId, catsSyntaxSemigroup, toBifunctorOps, toTraverseOps}
import cats.kernel.Monoid
import com.google.protobuf.ByteString
import com.wavesplatform.account.{Address, AddressScheme, Alias, PublicKey}
import com.wavesplatform.account.{Address, Alias, PublicKey}
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
import com.wavesplatform.crypto.KeyLength
import com.wavesplatform.database.protobuf.EthereumTransactionMeta
import com.wavesplatform.lang.ValidationError
import com.wavesplatform.lang.script.ScriptReader
import com.wavesplatform.protobuf.snapshot.TransactionStateSnapshot
import com.wavesplatform.protobuf.snapshot.TransactionStateSnapshot.AssetStatic
import com.wavesplatform.protobuf.transaction.{PBAmounts, PBRecipients, PBTransactions}
import com.wavesplatform.protobuf.transaction.{PBAmounts, PBTransactions}
import com.wavesplatform.protobuf.{AddressExt, ByteStrExt, ByteStringExt}
import com.wavesplatform.state.reader.LeaseDetails.Status
import com.wavesplatform.state.reader.{LeaseDetails, SnapshotBlockchain}
import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves}
import com.wavesplatform.transaction.TxValidationError.GenericError
Expand Down Expand Up @@ -62,14 +64,14 @@ case class StateSnapshot(
orderFills.map { case (orderId, VolumeAndFee(volume, fee)) =>
S.OrderFill(orderId.toByteString, volume, fee)
}.toSeq,
leaseStates.map { case (leaseId, details @ LeaseDetails(sender, recipient, amount, _, _, _)) =>
S.LeaseState(
leaseId.toByteString,
details.isActive,
amount,
sender.toByteString,
ByteString.copyFrom(recipient.asInstanceOf[Address].bytes)
)
leaseStates.map { case (leaseId, LeaseDetails(sender, recipient, amount, status, _, _)) =>
val pbStatus = status match {
case Status.Active =>
S.LeaseState.Status.Active(S.LeaseState.Active(amount, sender.toByteString, recipient.asInstanceOf[Address].toByteString))
case _: Status.Cancelled | _: Status.Expired =>
S.LeaseState.Status.Cancelled(S.LeaseState.Cancelled())
}
S.LeaseState(leaseId.toByteString, pbStatus)
}.toSeq,
accountScripts.map { case (publicKey, scriptOpt) =>
scriptOpt.fold(
Expand Down Expand Up @@ -161,21 +163,28 @@ object StateSnapshot {
.toMap

val leaseStates: Map[ByteStr, LeaseDetails] =
pbSnapshot.leaseStates
.map(ls =>
ls.leaseId.toByteStr -> LeaseDetails(
ls.sender.toPublicKey,
PBRecipients.toAddress(ls.recipient.toByteArray, AddressScheme.current.chainId).explicitGet(),
ls.amount,
if (ls.status)
LeaseDetails.Status.Active
else
pbSnapshot.leaseStates.map { ls =>
ls.status match {
case TransactionStateSnapshot.LeaseState.Status.Active(value) =>
ls.leaseId.toByteStr -> LeaseDetails(
value.sender.toPublicKey,
value.recipient.toAddress,
value.amount,
LeaseDetails.Status.Active,
sourceId = ByteStr.empty,
height = 0
)
case _: TransactionStateSnapshot.LeaseState.Status.Cancelled | TransactionStateSnapshot.LeaseState.Status.Empty =>
ls.leaseId.toByteStr -> LeaseDetails(
PublicKey(ByteStr.fill(KeyLength)(0)),
Address(Array.fill(Address.HashLength)(0)),
0,
LeaseDetails.Status.Cancelled(0, None),
sourceId = ByteStr.empty,
height = 0
)
)
.toMap
sourceId = ByteStr.empty,
height = 0
)
}
}.toMap

val aliases: Map[Alias, Address] =
pbSnapshot.aliases
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.wavesplatform.state.snapshot

import com.google.protobuf.ByteString
import com.wavesplatform.account.Alias
import com.wavesplatform.account.{Address, Alias, PublicKey}
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
import com.wavesplatform.crypto.KeyLength
import com.wavesplatform.lang.directives.values.V6
import com.wavesplatform.lang.v1.compiler.TestCompiler
import com.wavesplatform.protobuf.snapshot.TransactionStateSnapshot.AssetStatic
Expand Down Expand Up @@ -62,8 +63,8 @@ class StateSnapshotProtoTest extends PropSpec {
Map(
ByteStr.fromBytes(4, 5, 6) -> LeaseDetails(defaultSigner.publicKey, secondAddress, 123, Status.Active, ByteStr.empty, 0),
ByteStr.fromBytes(7, 8, 9) -> LeaseDetails(
secondSigner.publicKey,
defaultAddress,
PublicKey(ByteStr.fill(KeyLength)(0)),
Address(Array.fill(Address.HashLength)(0)),
0,
Status.Cancelled(0, None),
ByteStr.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.wavesplatform.TestValues.fee
import com.wavesplatform.account.{Address, Alias, PublicKey}
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
import com.wavesplatform.crypto.KeyLength
import com.wavesplatform.db.WithDomain
import com.wavesplatform.lang.directives.values.V6
import com.wavesplatform.lang.v1.compiler.TestCompiler
Expand Down Expand Up @@ -194,9 +195,9 @@ class StateSnapshotStorageTest extends PropSpec with WithDomain {
),
leaseStates = Map(
leaseTx.id() -> LeaseDetails(
sender.publicKey,
recipient,
leaseTx.amount.value,
PublicKey(ByteStr.fill(KeyLength)(0)),
Address(Array.fill(Address.HashLength)(0)),
0,
Cancelled(0, None),
ByteStr.empty,
0
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sbt.{Def, _}
object Dependencies {
// Node protobuf schemas
private[this] val protoSchemasLib =
"com.wavesplatform" % "protobuf-schemas" % "1.5.1-84-SNAPSHOT" classifier "protobuf-src" intransitive ()
"com.wavesplatform" % "protobuf-schemas" % "1.5.1.2-84-SNAPSHOT" classifier "protobuf-src" intransitive ()

def akkaModule(module: String): ModuleID = "com.typesafe.akka" %% s"akka-$module" % "2.6.20"

Expand Down

0 comments on commit a4304b7

Please sign in to comment.