Skip to content

Commit

Permalink
NODE-864: Aliases in liquid blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot committed Jun 25, 2018
1 parent f77c3b4 commit 206d14a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
18 changes: 7 additions & 11 deletions src/main/scala/com/wavesplatform/database/LevelDBWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.wavesplatform.settings.FunctionalitySettings
import com.wavesplatform.state._
import com.wavesplatform.state.reader.LeaseDetails
import org.iq80.leveldb.{DB, ReadOptions}
import scorex.account.{Address, AddressOrAlias, Alias}
import scorex.account.{Address, Alias}
import scorex.block.{Block, BlockHeader}
import scorex.transaction.Transaction.Type
import scorex.transaction.ValidationError.{AliasDoesNotExist, AliasIsDisabled}
Expand Down Expand Up @@ -513,16 +513,12 @@ class LevelDBWriter(writableDB: DB, fs: FunctionalitySettings, val maxCacheSize:
}
}

override def resolveAlias(a: AddressOrAlias): Either[ValidationError, Address] = a match {
case addr: Address => Right(addr)
case alias: Alias =>
readOnly { db =>
if (db.get(Keys.aliasIsDisabled(alias))) Left(AliasIsDisabled(alias))
else
db.get(Keys.addressIdOfAlias(alias))
.map(addressId => db.get(Keys.idToAddress(addressId)))
.toRight(AliasDoesNotExist(alias))
}
override def resolveAlias(alias: Alias): Either[ValidationError, Address] = readOnly { db =>
if (db.get(Keys.aliasIsDisabled(alias))) Left(AliasIsDisabled(alias))
else
db.get(Keys.addressIdOfAlias(alias))
.map(addressId => db.get(Keys.idToAddress(addressId)))
.toRight(AliasDoesNotExist(alias))
}

override def leaseDetails(leaseId: ByteStr): Option[LeaseDetails] = readOnly { db =>
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/wavesplatform/state/Blockchain.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wavesplatform.state

import com.wavesplatform.state.reader.LeaseDetails
import scorex.account.{Address, AddressOrAlias}
import scorex.account.{Address, AddressOrAlias, Alias}
import scorex.block.{Block, BlockHeader}
import scorex.transaction.lease.LeaseTransaction
import scorex.transaction.smart.script.Script
Expand Down Expand Up @@ -47,7 +47,7 @@ trait Blockchain {

def assetDescription(id: ByteStr): Option[AssetDescription]

def resolveAlias(a: AddressOrAlias): Either[ValidationError, Address]
def resolveAlias(a: Alias): Either[ValidationError, Address]

def leaseDetails(leaseId: ByteStr): Option[LeaseDetails]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.wavesplatform.utils.{UnsupportedFeature, forceStopApplication}
import kamon.Kamon
import monix.reactive.Observable
import monix.reactive.subjects.ConcurrentSubject
import scorex.account.{Address, AddressOrAlias}
import scorex.account.{Address, Alias}
import scorex.block.Block.BlockId
import scorex.block.{Block, BlockHeader, MicroBlock}
import scorex.transaction.Transaction.Type
Expand Down Expand Up @@ -416,8 +416,8 @@ class BlockchainUpdaterImpl(blockchain: Blockchain, settings: WavesSettings, tim
CompositeBlockchain.composite(blockchain, diff).assetDescription(id)
}

override def resolveAlias(a: AddressOrAlias): Either[ValidationError, Address] = ngState.fold(blockchain.resolveAlias(a)) { ng =>
CompositeBlockchain.composite(blockchain, ng.bestLiquidDiff).resolveAlias(a)
override def resolveAlias(alias: Alias): Either[ValidationError, Address] = ngState.fold(blockchain.resolveAlias(alias)) { ng =>
CompositeBlockchain.composite(blockchain, ng.bestLiquidDiff).resolveAlias(alias)
}

override def leaseDetails(leaseId: AssetId): Option[LeaseDetails] = ngState match {
Expand Down
7 changes: 6 additions & 1 deletion src/main/scala/com/wavesplatform/state/package.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wavesplatform

import scorex.account.{Address, Alias}
import scorex.account.{Address, AddressOrAlias, Alias}
import scorex.block.Block
import scorex.transaction.ValidationError.{AliasDoesNotExist, GenericError}
import scorex.transaction._
Expand Down Expand Up @@ -53,6 +53,11 @@ package object state {

def genesis: Block = blockchain.blockAt(1).get

def resolveAlias(a: AddressOrAlias): Either[ValidationError, Address] = a match {
case addr: Address => Right(addr)
case alias: Alias => blockchain.resolveAlias(alias)
}

def canCreateAlias(alias: Alias): Boolean = blockchain.resolveAlias(alias) match {
case Left(AliasDoesNotExist(_)) => true
case _ => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.wavesplatform.state.reader
import cats.implicits._
import cats.kernel.Monoid
import com.wavesplatform.state._
import scorex.account.{Address, AddressOrAlias}
import scorex.account.{Address, AddressOrAlias, Alias}
import scorex.block.{Block, BlockHeader}
import scorex.transaction.Transaction.Type
import scorex.transaction.ValidationError.AliasDoesNotExist
import scorex.transaction.ValidationError.{AliasDoesNotExist, AliasIsDisabled}
import scorex.transaction.assets.IssueTransaction
import scorex.transaction.lease.LeaseTransaction
import scorex.transaction.smart.script.Script
Expand Down Expand Up @@ -92,11 +92,11 @@ class CompositeBlockchain(inner: Blockchain, maybeDiff: => Option[Diff]) extends
}
}

override def resolveAlias(a: AddressOrAlias): Either[ValidationError, Address] =
inner.resolveAlias(a).left.flatMap {
case adne @ AliasDoesNotExist(alias) => diff.aliases.get(alias).toRight(adne)
case other => Left(other)
}
override def resolveAlias(alias: Alias): Either[ValidationError, Address] = inner.resolveAlias(alias) match {
case l @ Left(AliasIsDisabled(_)) => l
case Right(addr) => Right(diff.aliases.getOrElse(alias, addr))
case Left(adne: AliasDoesNotExist) => diff.aliases.get(alias).toRight(adne)
}

override def allActiveLeases: Set[LeaseTransaction] = {
val (active, canceled) = diff.leaseState.partition(_._2)
Expand Down

0 comments on commit 206d14a

Please sign in to comment.