io.proximax.sdk.model.transaction.builder.AggregateTransactionBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-xpx-chain-sdk Show documentation
Show all versions of java-xpx-chain-sdk Show documentation
The ProximaX Sirius Chain Java SDK is a Java library for interacting with the Sirius Blockchain.
The newest version!
/*
* Copyright 2019 ProximaX Limited. All rights reserved.
* Use of this source code is governed by the Apache 2.0
* license that can be found in the LICENSE file.
*/
package io.proximax.sdk.model.transaction.builder;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import io.proximax.sdk.model.transaction.AggregateTransaction;
import io.proximax.sdk.model.transaction.AggregateTransactionCosignature;
import io.proximax.sdk.model.transaction.EntityType;
import io.proximax.sdk.model.transaction.EntityVersion;
import io.proximax.sdk.model.transaction.Transaction;
/**
*
* builder for {@link AggregateTransaction}
*
*
* Standard use: call {@link #innerTransactions(List)} or {@link #innerTransactions(Transaction...)} to specify
* transactions that will be bundled inside of created aggregate transaction
*
*/
public class AggregateTransactionBuilder extends TransactionBuilder {
private List innerTransactions;
private List cosignatures;
private AggregateTransactionBuilder(EntityType type, Integer version) {
super(type, version);
// provide empty lists as defaults
this.innerTransactions = new ArrayList<>();
this.cosignatures = new ArrayList<>();
}
public static AggregateTransactionBuilder createBonded() {
return new AggregateTransactionBuilder(EntityType.AGGREGATE_BONDED, EntityVersion.AGGREGATE_BONDED.getValue());
}
public static AggregateTransactionBuilder createComplete() {
return new AggregateTransactionBuilder(EntityType.AGGREGATE_COMPLETE,
EntityVersion.AGGREGATE_COMPLETE.getValue());
}
@Override
protected AggregateTransactionBuilder self() {
return this;
}
@Override
public AggregateTransaction build() {
// use or calculate maxFee
BigInteger maxFee = getMaxFee()
.orElseGet(() -> getMaxFeeCalculation(AggregateTransaction.calculatePayloadSize(getInnerTransactions())));
// create transaction instance
return new AggregateTransaction(getType(), getNetworkType(), getVersion(), getDeadline(), maxFee, getSignature(),
getSigner(), getTransactionInfo(), getInnerTransactions(), getCosignatures());
}
// ------------------------------------- setters ---------------------------------------------//
/**
* set list of inner transactions
*
* @param innerTransactions inner transactions
* @return the builder
*/
public AggregateTransactionBuilder innerTransactions(List innerTransactions) {
this.innerTransactions = innerTransactions;
return self();
}
/**
* set list of available cosignatures
*
* @param cosignatures list of cosignatures
* @return the builder
*/
public AggregateTransactionBuilder cosignatures(List cosignatures) {
this.cosignatures = cosignatures;
return self();
}
// -------------------------------------- getters --------------------------------------------//
/**
* @return the innerTransactions
*/
public List getInnerTransactions() {
return innerTransactions;
}
/**
* @return the cosignatures
*/
public List getCosignatures() {
return cosignatures;
}
// -------------------------------------- convenience --------------------------------------------//
/**
* set list of inner transactions
*
* @param innerTransactions inner transactions
* @return the builder
*/
public AggregateTransactionBuilder innerTransactions(Transaction... innerTransactions) {
return innerTransactions(Arrays.asList(innerTransactions));
}
/**
* set list of cosignatures
*
* @param cosignatures cosignatures
* @return the builder
*/
public AggregateTransactionBuilder cosignatures(AggregateTransactionCosignature... cosignatures) {
return cosignatures(Arrays.asList(cosignatures));
}
}