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

io.proximax.sdk.model.transaction.builder.SecretProofTransactionBuilder 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.sdk.model.transaction.HashType;
import io.proximax.sdk.model.transaction.Recipient;
import io.proximax.sdk.model.transaction.SecretProofTransaction;
import io.proximax.sdk.model.transaction.EntityType;
import io.proximax.sdk.model.transaction.EntityVersion;

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

   private HashType hashType;
   private String secret;
   private String proof;
   private Recipient recipient;

   public SecretProofTransactionBuilder() {
      super(EntityType.SECRET_PROOF, EntityVersion.SECRET_PROOF.getValue());
   }

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

   @Override
   public SecretProofTransaction build() {
      // use or calculate maxFee
      BigInteger maxFee = getMaxFee().orElseGet(
            () -> getMaxFeeCalculation(SecretProofTransaction.calculatePayloadSize(getRecipient(), getProof())));
      // create transaction instance
      return new SecretProofTransaction(getNetworkType(), getVersion(), getDeadline(), maxFee, getSignature(),
            getSigner(), getTransactionInfo(), getHashType(), getSecret(), getProof(), getRecipient());
   }

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

   /**
    * type of used hashing function
    * 
    * @param hashType hash function
    * @return self
    */
   public SecretProofTransactionBuilder hashType(HashType hashType) {
      this.hashType = hashType;
      return self();
   }

   /**
    * lock secret
    * 
    * @param secret the secret
    * @return self
    */
   public SecretProofTransactionBuilder secret(String secret) {
      this.secret = secret;
      return self();
   }

   /**
    * recipient of the locked mosaic
    * 
    * @param recipient the recipient
    * @return self
    */
   public SecretProofTransactionBuilder recipient(Recipient recipient) {
      this.recipient = recipient;
      return self();
   }

   /**
    * proof of the secret
    * 
    * @param proof the proof to set
    * @return self
    */
   public SecretProofTransactionBuilder proof(String proof) {
      this.proof = proof;
      return self();
   }

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

   /**
    * @return the hashType
    */
   public HashType getHashType() {
      return hashType;
   }

   /**
    * @return the secret
    */
   public String getSecret() {
      return secret;
   }

   /**
    * @return the recipient
    */
   public Recipient getRecipient() {
      return recipient;
   }

   /**
    * @return the proof
    */
   public String getProof() {
      return proof;
   }

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

   /**
    * specify lock secret along with the corresponding hash type
    * 
    * @param hashType hashing function used to hash proof to create secret
    * @param secret the secret
    * @return self
    */
   public SecretProofTransactionBuilder secret(HashType hashType, String secret) {
      return hashType(hashType).secret(secret);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy