diff --git a/lib-api/src/main/java/org/ergoplatform/appkit/OutBoxBuilder.java b/lib-api/src/main/java/org/ergoplatform/appkit/OutBoxBuilder.java index 6c190e11..4648e00e 100644 --- a/lib-api/src/main/java/org/ergoplatform/appkit/OutBoxBuilder.java +++ b/lib-api/src/main/java/org/ergoplatform/appkit/OutBoxBuilder.java @@ -2,6 +2,9 @@ import org.ergoplatform.SigmaConstants; import org.ergoplatform.sdk.ErgoToken; +import sigmastate.SInt; + +import java.util.List; /** * This interface is used to build a new output box, which can be included @@ -34,11 +37,22 @@ public interface OutBoxBuilder { * * @param tokens one or more tokens to be added to the constructed output box. * @see ErgoToken + * @deprecated Use {@link #tokens(List)} instead. */ + @Deprecated OutBoxBuilder tokens(ErgoToken... tokens); /** - * Mints new token according to https://github.com/ergoplatform/eips/blob/master/eip-0004.md + * Configures amounts for tokens (up to {@link SigmaConstants.MaxTokens}). + * Each Ergo box can store zero or more tokens (aka assets). + * + * @param tokens tokens to be added to the constructed output box. + * @see ErgoToken + */ + OutBoxBuilder tokens(List tokens); + + /** + * Mints new token according to EIP-0004 * * @param token token to mint * @see Eip4Token and Eip4TokenBuilder @@ -58,6 +72,10 @@ public interface OutBoxBuilder { */ OutBoxBuilder registers(ErgoValue... registers); + default OutBoxBuilder registers(List> registers) { + return registers(registers.toArray(new ErgoValue[0])); + } + /** * Configure the height when the transaction containing the box was created. * This height, when explicitly specified, should not exceed height of the block, diff --git a/lib-api/src/main/java/org/ergoplatform/appkit/UnsignedTransactionBuilder.java b/lib-api/src/main/java/org/ergoplatform/appkit/UnsignedTransactionBuilder.java index 0385f3cd..f0e8e180 100644 --- a/lib-api/src/main/java/org/ergoplatform/appkit/UnsignedTransactionBuilder.java +++ b/lib-api/src/main/java/org/ergoplatform/appkit/UnsignedTransactionBuilder.java @@ -23,7 +23,13 @@ public interface UnsignedTransactionBuilder { UnsignedTransactionBuilder preHeader(PreHeader ph); /** - * Adds input boxes to an already specified list of inputs or, if no input boxes defined yet, + * @deprecated Use {@link #addInputs(List)} instead. + */ + @Deprecated + UnsignedTransactionBuilder addInputs(InputBox... boxes); + + /** + * Adds input boxes to an already specified list of inputs or, if no input boxes are defined yet, * as the boxes to spend. The order is preserved. * The boxes that will be spent by the transaction when it will be included in a block. * @@ -33,17 +39,29 @@ public interface UnsignedTransactionBuilder { * as {@link OutBox} and then {@link OutBox#convertToInputWith(String, short) converted} to * {@link InputBox}. */ - UnsignedTransactionBuilder addInputs(InputBox... boxes); + UnsignedTransactionBuilder addInputs(List boxes); /** - * @deprecated use {@link #addInputs(InputBox...)} + * @deprecated Use {@link #addInputs(List)} instead. */ @Deprecated UnsignedTransactionBuilder boxesToSpend(List boxes); + /** + * @deprecated Use {@link #addDataInputs(List)} instead. + */ + @Deprecated + UnsignedTransactionBuilder addDataInputs(InputBox... boxes); + + /** + * @deprecated Use {@link #addDataInputs(List)} instead. + */ + @Deprecated + UnsignedTransactionBuilder withDataInputs(List boxes); + /** * Adds input boxes to an already specified list of data inputs or, if no data input boxes - * defined yet, set the boxes as the data input boxes to be used. The order is preserved. + * are defined yet, set the boxes as the data input boxes to be used. The order is preserved. * * @param boxes list of boxes to be used as data-inputs by the transaction. The boxes can either be * {@link BlockchainContext#getBoxesById(String...) obtained} from context of created from @@ -51,22 +69,22 @@ public interface UnsignedTransactionBuilder { * as {@link OutBox} and then {@link OutBox#convertToInputWith(String, short) converted} to * {@link InputBox}. */ - UnsignedTransactionBuilder addDataInputs(InputBox... boxes); + UnsignedTransactionBuilder addDataInputs(List boxes); /** - * @deprecated use {@link #addDataInputs(InputBox...)} + * @deprecated Use {@link #addOutputs(List)} instead. */ @Deprecated - UnsignedTransactionBuilder withDataInputs(List boxes); + UnsignedTransactionBuilder outputs(OutBox... outputs); /** - * @deprecated use {@link #addOutputs(OutBox...)} + * @deprecated Use {@link #addOutputs(List)} instead. */ @Deprecated - UnsignedTransactionBuilder outputs(OutBox... outputs); + UnsignedTransactionBuilder addOutputs(OutBox... outBoxes); /** - * Adds output boxes to an already specified list of outputs or, if no output boxes defined yet, + * Adds output boxes to an already specified list of outputs or, if no output boxes are defined yet, * as the boxes to be output. The order is preserved. * After this transaction is {@link UnsignedTransactionBuilder#build() built}, * {@link ErgoProver#sign(UnsignedTransaction)} signed, @@ -75,7 +93,7 @@ public interface UnsignedTransactionBuilder { * * @param outBoxes output boxes created by the transaction */ - UnsignedTransactionBuilder addOutputs(OutBox... outBoxes); + UnsignedTransactionBuilder addOutputs(List outBoxes); /** * Adds transaction fee output. @@ -84,11 +102,17 @@ public interface UnsignedTransactionBuilder { */ UnsignedTransactionBuilder fee(long feeAmount); + /** + * @deprecated Use {@link #tokensToBurn(List)} instead. + */ + @Deprecated + UnsignedTransactionBuilder tokensToBurn(ErgoToken... tokens); + /** * Configures amounts for tokens to be burnt. * Each Ergo box can store zero or more tokens (aka assets). * In contrast to strict requirement on ERG balance between transaction inputs and outputs, - * the amounts of output tokens can be less then the amounts of input tokens. + * the amounts of output tokens can be less than the amounts of input tokens. * This is interpreted as token burning i.e. reducing the total amount of tokens in * circulation in the blockchain. * Note, once issued/burnt, the amount of tokens in circulation cannot be increased. @@ -96,7 +120,7 @@ public interface UnsignedTransactionBuilder { * @param tokens one or more tokens to be burnt as part of the transaction. * @see ErgoToken */ - UnsignedTransactionBuilder tokensToBurn(ErgoToken... tokens); + UnsignedTransactionBuilder tokensToBurn(List tokens); /** * Adds change output to the specified address if needed. diff --git a/lib-impl/src/main/java/org/ergoplatform/appkit/impl/OutBoxBuilderImpl.scala b/lib-impl/src/main/java/org/ergoplatform/appkit/impl/OutBoxBuilderImpl.scala index 00420035..f5b30a08 100644 --- a/lib-impl/src/main/java/org/ergoplatform/appkit/impl/OutBoxBuilderImpl.scala +++ b/lib-impl/src/main/java/org/ergoplatform/appkit/impl/OutBoxBuilderImpl.scala @@ -32,6 +32,16 @@ class OutBoxBuilderImpl(_txB: UnsignedTransactionBuilderImpl) extends OutBoxBuil this } + override def tokens(tokens: java.util.List[ErgoToken]): OutBoxBuilderImpl = { + val maxTokens = SigmaConstants.MaxTokens.value + require(tokens.size <= maxTokens, SigmaConstants.MaxTokens.description + s": $maxTokens") + val iterator = tokens.iterator() + while (iterator.hasNext) { + _tokens += iterator.next + } + this + } + override def mintToken(token: Eip4Token): OutBoxBuilder = { val tokenNameVal = token.getMintingBoxR4 val tokenDescVal = token.getMintingBoxR5 diff --git a/lib-impl/src/main/java/org/ergoplatform/appkit/impl/UnsignedTransactionBuilderImpl.scala b/lib-impl/src/main/java/org/ergoplatform/appkit/impl/UnsignedTransactionBuilderImpl.scala index 69a3e971..6986a72a 100644 --- a/lib-impl/src/main/java/org/ergoplatform/appkit/impl/UnsignedTransactionBuilderImpl.scala +++ b/lib-impl/src/main/java/org/ergoplatform/appkit/impl/UnsignedTransactionBuilderImpl.scala @@ -38,6 +38,16 @@ class UnsignedTransactionBuilderImpl(val _ctx: BlockchainContextImpl) extends Un this } + override def addInputs(boxes: util.List[InputBox]): UnsignedTransactionBuilder = { + val iterator = boxes.iterator() + while (iterator.hasNext) { + iterator.next match { + case b: InputBoxImpl => _inputs.add(b) + } + } + this + } + override def boxesToSpend(inputBoxes: List[InputBox]): UnsignedTransactionBuilder = { require(_inputs.isEmpty, "inputs already specified") addInputs(JavaHelpers.toIndexedSeq(inputBoxes): _*) @@ -57,6 +67,16 @@ class UnsignedTransactionBuilderImpl(val _ctx: BlockchainContextImpl) extends Un this } + override def addDataInputs(boxes: util.List[InputBox]): UnsignedTransactionBuilder = { + val iterator = boxes.iterator() + while (iterator.hasNext) { + iterator.next match { + case b: InputBoxImpl => _dataInputs.add(b) + } + } + this + } + override def addOutputs(outBoxes: OutBox*): UnsignedTransactionBuilder = { outBoxes.foreach { case b: OutBoxImpl => _outputs.add(b) @@ -70,6 +90,16 @@ class UnsignedTransactionBuilderImpl(val _ctx: BlockchainContextImpl) extends Un this } + override def addOutputs(outBoxes: util.List[OutBox]): UnsignedTransactionBuilder = { + val iterator = outBoxes.iterator() + while (iterator.hasNext) { + iterator.next match { + case b: OutBoxImpl => _outputs.add(b) + } + } + this + } + override def fee(feeAmount: Long): UnsignedTransactionBuilder = { require(_feeAmount.isEmpty, "Fee already defined") _feeAmount = Some(feeAmount) @@ -86,6 +116,12 @@ class UnsignedTransactionBuilderImpl(val _ctx: BlockchainContextImpl) extends Un this } + override def tokensToBurn(tokens: util.List[ErgoToken]): UnsignedTransactionBuilder = { + require(_tokensToBurn.isEmpty, "Tokens to burn already specified.") + _tokensToBurn = Some(new util.ArrayList[ErgoToken](tokens)) + this + } + override def sendChangeTo(changeAddress: ErgoAddress): UnsignedTransactionBuilder = { require(_changeAddress.isEmpty, "Change address is already specified") _changeAddress = Some(changeAddress)