Skip to content

Commit

Permalink
issues/279 - EraEndV2 tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
meywood committed Jun 10, 2024
1 parent a25c48a commit dd115d8
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 82 deletions.
4 changes: 1 addition & 3 deletions src/main/java/com/casper/sdk/model/block/BlockBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
@Setter
public abstract class BlockBody {

/**
* @see PublicKey
*/
/** @see PublicKey */
@JsonProperty("proposer")
private PublicKey proposer;

Expand Down
16 changes: 3 additions & 13 deletions src/main/java/com/casper/sdk/model/block/BlockBodyV1.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
import com.casper.sdk.model.key.PublicKey;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

import java.util.List;

Expand All @@ -26,16 +21,11 @@
@NoArgsConstructor
public class BlockBodyV1 extends BlockBody {

/**
* List of Hex-encoded hash digest
*/
/** List of Hex-encoded hash digest */
@JsonProperty("deploy_hashes")
private List<Digest> deployHashes;

/**
* List of Hex-encoded hash digest
*/
/** List of Hex-encoded hash digest */
@JsonProperty("transfer_hashes")
private List<Digest> transferHashes;

}
12 changes: 3 additions & 9 deletions src/main/java/com/casper/sdk/model/block/BlockHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,16 @@ public class BlockHeader {
@JsonProperty("accumulated_seed")
private Digest accumulatedSeed;

/**
* Era ID newtype
*/
/** Era ID newtype */
@JsonProperty("era_id")
private long eraId;

/**
* Timestamp formatted as per RFC 3339
*/
/** Timestamp formatted as per RFC 3339 */
@JsonProperty("timestamp")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date timeStamp;

/**
* Casper Platform protocol version
*/
/** Casper Platform protocol version */
@JsonProperty("protocol_version")
private String protocolVersion;
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/casper/sdk/model/block/BlockHeaderV2.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.casper.sdk.model.era.EraEndV2;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.util.Date;

/**
* @author [email protected]
*/
Expand All @@ -28,6 +26,4 @@ public class BlockHeaderV2 extends BlockHeader {

@JsonProperty("last_switch_block_hash")
private Digest lastSwitchBlockHash;


}
12 changes: 3 additions & 9 deletions src/main/java/com/casper/sdk/model/block/BlockV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,15 @@
@NoArgsConstructor
public class BlockV1 extends Block<JsonBlockHeader, BlockBodyV1> {

/**
* {@link JsonBlockHeader}
*/
/** {@link JsonBlockHeader} */
@JsonProperty("header")
private JsonBlockHeader header;

/**
* {@link BlockBodyV1}
*/
/** {@link BlockBodyV1} */
@JsonProperty("body")
private BlockBodyV1 body;

/**
* List of {@link JsonProof}
*/
/** List of {@link JsonProof} */
@JsonProperty("proofs")
private List<JsonProof> proofs;
}
36 changes: 0 additions & 36 deletions src/main/java/com/casper/sdk/model/block/EraEndV2.java

This file was deleted.

8 changes: 2 additions & 6 deletions src/main/java/com/casper/sdk/model/block/JsonBlockData.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
@NoArgsConstructor
public class JsonBlockData {

/**
* The RPC API version
*/
/** The RPC API version */
@JsonProperty("api_version")
private String apiVersion;

/**
* @see BlockV1
*/
/** @see BlockV1 */
@JsonProperty("block")
private BlockV1 block;
}
55 changes: 55 additions & 0 deletions src/main/java/com/casper/sdk/model/era/EraEndV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.casper.sdk.model.era;

import com.casper.sdk.exception.InvalidKeyBytesException;
import com.casper.sdk.model.key.PublicKey;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* @author [email protected]
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class EraEndV2 {

private List<PublicKey> equivocators;
@JsonProperty("inactive_validators")
private List<PublicKey> inactiveValidators;
@JsonProperty("next_era_validator_weights")
private List<ValidatorWeight> nextEraValidatorWeights;
@JsonProperty("rewards")
private Map<PublicKey, List<BigInteger>> rewards;
@JsonProperty("next_era_gas_price")
private int nextEraGasPrice;

@JsonSetter("rewards")
public void setRewards(final Map<String, List<BigInteger>> rewards) {

this.rewards = new LinkedHashMap<>();

if (rewards != null) {
rewards.forEach((key, value) -> {
try {
// Jackson is not good at deserializing keys so we have to do it manually
this.rewards.put(PublicKey.fromTaggedHexString(key), value);
} catch (NoSuchAlgorithmException e) {
throw new InvalidKeyBytesException(e);
}
});
}
}
}
3 changes: 2 additions & 1 deletion src/test/java/com/casper/sdk/service/CasperServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.casper.sdk.model.deploy.executabledeploy.ModuleBytes;
import com.casper.sdk.model.deploy.executabledeploy.StoredContractByHash;
import com.casper.sdk.model.deploy.executionresult.Success;
import com.casper.sdk.model.era.EraEndV2;
import com.casper.sdk.model.era.EraInfoData;
import com.casper.sdk.model.globalstate.GlobalStateData;
import com.casper.sdk.model.key.AlgorithmTag;
Expand Down Expand Up @@ -568,6 +569,6 @@ void chainGetBlockEraEndV2() throws NoSuchAlgorithmException {
assertThat(eraEnd.getNextEraValidatorWeights().get(0).getWeight(), is(new BigInteger("11823890605832274469")));

assertThat(eraEnd.getRewards().size(), is(5));
assertThat(eraEnd.getRewards().get("010b277da84a12c8814d5723eeb57123ff287f22466fd13faca1bb1fae57d2679b"), hasItems(new BigInteger("4026058477024681"), new BigInteger("402627925137076")));
assertThat(eraEnd.getRewards().get(PublicKey.fromTaggedHexString("010b277da84a12c8814d5723eeb57123ff287f22466fd13faca1bb1fae57d2679b")), hasItems(new BigInteger("4026058477024681"), new BigInteger("402627925137076")));
}
}

0 comments on commit dd115d8

Please sign in to comment.