Bid.java

  1. package com.syntifi.casper.sdk.model.bid;

  2. import com.fasterxml.jackson.annotation.JsonGetter;
  3. import com.fasterxml.jackson.annotation.JsonIgnore;
  4. import com.fasterxml.jackson.annotation.JsonProperty;
  5. import com.fasterxml.jackson.annotation.JsonSetter;
  6. import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
  7. import com.syntifi.casper.sdk.exception.InvalidByteStringException;
  8. import com.syntifi.casper.sdk.model.key.PublicKey;
  9. import com.syntifi.casper.sdk.model.uref.URef;
  10. import lombok.AllArgsConstructor;
  11. import lombok.Builder;
  12. import lombok.Getter;
  13. import lombok.NoArgsConstructor;
  14. import lombok.Setter;

  15. import java.math.BigInteger;
  16. import java.security.NoSuchAlgorithmException;
  17. import java.util.LinkedHashMap;
  18. import java.util.Map;

  19. /**
  20.  * An entry in the validator map.
  21.  *
  22.  * @author Alexandre Carvalho
  23.  * @author Andre Bertolace
  24.  * @since 0.0.1
  25.  */
  26. @Getter
  27. @Setter
  28. @Builder
  29. @AllArgsConstructor
  30. @NoArgsConstructor
  31. public class Bid {

  32.     /**
  33.      * The purse that was used for bonding.
  34.      */
  35.     @JsonProperty("bonding_purse")
  36.     private URef bondingPurse;

  37.     /**
  38.      * Delegation rate
  39.      */
  40.     @JsonProperty("delegation_rate")
  41.     private int delegationRate;

  42.     /**
  43.      * This validator's delegators, indexed by their public keys
  44.      */
  45.     @JsonIgnore
  46.     @Builder.Default
  47.     private Map<PublicKey, Delegator> delegators = new LinkedHashMap<>();

  48.     /**
  49.      * `true` if validator has been \"evicted\"
  50.      */
  51.     private boolean inactive;

  52.     /**
  53.      * The amount of tokens staked by a validator (not including delegators).
  54.      */
  55.     @JsonIgnore
  56.     private BigInteger stakedAmount;

  57.     /**
  58.      * Validator PublicKey
  59.      */
  60.     @JsonProperty("validator_public_key")
  61.     private PublicKey validatorPublicKey;

  62.     /**
  63.      * Vesting schedule for a genesis validator. `None` if non-genesis validator.
  64.      */
  65.     @JsonProperty("vesting_schedule")
  66.     private VestingSchedule vestingSchedule;

  67.     @JsonSetter("delegators")
  68.     @ExcludeFromJacocoGeneratedReport
  69.     protected void setJsonDelegators(Map<String, Delegator> node)
  70.             throws NoSuchAlgorithmException, InvalidByteStringException {
  71.         for (Map.Entry<String, Delegator> entry : node.entrySet()) {
  72.             PublicKey publicKey = PublicKey.fromTaggedHexString(entry.getKey());
  73.             Delegator delegator = entry.getValue();
  74.             this.delegators.put(publicKey, delegator);
  75.         }
  76.     }

  77.     @JsonGetter("delegators")
  78.     @ExcludeFromJacocoGeneratedReport
  79.     protected Map<String, Delegator> getJsonDelegators() {
  80.         Map<String, Delegator> out = new LinkedHashMap<>();
  81.         for (Map.Entry<PublicKey, Delegator> entry : this.delegators.entrySet()) {
  82.             out.put(entry.getKey().getAlgoTaggedHex(), entry.getValue());
  83.         }
  84.         return out;
  85.     }

  86.     @JsonProperty("staked_amount")
  87.     @ExcludeFromJacocoGeneratedReport
  88.     protected String getJsonStakedAmount() {
  89.         return this.stakedAmount.toString(10);
  90.     }

  91.     @JsonProperty("staked_amount")
  92.     @ExcludeFromJacocoGeneratedReport
  93.     protected void setJsonStakedAmount(String value) {
  94.         this.stakedAmount = new BigInteger(value, 10);
  95.     }
  96. }