ChainIdHash.java

  1. /*
  2.  * @copyright defined in LICENSE.txt
  3.  */

  4. package hera.api.model;

  5. import hera.annotation.ApiAudience;
  6. import hera.annotation.ApiStability;
  7. import hera.api.encode.Encodable;
  8. import hera.exception.DecodingFailureException;
  9. import hera.util.Adaptor;

  10. @ApiAudience.Public
  11. @ApiStability.Unstable
  12. public class ChainIdHash extends Hash implements Adaptor, Encodable {

  13.   /**
  14.    * Create {@code ChainIdHash} with a base58 encoded value.
  15.    *
  16.    * @param encoded String with base58 encoded
  17.    * @return created {@link ChainIdHash}
  18.    * @throws DecodingFailureException if decoding failed
  19.    */
  20.   @ApiAudience.Public
  21.   public static ChainIdHash of(final String encoded) {
  22.     return new ChainIdHash(encoded);
  23.   }

  24.   /**
  25.    * Create {@code ChainIdHash}.
  26.    *
  27.    * @param bytesValue {@link BytesValue}
  28.    * @return created {@link ChainIdHash}
  29.    */
  30.   @ApiAudience.Private
  31.   public static ChainIdHash of(final BytesValue bytesValue) {
  32.     return new ChainIdHash(bytesValue);
  33.   }

  34.   /**
  35.    * ChainIdHash constructor.
  36.    *
  37.    * @param encoded String with base58 encoded
  38.    * @throws DecodingFailureException if decoding failed
  39.    */
  40.   @ApiAudience.Public
  41.   public ChainIdHash(final String encoded) {
  42.     super(encoded);
  43.   }

  44.   /**
  45.    * ChainIdHash constructor.
  46.    *
  47.    * @param bytesValue {@link BytesValue}
  48.    */
  49.   @ApiAudience.Private
  50.   public ChainIdHash(final BytesValue bytesValue) {
  51.     super(bytesValue);
  52.   }

  53.   @SuppressWarnings("unchecked")
  54.   @Override
  55.   public <T> T adapt(Class<T> adaptor) {
  56.     if (adaptor.isAssignableFrom(ChainIdHash.class)) {
  57.       return (T) this;
  58.     } else if (adaptor.isAssignableFrom(BlockHash.class)) {
  59.       return (T) BlockHash.of(getBytesValue());
  60.     } else if (adaptor.isAssignableFrom(TxHash.class)) {
  61.       return (T) TxHash.of(getBytesValue());
  62.     }
  63.     return null;
  64.   }

  65. }