|
| 1 | +/* |
| 2 | + * Copyright Consensys Software Inc., 2024 |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package tech.pegasys.teku.ethereum.json.types.validator; |
| 15 | + |
| 16 | +import java.util.Objects; |
| 17 | +import tech.pegasys.teku.infrastructure.json.types.CoreTypes; |
| 18 | +import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition; |
| 19 | +import tech.pegasys.teku.infrastructure.unsigned.UInt64; |
| 20 | + |
| 21 | +public class SyncCommitteeSelectionProof { |
| 22 | + |
| 23 | + public static final DeserializableTypeDefinition<SyncCommitteeSelectionProof> |
| 24 | + SYNC_COMMITTEE_SELECTION_PROOF = |
| 25 | + DeserializableTypeDefinition.object( |
| 26 | + SyncCommitteeSelectionProof.class, SyncCommitteeSelectionProof.Builder.class) |
| 27 | + .name("SyncCommitteeSelectionProof") |
| 28 | + .initializer(SyncCommitteeSelectionProof::builder) |
| 29 | + .finisher(SyncCommitteeSelectionProof.Builder::build) |
| 30 | + .withField( |
| 31 | + "validator_index", |
| 32 | + CoreTypes.INTEGER_TYPE, |
| 33 | + SyncCommitteeSelectionProof::getValidatorIndex, |
| 34 | + SyncCommitteeSelectionProof.Builder::validatorIndex) |
| 35 | + .withField( |
| 36 | + "slot", |
| 37 | + CoreTypes.UINT64_TYPE, |
| 38 | + SyncCommitteeSelectionProof::getSlot, |
| 39 | + SyncCommitteeSelectionProof.Builder::slot) |
| 40 | + .withField( |
| 41 | + "subcommittee_index", |
| 42 | + CoreTypes.INTEGER_TYPE, |
| 43 | + SyncCommitteeSelectionProof::getSubcommitteeIndex, |
| 44 | + SyncCommitteeSelectionProof.Builder::subcommitteeIndex) |
| 45 | + .withField( |
| 46 | + "selection_proof", |
| 47 | + CoreTypes.STRING_TYPE, |
| 48 | + SyncCommitteeSelectionProof::getSelectionProof, |
| 49 | + SyncCommitteeSelectionProof.Builder::selectionProof) |
| 50 | + .build(); |
| 51 | + |
| 52 | + private final int validatorIndex; |
| 53 | + private final UInt64 slot; |
| 54 | + private final int subcommitteeIndex; |
| 55 | + private final String selectionProof; |
| 56 | + |
| 57 | + private SyncCommitteeSelectionProof( |
| 58 | + final int validatorIndex, |
| 59 | + final UInt64 slot, |
| 60 | + final int subcommitteeIndex, |
| 61 | + final String selectionProof) { |
| 62 | + this.validatorIndex = validatorIndex; |
| 63 | + this.slot = slot; |
| 64 | + this.subcommitteeIndex = subcommitteeIndex; |
| 65 | + this.selectionProof = selectionProof; |
| 66 | + } |
| 67 | + |
| 68 | + public int getValidatorIndex() { |
| 69 | + return validatorIndex; |
| 70 | + } |
| 71 | + |
| 72 | + public UInt64 getSlot() { |
| 73 | + return slot; |
| 74 | + } |
| 75 | + |
| 76 | + public int getSubcommitteeIndex() { |
| 77 | + return subcommitteeIndex; |
| 78 | + } |
| 79 | + |
| 80 | + public String getSelectionProof() { |
| 81 | + return selectionProof; |
| 82 | + } |
| 83 | + |
| 84 | + public static SyncCommitteeSelectionProof.Builder builder() { |
| 85 | + return new SyncCommitteeSelectionProof.Builder(); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean equals(final Object o) { |
| 90 | + if (this == o) { |
| 91 | + return true; |
| 92 | + } |
| 93 | + if (o == null || getClass() != o.getClass()) { |
| 94 | + return false; |
| 95 | + } |
| 96 | + final SyncCommitteeSelectionProof that = (SyncCommitteeSelectionProof) o; |
| 97 | + return validatorIndex == that.validatorIndex |
| 98 | + && subcommitteeIndex == that.subcommitteeIndex |
| 99 | + && Objects.equals(slot, that.slot) |
| 100 | + && Objects.equals(selectionProof, that.selectionProof); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public int hashCode() { |
| 105 | + return Objects.hash(validatorIndex, slot, subcommitteeIndex, selectionProof); |
| 106 | + } |
| 107 | + |
| 108 | + public static class Builder { |
| 109 | + |
| 110 | + private int validatorIndex; |
| 111 | + private UInt64 slot; |
| 112 | + private int subcommitteeIndex; |
| 113 | + private String selectionProof; |
| 114 | + |
| 115 | + public Builder validatorIndex(final int validatorIndex) { |
| 116 | + this.validatorIndex = validatorIndex; |
| 117 | + return this; |
| 118 | + } |
| 119 | + |
| 120 | + public Builder subcommitteeIndex(final int subcommitteeIndex) { |
| 121 | + this.subcommitteeIndex = subcommitteeIndex; |
| 122 | + return this; |
| 123 | + } |
| 124 | + |
| 125 | + public Builder slot(final UInt64 slot) { |
| 126 | + this.slot = slot; |
| 127 | + return this; |
| 128 | + } |
| 129 | + |
| 130 | + public Builder selectionProof(final String selectionProof) { |
| 131 | + this.selectionProof = selectionProof; |
| 132 | + return this; |
| 133 | + } |
| 134 | + |
| 135 | + public SyncCommitteeSelectionProof build() { |
| 136 | + return new SyncCommitteeSelectionProof( |
| 137 | + validatorIndex, slot, subcommitteeIndex, selectionProof); |
| 138 | + } |
| 139 | + } |
| 140 | +} |
0 commit comments