Skip to content

Commit

Permalink
Merge branch 'version-1.4.x' into node-2348-api-liquid-balances
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 authored Oct 28, 2022
2 parents 557636f + 9ead4d4 commit 9ffa6bd
Show file tree
Hide file tree
Showing 38 changed files with 1,744 additions and 1,011 deletions.
119 changes: 0 additions & 119 deletions Jenkinsfile

This file was deleted.

11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ lazy val `lang-tests` = project
.in(file("lang/tests"))
.dependsOn(`lang-testkit`)

lazy val `lang-tests-js` = project
.in(file("lang/tests-js"))
.enablePlugins(ScalaJSPlugin)
.dependsOn(`lang-js`)
.settings(
libraryDependencies += Dependencies.scalaJsTest.value,
testFrameworks += new TestFramework("utest.runner.Framework")
)

lazy val node = project.dependsOn(`lang-jvm`, `lang-testkit` % "test")

lazy val `grpc-server` = project.dependsOn(node % "compile;test->test;runtime->provided")
Expand Down Expand Up @@ -100,6 +109,7 @@ lazy val `waves-node` = (project in file("."))
`lang-js`,
`lang-jvm`,
`lang-tests`,
`lang-tests-js`,
`lang-testkit`,
`repl-js`,
`repl-jvm`,
Expand Down Expand Up @@ -188,6 +198,7 @@ checkPRRaw := Def
(`lang-tests` / Test / test).value
(`repl-jvm` / Test / test).value
(`lang-js` / Compile / fastOptJS).value
(`lang-tests-js` / Test / test).value
(`grpc-server` / Test / test).value
(node / Test / test).value
(`repl-js` / Compile / fastOptJS).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Repo(db: DB, blocksApi: CommonBlocksApi)(implicit s: Scheduler) extends Bl
db.put(keyForHeight(ls.keyBlock.height), ls.solidify().protobuf.update(_.append.block.optionalBlock := None).toByteArray)
)

val ba = BlockAppended.from(block, diff, blockchainBeforeWithMinerReward)
val ba = BlockAppended.from(block, diff, blockchainBeforeWithMinerReward, minerReward)
liquidState = Some(LiquidState(ba, Seq.empty))
handlers.forEach(_.handleUpdate(ba))
}
Expand Down
15 changes: 6 additions & 9 deletions grpc-server/src/main/scala/com/wavesplatform/events/events.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.wavesplatform.transaction.assets.exchange.ExchangeTransaction
import com.wavesplatform.transaction.lease.LeaseTransaction
import com.wavesplatform.transaction.smart.InvokeScriptTransaction
import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction}
import com.wavesplatform.transaction.{Asset, Authorized, EthereumTransaction, GenesisTransaction}
import com.wavesplatform.transaction.{Asset, Authorized, EthereumTransaction}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
Expand Down Expand Up @@ -557,21 +557,18 @@ final case class BlockAppended(
}

object BlockAppended {
def from(block: Block, diff: DetailedDiff, blockchainBeforeWithMinerReward: Blockchain): BlockAppended = {
def from(block: Block, diff: DetailedDiff, blockchainBeforeWithMinerReward: Blockchain, minerReward: Option[Long]): BlockAppended = {
val height = blockchainBeforeWithMinerReward.height
val (blockStateUpdate, txsStateUpdates, txsMetadata, refAssets) =
StateUpdate.container(blockchainBeforeWithMinerReward, diff, block.sender.toAddress)

// updatedWavesAmount can change as a result of either genesis transactions or miner rewards
val updatedWavesAmount = blockchainBeforeWithMinerReward.height match {
// genesis case
case 0 => block.transactionData.collect { case GenesisTransaction(_, amount, _, _, _) => amount.value }.sum
// miner reward case
case height => blockchainBeforeWithMinerReward.wavesAmount(height).toLong
}
val wavesAmount = blockchainBeforeWithMinerReward.wavesAmount(height).toLong
val updatedWavesAmount = wavesAmount + minerReward.filter(_ => height > 0).getOrElse(0L)

BlockAppended(
block.id(),
blockchainBeforeWithMinerReward.height + 1,
height + 1,
block,
updatedWavesAmount,
blockStateUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.wavesplatform.events.protobuf.BlockchainUpdated.Rollback.RollbackType
import com.wavesplatform.events.protobuf.BlockchainUpdated.Update
import com.wavesplatform.events.protobuf.serde.*
import com.wavesplatform.events.protobuf.{TransactionMetadata, BlockchainUpdated as PBBlockchainUpdated}
import com.wavesplatform.features.BlockchainFeatures.BlockReward
import com.wavesplatform.history.Domain
import com.wavesplatform.lang.directives.values.V5
import com.wavesplatform.lang.v1.FunctionHeader
Expand Down Expand Up @@ -278,9 +279,74 @@ class BlockchainUpdatesSpec extends FreeSpec with WithBUDomain with ScalaFutures
)
}

"should include correct waves amount" in withNEmptyBlocksSubscription(settings = currentSettings) { result =>
val balances = result.collect { case b if b.update.isAppend => b.getAppend.getBlock.updatedWavesAmount }
balances shouldBe Seq(10000000000000000L, 10000000600000000L, 10000001200000000L)
"should include correct waves amount" - {
val totalWaves = 100_000_000_0000_0000L
val reward = 6_0000_0000

"on preactivated block reward" in {
val settings = currentSettings.setFeaturesHeight((BlockReward, 0))

withDomainAndRepo(settings) { case (d, repo) =>
d.appendBlock()
d.blockchain.wavesAmount(1) shouldBe totalWaves + reward
repo.getBlockUpdate(1).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward

d.appendBlock()
d.blockchain.wavesAmount(2) shouldBe totalWaves + reward * 2
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2
}
}

"on activation of block reward" in {
val settings = currentSettings.setFeaturesHeight((BlockReward, 3))

withNEmptyBlocksSubscription(settings = settings, count = 3) { result =>
val balances = result.collect { case b if b.update.isAppend => b.getAppend.getBlock.updatedWavesAmount }
balances shouldBe Seq(totalWaves, totalWaves, totalWaves + reward, totalWaves + reward * 2)
}

withDomainAndRepo(settings) { case (d, repo) =>
d.appendBlock()
d.blockchain.wavesAmount(1) shouldBe totalWaves
repo.getBlockUpdate(1).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves

d.appendBlock()
d.blockchain.wavesAmount(2) shouldBe totalWaves
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves

d.appendBlock()
d.blockchain.wavesAmount(3) shouldBe totalWaves + reward
repo.getBlockUpdate(3).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward

d.appendBlock()
d.blockchain.wavesAmount(4) shouldBe totalWaves + reward * 2
repo.getBlockUpdate(4).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2
}
}

"on rollbacks" in {
withDomainAndRepo(currentSettings) { case (d, repo) =>
d.appendBlock()

// block and micro append
val block = d.appendBlock()
block.sender shouldBe defaultSigner.publicKey

d.appendMicroBlock(TxHelpers.transfer(defaultSigner))
d.blockchain.wavesAmount(2) shouldBe totalWaves + reward * 2
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2

// micro rollback
d.appendKeyBlock(Some(block.id()))
d.blockchain.wavesAmount(3) shouldBe totalWaves + reward * 3
repo.getBlockUpdate(3).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 3

// block rollback
d.rollbackTo(2)
d.blockchain.wavesAmount(2) shouldBe totalWaves + reward * 2
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2
}
}
}

"should include correct heights" in withNEmptyBlocksSubscription(settings = currentSettings) { result =>
Expand Down
11 changes: 8 additions & 3 deletions lang/js/src/main/scala/JsAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,19 @@ object JsAPI {
"ast" -> toJs(expr),
"complexity" -> complexity.toDouble
)
case CompileResult.DApp(_, di, error) =>
case CompileResult.DApp(_, di, meta, error) =>
val mappedMeta =
meta.argsWithFuncName.map { case (func, argsWithName) =>
func -> argsWithName.map { case (arg, argType) => arg -> argType.name }.toJSArray
}.toJSDictionary

val compactNameToOriginalName: Map[String, String] =
di.dApp.meta.compactNameAndOriginalNamePairList.map(pair => pair.compactName -> pair.originalName).toMap

val resultFields: Seq[(String, Any)] = Seq(
"result" -> Global.toBuffer(di.bytes),
"ast" -> toJs(di.dApp),
"meta" -> mappedMeta,
"complexity" -> di.maxComplexity._2.toDouble,
"verifierComplexity" -> di.verifierComplexity.toDouble,
"callableComplexities" -> di.callableComplexities.view.mapValues(_.toDouble).toMap.toJSDictionary,
Expand All @@ -176,13 +182,12 @@ object JsAPI {
compactNameToOriginalName.getOrElse(name, name) -> complexity.toDouble
}.toJSDictionary
)
val errorFieldOpt: Seq[(String, Any)] = {
val errorFieldOpt: Seq[(String, Any)] =
error
.fold(
error => Seq("error" -> error),
_ => Seq()
)
}
js.Dynamic.literal.applyDynamic("apply")((resultFields ++ errorFieldOpt)*)
}
)
Expand Down
10 changes: 5 additions & 5 deletions lang/js/src/main/scala/JsApiUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ object JsApiUtils {
}

jObj.applyDynamic("apply")(
"type" -> "DAPP",
"posStart" -> ast.position.start,
"posEnd" -> ast.position.end,
"decList" -> ast.decs.map(serDec).toJSArray,
"annFuncList" -> ast.fs.map(serAnnFunc)
"type" -> "DAPP",
"posStart" -> ast.position.start,
"posEnd" -> ast.position.end,
"decList" -> ast.decs.map(serDec).toJSArray,
"annFuncList" -> ast.fs.map(serAnnFunc).toJSArray
)
}

Expand Down
24 changes: 8 additions & 16 deletions lang/js/src/main/scala/com/wavesplatform/lang/Global.scala
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
package com.wavesplatform.lang

import java.math.{BigInteger, BigDecimal => BD}

import cats.syntax.either._
import cats.syntax.either.*
import com.wavesplatform.common.utils.{Base58, Base64}
import com.wavesplatform.lang.v1.BaseGlobal
import com.wavesplatform.lang.v1.evaluator.ctx.impl.Rounding
import com.wavesplatform.lang.v1.evaluator.ctx.impl.crypto.RSA.DigestAlgorithm

import java.math.{BigInteger, BigDecimal as BD}
import scala.collection.mutable
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.JSConverters.*
import scala.scalajs.js.typedarray.{ArrayBuffer, Int8Array}
import scala.util.Try

object Global extends BaseGlobal {
def base58Encode(input: Array[Byte]): Either[String, String] = Right(impl.Global.base58Encode(toBuffer(input)))
def base58Encode(input: Array[Byte]): Either[String, String] = Right(Base58.encode(input))
override def base58Decode(input: String, limit: Int): Either[String, Array[Byte]] =
for {
_ <- Either.cond(input.length <= limit, {}, s"Input is too long (${input.length}), limit is $limit")
x <- impl.Global
.base58Decode(input)
.toOption
.map(toArray)
.toRight("Cannot decode")
x <- Try(Base58.decode(input)).toEither.leftMap(_.getMessage)
} yield x

override def base64Encode(input: Array[Byte]): Either[String, String] = Right(impl.Global.base64Encode(toBuffer(input)))
override def base64Encode(input: Array[Byte]): Either[String, String] = Right(Base64.encode(input))
override def base64Decode(input: String, limit: Int): Either[String, Array[Byte]] =
for {
_ <- Either.cond(input.length <= limit, {}, s"Input is too long (${input.length}), limit is $limit")
x <- impl.Global
.base64Decode(input)
.toOption
.map(toArray)
.toRight("Cannot decode")
x <- Try(Base64.decode(input)).toEither.leftMap(_.getMessage)
} yield x

private val hex: Array[Char] = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')
Expand Down
Loading

0 comments on commit 9ffa6bd

Please sign in to comment.