All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.proximax.sdk.model.transaction.builder.BlockchainConfigTransactionBuilder Maven / Gradle / Ivy

Go to download

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 io.proximax.core.utils.StringUtils;
import io.proximax.sdk.model.transaction.BlockchainConfigTransaction;
import io.proximax.sdk.model.transaction.EntityType;
import io.proximax.sdk.model.transaction.EntityVersion;

/**
 * builder for {@link BlockchainConfigTransactionBuilder}
 */
public class BlockchainConfigTransactionBuilder
      extends TransactionBuilder {

   private BigInteger applyHeightDelta;
   private String blockchainConfig;
   private String supportedEntityVersions;

   public BlockchainConfigTransactionBuilder() {
      super(EntityType.BLOCKCHAIN_CONFIG, EntityVersion.BLOCKCHAIN_CONFIG.getValue());
   }

   @Override
   protected BlockchainConfigTransactionBuilder self() {
      return this;
   }

   @Override
   public BlockchainConfigTransaction build() {
      // use or calculate maxFee
      BigInteger maxFee = getMaxFee().orElseGet(() -> getMaxFeeCalculation(
            BlockchainConfigTransaction.calculatePayloadSize(StringUtils.getBytes(getBlockchainConfig()).length,
                  StringUtils.getBytes(getSupportedEntityVersions()).length)));
      // create transaction instance
      return new BlockchainConfigTransaction(getNetworkType(), getVersion(), getDeadline(), maxFee, getSignature(),
            getSigner(), getTransactionInfo(), getApplyHeightDelta(), getBlockchainConfig(),
            getSupportedEntityVersions());
   }

   // ------------------------------------- setters ---------------------------------------------//

   /**
    * number of blocks after which specified configuration will become valid
    * 
    * @param applyHeightDelta number of blocks
    * @return self
    */
   public BlockchainConfigTransactionBuilder applyHeightDelta(BigInteger applyHeightDelta) {
      this.applyHeightDelta = applyHeightDelta;
      return self();
   }

   /**
    * configuration in the format of property file
    * 
    * @param blockchainConfig the configuration
    * @return self
    */
   public BlockchainConfigTransactionBuilder blockchainConfig(String blockchainConfig) {
      this.blockchainConfig = blockchainConfig;
      return self();
   }

   /**
    * JSON string representing supported entity versions
    * 
    * @param supportedEntityVersions JSON string
    * @return self
    */
   public BlockchainConfigTransactionBuilder supportedEntityVersions(String supportedEntityVersions) {
      this.supportedEntityVersions = supportedEntityVersions;
      return self();
   }

   // -------------------------------------- getters --------------------------------------------//

   /**
    * @return the applyHeightDelta
    */
   public BigInteger getApplyHeightDelta() {
      return applyHeightDelta;
   }

   /**
    * @return the blockchainConfig
    */
   public String getBlockchainConfig() {
      return blockchainConfig;
   }

   /**
    * @return the supportedEntityVersions
    */
   public String getSupportedEntityVersions() {
      return supportedEntityVersions;
   }

   // -------------------------------------- convenience --------------------------------------------//

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy