Skip to content

Commit

Permalink
Merge pull request #1734 from ergoplatform/v4.0.33
Browse files Browse the repository at this point in the history
Candidate for 4.0.33 release
  • Loading branch information
kushti committed Jul 4, 2022
2 parents 205eabf + 014ccf6 commit 8066c84
Show file tree
Hide file tree
Showing 39 changed files with 728 additions and 250 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -82,7 +82,7 @@ To run specific Ergo version `<VERSION>` as a service with custom config `/path/
-e MAX_HEAP=3G \
ergoplatform/ergo:<VERSION> --<networkId> -c /etc/myergo.conf

Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v4.0.32`.
Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v4.0.33`.

This will connect to the Ergo mainnet or testnet following your configuration passed in `myergo.conf` and network flag `--<networkId>`. Every default config value would be overwritten with corresponding value in `myergo.conf`. `MAX_HEAP` variable can be used to control how much memory can the node consume.

Expand Down
96 changes: 0 additions & 96 deletions ergo-wallet/src/main/scala/org/ergoplatform/wallet/Utils.scala

This file was deleted.

Expand Up @@ -7,7 +7,7 @@ import org.ergoplatform.wallet.Constants.MaxAssetsPerBox
import org.ergoplatform.wallet.{AssetUtils, TokensMap}
import scala.annotation.tailrec
import scala.collection.mutable
import org.ergoplatform.wallet.Utils._
import org.ergoplatform.wallet.transactions.TransactionBuilder._
import org.ergoplatform.wallet.boxes.BoxSelector.BoxSelectionError

/**
Expand Down
Expand Up @@ -5,7 +5,7 @@ import org.ergoplatform.wallet.boxes.BoxSelector.BoxSelectionError
import org.ergoplatform.ErgoBoxAssets
import org.ergoplatform.wallet.{AssetUtils, TokensMap}
import scorex.util.ModifierId
import org.ergoplatform.wallet.Utils._
import org.ergoplatform.wallet.transactions.TransactionBuilder._

import scala.annotation.tailrec
import scala.collection.mutable
Expand Down
@@ -1,6 +1,5 @@
package org.ergoplatform.wallet.transactions

import scala.collection.IndexedSeq
import org.ergoplatform.ErgoBox
import org.ergoplatform.DataInput
import org.ergoplatform.ErgoBoxCandidate
Expand All @@ -19,10 +18,145 @@ import scorex.crypto.hash.Digest32
import org.ergoplatform.wallet.{AssetUtils, TokensMap}
import org.ergoplatform.wallet.boxes.BoxSelector
import org.ergoplatform.wallet.boxes.DefaultBoxSelector

import scorex.crypto.authds.ADKey
import scorex.util.encode.Base16
import scala.collection.JavaConverters._

object TransactionBuilder {

/**
* @param recipientAddress - payment recipient address
* @param transferAmt - amount of ERGs to transfer
*/
case class Payment(
recipientAddress: ErgoAddress,
transferAmt: Long
)

/**
* Assembles unsigned payment transaction with multiple outputs
*
* @param inputIds - identifiers of inputs to be used in transaction
* @param feeAmt - fee amount
* @param currentHeight - current blockchain height
* @param payments - list of addresses and corresponding amounts to make outputs from
* @param changeAddress - change recipient address
* @param changeAmt - amount to return back to `changeAddress`
* @return unsigned transaction
*/
def multiPaymentTransaction(inputIds: Array[String],
feeAmt: Long,
payments: java.util.List[Payment],
changeAddress: ErgoAddress,
changeAmt: Long,
currentHeight: Int): UnsignedErgoLikeTransaction = {
val feeBox = new ErgoBoxCandidate(
feeAmt,
ErgoScriptPredef.feeProposition(),
currentHeight,
Seq.empty[(ErgoBox.TokenId, Long)].toColl,
Map.empty
)
val paymentBoxes =
payments.asScala.map { case Payment(recipientAddress, transferAmt) =>
new ErgoBoxCandidate(
transferAmt,
recipientAddress.script,
currentHeight,
Seq.empty[(ErgoBox.TokenId, Long)].toColl,
Map.empty
)
}.toVector

val outputs =
if (changeAmt == 0) {
paymentBoxes :+ feeBox
} else {
val changeBox = new ErgoBoxCandidate(
changeAmt,
changeAddress.script,
currentHeight,
Seq.empty[(ErgoBox.TokenId, Long)].toColl,
Map.empty
)
paymentBoxes ++ Vector(feeBox, changeBox)
}
val unsignedInputs = inputIds
.flatMap { id =>
Base16.decode(id)
.map(x => new UnsignedInput(ADKey @@ x))
.toOption
}.toIndexedSeq

new UnsignedErgoLikeTransaction(
unsignedInputs,
dataInputs = IndexedSeq.empty,
outputs
)
}

/**
* Assembles unsigned payment transaction.
*
* @param recipientAddress - payment recipient address
* @param changeAddress - change recipient address
* @param transferAmt - amount of ERGs to transfer
* @param feeAmt - fee amount
* @param changeAmt - amount to return back to `changeAddress`
* @param inputIds - identifiers of inputs to be used in transaction
* @param currentHeight - current blockchain height
* @return unsigned transaction
*/
def paymentTransaction(recipientAddress: ErgoAddress,
changeAddress: ErgoAddress,
transferAmt: Long,
feeAmt: Long,
changeAmt: Long,
inputIds: Array[String],
currentHeight: Int): UnsignedErgoLikeTransaction = {
val payTo = new ErgoBoxCandidate(
transferAmt,
recipientAddress.script,
currentHeight,
Seq.empty[(ErgoBox.TokenId, Long)].toColl,
Map.empty
)
val fee = new ErgoBoxCandidate(
feeAmt,
ErgoScriptPredef.feeProposition(),
currentHeight,
Seq.empty[(ErgoBox.TokenId, Long)].toColl,
Map.empty
)
val change = new ErgoBoxCandidate(
changeAmt,
changeAddress.script,
currentHeight,
Seq.empty[(ErgoBox.TokenId, Long)].toColl,
Map.empty
)
val unsignedInputs = inputIds
.flatMap { id =>
Base16.decode(id)
.map(x => new UnsignedInput(ADKey @@ x))
.toOption
}
.toIndexedSeq

val dataInputs = IndexedSeq.empty
val outputs = if (changeAmt == 0) {
IndexedSeq(payTo, fee)
} else {
IndexedSeq(payTo, change, fee)
}

new UnsignedErgoLikeTransaction(
unsignedInputs,
dataInputs,
outputs
)
}

def collectOutputTokens(outputCandidates: Seq[ErgoBoxCandidate]): TokensMap = {
AssetUtils.mergeAssets(
initialMap = Map.empty[ModifierId, Long],
Expand Down Expand Up @@ -147,4 +281,28 @@ object TransactionBuilder {
)
}

implicit class EitherOpsFor211[+A, +B](val source: Either[A, B]) extends AnyVal {

/** The given function is applied if this is a `Right`.
*
* {{{
* Right(12).map(x => "flower") // Result: Right("flower")
* Left(12).map(x => "flower") // Result: Left(12)
* }}}
*/
def mapRight[B1](f: B => B1): Either[A, B1] = source match {
case Right(b) => Right(f(b))
case _ => source.asInstanceOf[Either[A, B1]]
}

/** Binds the given function across `Right`.
*
* @param f The function to bind across `Right`.
*/
def flatMapRight[A1 >: A, B1](f: B => Either[A1, B1]): Either[A1, B1] = source match {
case Right(b) => f(b)
case _ => source.asInstanceOf[Either[A1, B1]]
}
}

}

0 comments on commit 8066c84

Please sign in to comment.