AergoSpec.java

  1. package hera.spec;

  2. import hera.api.model.AccountAddress;
  3. import hera.api.model.ContractDefinition;
  4. import hera.api.model.ContractInvocation;
  5. import java.math.BigDecimal;
  6. import lombok.Getter;
  7. import lombok.RequiredArgsConstructor;

  8. public class AergoSpec {

  9.   /* address, name, private key */

  10.   public static final byte ADDRESS_PREFIX = 0x42;

  11.   // [odd|even] of publickey.y + [optional 0x00] + publickey.x
  12.   // which is equivalent with s compressed public key (see also X9.62 s 4.2.1)
  13.   public static final int ADDRESS_BYTE_LENGTH = 33;

  14.   public static final int NAME_LENGTH = 12;

  15.   public static final byte ENCRYPTED_PRIVATE_KEY_PREFIX = (byte) 0xAA;


  16.   /* amount unit */

  17.   @RequiredArgsConstructor
  18.   public enum Unit {
  19.     AER("Aer", new BigDecimal("1"), new BigDecimal("1")),
  20.     GAER("Gaer", new BigDecimal("1.E-9"), new BigDecimal("1.E9")),
  21.     AERGO("Aergo", new BigDecimal("1.E-18"), new BigDecimal("1.E18"));

  22.     @Getter
  23.     protected final String name;

  24.     @Getter
  25.     protected final BigDecimal minimum;

  26.     @Getter
  27.     protected final BigDecimal ratio;
  28.   }


  29.   /* payload */

  30.   public static final String PAYLOAD_VERSION = "v1";

  31.   public enum PayloadType {
  32.     ContractDefinition("", ContractDefinition.class),
  33.     ContractInvocation("", ContractInvocation.class),
  34.     Vote("", String.class, String[].class),
  35.     Stake("stake"),
  36.     Unstake("unstake"),
  37.     CreateName("createName", String.class),
  38.     UpdateName("updateName", String.class, AccountAddress.class);

  39.     @Getter
  40.     protected final String name;
  41.     @Getter
  42.     protected final Class<?>[] targets;

  43.     private PayloadType(final String name, final Class<?>... targets) {
  44.       this.name = name;
  45.       this.targets = targets;
  46.     }
  47.   }

  48.   public static final String BIGNUM_JSON_KEY = "_bignum";

  49.   public static final byte CONTRACT_PAYLOAD_VERSION = (byte) 0xC0;


  50.   /* signature */

  51.   public static final int SIGN_HEADER_MAGIC = 0x30;

  52.   public static final int SIGN_INT_MARKER = 0x02;

  53.   // minimum length of a DER encoded signature which both R and S are 1 byte each.
  54.   // <header-magic> + <1-byte> + <int-marker> + 0x01 + <r.byte> + <int-marker> + 0x01 + <s.byte>
  55.   public static final int SIGN_MINIMUM_LENGTH = 8;

  56. }