-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NODE-2626 Corrected snapshot hash of LeaseState (#3909)
- Loading branch information
Showing
18 changed files
with
195 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
node/src/main/scala/com/wavesplatform/state/LeaseSnapshot.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.wavesplatform.state | ||
import com.wavesplatform.account.{AddressOrAlias, PublicKey} | ||
import com.wavesplatform.common.state.ByteStr | ||
import com.wavesplatform.state.reader.LeaseDetails | ||
import com.wavesplatform.transaction.Transaction | ||
import com.wavesplatform.transaction.lease.LeaseCancelTransaction | ||
|
||
import scala.util.Try | ||
|
||
case class LeaseSnapshot(sender: PublicKey, recipient: AddressOrAlias, amount: Long, status: LeaseDetails.Status) { | ||
val isActive: Boolean = status == LeaseDetails.Status.Active | ||
|
||
def toDetails(blockchain: Blockchain, txOpt: Option[Transaction], innerDetails: => Option[LeaseDetails]): LeaseDetails = { | ||
def height(id: ByteStr) = blockchain.transactionMeta(id).map(_.height).getOrElse(blockchain.height) | ||
val (sourceId, sourceHeight) = txOpt match { | ||
case Some(c: LeaseCancelTransaction) => (c.leaseId, height(c.leaseId)) | ||
case Some(i) if isActive => (i.id(), blockchain.height) // produced by lease or invoke (including eth) | ||
case Some(i) if !isActive && innerDetails.isEmpty => (i.id(), blockchain.height) // produced and cancelled by the same invoke | ||
case _ => | ||
def id = innerDetails.get.sourceId // cancelled by invoke and produced by other transaction from the state | ||
Try((id, height(id))).getOrElse((ByteStr.empty, 0)) | ||
} | ||
LeaseDetails(sender, recipient, amount, status, sourceId, sourceHeight) | ||
} | ||
} | ||
|
||
object LeaseSnapshot { | ||
def fromDetails(details: LeaseDetails): LeaseSnapshot = | ||
LeaseSnapshot(details.sender, details.recipient, details.amount, details.status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.