Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/279 - BlockV2 #294

Merged
merged 7 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script/docker-run
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
# run the cspr-nctl container in docker
docker run --rm -it --name cspr-nctl -d -p 25101:25101 -p 11101:11101 -p 14101:14101 -p 18101:18101 stormeye2000/cspr-nctl:linux-1.5.5
docker run --rm -it --name cspr-nctl-condor -d -p 25101:25101 -p 11101:11101 -p 14101:14101 -p 18101:18101 casper-nctl:feat-2.0
3 changes: 1 addition & 2 deletions src/main/java/com/casper/sdk/model/auction/AuctionState.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ public class AuctionState {
*/
@JsonProperty("state_root_hash")
private String stateRootHash;

}
}
34 changes: 34 additions & 0 deletions src/main/java/com/casper/sdk/model/block/Block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* Abstract base class for all block versions.
*
* @author [email protected]
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({
@JsonSubTypes.Type(value = BlockV1.class, name = "Version1"),
@JsonSubTypes.Type(value = BlockV2.class, name = "Version2")})
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public abstract class Block<HeaderT extends BlockHeader, BodyT extends BlockBody> {

@JsonProperty("hash")
private Digest hash;

public abstract HeaderT getHeader();

public abstract BodyT getBody();

}
26 changes: 26 additions & 0 deletions src/main/java/com/casper/sdk/model/block/BlockBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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.Getter;
import lombok.Setter;

/**
* Abstract class for block body.
*
* @author [email protected]
*/
@Getter
@Setter
public abstract class BlockBody {

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

/** The body's hash. */
@JsonProperty("hash")
private Digest hash;
}

31 changes: 31 additions & 0 deletions src/main/java/com/casper/sdk/model/block/BlockBodyV1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.casper.sdk.model.block;

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

import java.util.List;

/**
* A JSON-friendly representation of `Body`
*
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see BlockV1
* @since 0.0.1
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BlockBodyV1 extends BlockBody {

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

/** List of Hex-encoded hash digest */
@JsonProperty("transfer_hashes")
private List<Digest> transferHashes;
}
36 changes: 36 additions & 0 deletions src/main/java/com/casper/sdk/model/block/BlockBodyV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
import com.casper.sdk.model.transaction.TransactionCategory;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.util.List;
import java.util.Map;

/**
* V2 of the block body
*
* @author [email protected]
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BlockBodyV2 extends BlockBody {

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

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

@JsonProperty("rewarded_signatures")
private List<List<Long>> rewardedSignatures;

@JsonProperty("transactions")
private Map<TransactionCategory, List<Digest>> transactions;
}
51 changes: 51 additions & 0 deletions src/main/java/com/casper/sdk/model/block/BlockHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
* Abstract class for block header.
*
* @author [email protected]
*/
@Getter
@Setter
public abstract class BlockHeader {

@JsonProperty("parent_hash")
private Digest parentHash;

@JsonProperty("state_root_hash")
private Digest stateRootHash;

@JsonProperty("body_hash")
private Digest bodyHash;

@JsonProperty("random_bit")
private boolean randomBit;

@JsonProperty("height")
private long height;

@JsonProperty("accumulated_seed")
private Digest accumulatedSeed;

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

/** 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 */
@JsonProperty("protocol_version")
private String protocolVersion;
}

31 changes: 31 additions & 0 deletions src/main/java/com/casper/sdk/model/block/BlockHeaderV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.casper.sdk.model.block;

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

/**
* V2 Block header.
*
* @author [email protected]
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BlockHeaderV2 extends BlockHeader {

@JsonProperty("era_end")
private EraEndV2 eraEnd;

@JsonProperty("proposer")
private Digest proposer;

@JsonProperty("current_gas_price")
private long currentGasPrice;

@JsonProperty("last_switch_block_hash")
private Digest lastSwitchBlockHash;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
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 @@ -23,29 +18,17 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class JsonBlock {
public class BlockV1 extends Block<JsonBlockHeader, BlockBodyV1> {

/**
* The block's hash.
*/
@JsonProperty("hash")
private Digest hash;

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

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

/**
* List of {@link JsonProof}
*/
/** List of {@link JsonProof} */
@JsonProperty("proofs")
private List<JsonProof> proofs;
}
23 changes: 23 additions & 0 deletions src/main/java/com/casper/sdk/model/block/BlockV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.casper.sdk.model.block;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

/**
* V2 Block
*
* @author [email protected]
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BlockV2 extends Block<BlockHeaderV2, BlockBodyV2> {

@JsonProperty("header")
private BlockHeaderV2 header;

@JsonProperty("body")
private BlockBodyV2 body;
}
30 changes: 30 additions & 0 deletions src/main/java/com/casper/sdk/model/block/BlockWithSignatures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.casper.sdk.model.block;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.util.List;

/**
* Block and its associated signatures.
*
* @author [email protected]
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BlockWithSignatures {

@JsonProperty("block")
private Block<?, ?> block;

@JsonProperty("proofs")
private List<JsonProof> proofs;

public <BlockT extends Block<?, ?>> BlockT getBlock() {
//noinspection unchecked
return (BlockT) block;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.casper.sdk.model.block;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* The response for a V2 chain_get_block RPC request.
*
* @author [email protected]
*/
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class ChainGetBlockResponse {

@JsonProperty("api_version")
private String apiVersion;

@JsonProperty("block_with_signatures")
private BlockWithSignatures blockWithSignatures;
}
Loading