io.proximax.sdk.model.transaction.builder.ExchangeOfferAddTransactionBuilder 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.exchange.AddExchangeOffer;
import io.proximax.sdk.model.transaction.EntityType;
import io.proximax.sdk.model.transaction.EntityVersion;
import io.proximax.sdk.model.transaction.ExchangeOfferAddTransaction;
/**
*
* builder for {@link ExchangeOfferAddTransaction}
*
*
* Standard use: to place offers call {@link #offers(AddExchangeOffer...)}
*
*/
public class ExchangeOfferAddTransactionBuilder extends TransactionBuilder {
private List offers;
public ExchangeOfferAddTransactionBuilder() {
super(EntityType.EXCHANGE_OFFER_ADD, EntityVersion.EXCHANGE_OFFER_ADD.getValue());
// defaults
offers = new ArrayList<>();
}
@Override
protected ExchangeOfferAddTransactionBuilder self() {
return this;
}
@Override
public ExchangeOfferAddTransaction build() {
// use or calculate maxFee
BigInteger maxFee = getMaxFee().orElseGet(
() -> getMaxFeeCalculation(ExchangeOfferAddTransaction.calculatePayloadSize(getOffers().size())));
// create transaction instance
return new ExchangeOfferAddTransaction(getNetworkType(), getVersion(), getDeadline(), maxFee, getSignature(), getSigner(),
getTransactionInfo(), getOffers());
}
// ------------------------------------ setters ------------------------------------//
/**
* specify offers to be announced
*
* @param offers list of offers
* @return self
*/
public ExchangeOfferAddTransactionBuilder offers(List offers) {
this.offers = offers;
return this;
}
// ------------------------------------------- getters ------------------------------------------//
/**
* @return the mosaics
*/
public List getOffers() {
return offers;
}
// ----------------------------------------- convenience methods -------------------------------------//
/**
* @param offers the offers to set
* @return self
*/
public ExchangeOfferAddTransactionBuilder offers(AddExchangeOffer... offers) {
return offers(Arrays.asList(offers));
}
}