|
| 1 | +package com.algorand.algosdk.transaction; |
| 2 | + |
| 3 | +import java.io.Serializable; |
| 4 | +import java.math.BigInteger; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.Objects; |
| 7 | + |
| 8 | +import com.algorand.algosdk.crypto.*; |
| 9 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 10 | +import com.fasterxml.jackson.annotation.JsonInclude; |
| 11 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 12 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
| 13 | + |
| 14 | +@JsonPropertyOrder(alphabetic = true) |
| 15 | +@JsonInclude(JsonInclude.Include.NON_DEFAULT) |
| 16 | +public class HeartbeatTxnFields implements Serializable { |
| 17 | + @JsonProperty("a") |
| 18 | + public Address hbAddress = new Address(); |
| 19 | + |
| 20 | + @JsonProperty("prf") |
| 21 | + public HeartbeatProof hbProof = new HeartbeatProof(); |
| 22 | + |
| 23 | + @JsonProperty("sd") |
| 24 | + public byte[] hbSeed = new byte[32]; // committee.Seed |
| 25 | + |
| 26 | + @JsonProperty("vid") |
| 27 | + public ParticipationPublicKey hbVoteID = new ParticipationPublicKey(); |
| 28 | + |
| 29 | + @JsonProperty("kd") |
| 30 | + public BigInteger hbKeyDilution = BigInteger.valueOf(0); |
| 31 | + |
| 32 | + public HeartbeatTxnFields() {} |
| 33 | + |
| 34 | + public HeartbeatTxnFields( |
| 35 | + Address hbAddress, |
| 36 | + HeartbeatProof hbProof, |
| 37 | + byte[] hbSeed, |
| 38 | + ParticipationPublicKey hbVoteID, |
| 39 | + BigInteger hbKeyDilution |
| 40 | + ) { |
| 41 | + this.hbAddress = Objects.requireNonNull(hbAddress, "hbAddress must not be null"); |
| 42 | + this.hbProof = Objects.requireNonNull(hbProof, "hbProof must not be null"); |
| 43 | + this.hbVoteID = Objects.requireNonNull(hbVoteID, "hbVoteID must not be null"); |
| 44 | + this.hbKeyDilution = Objects.requireNonNull(hbKeyDilution, "hbKeyDilution must not be null"); |
| 45 | + if (hbSeed == null) { |
| 46 | + throw new NullPointerException("hbSeed must not be null"); |
| 47 | + } |
| 48 | + System.arraycopy(hbSeed, 0, this.hbSeed, 0, this.hbSeed.length); |
| 49 | + } |
| 50 | + |
| 51 | + @JsonCreator |
| 52 | + public HeartbeatTxnFields( |
| 53 | + @JsonProperty("a") byte[] hbAddress, |
| 54 | + @JsonProperty("prf") HeartbeatProof hbProof, |
| 55 | + @JsonProperty("sd") byte[] hbSeed, |
| 56 | + @JsonProperty("vid") byte[] hbVoteID, |
| 57 | + @JsonProperty("kd") BigInteger hbKeyDilution |
| 58 | + ) { |
| 59 | + if (hbAddress != null) { |
| 60 | + this.hbAddress = new Address(hbAddress); |
| 61 | + } |
| 62 | + if (hbProof != null) { |
| 63 | + this.hbProof = hbProof; |
| 64 | + } |
| 65 | + if (hbSeed != null) { |
| 66 | + System.arraycopy(hbSeed, 0, this.hbSeed, 0, this.hbSeed.length); |
| 67 | + } |
| 68 | + if (hbVoteID != null) { |
| 69 | + this.hbVoteID = new ParticipationPublicKey(hbVoteID); |
| 70 | + } |
| 71 | + if (hbKeyDilution != null) { |
| 72 | + this.hbKeyDilution = hbKeyDilution; |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public boolean equals(Object o) { |
| 78 | + if (this == o) return true; |
| 79 | + if (o == null || getClass() != o.getClass()) return false; |
| 80 | + HeartbeatTxnFields that = (HeartbeatTxnFields) o; |
| 81 | + return hbAddress.equals(that.hbAddress) && |
| 82 | + hbProof.equals(that.hbProof) && |
| 83 | + Arrays.equals(hbSeed, that.hbSeed) && |
| 84 | + hbVoteID.equals(that.hbVoteID) && |
| 85 | + hbKeyDilution.equals(that.hbKeyDilution); |
| 86 | + } |
| 87 | +} |
0 commit comments