-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional RPC methods and data structures (#528)
- Loading branch information
Showing
9 changed files
with
408 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
networking/p2p/src/main/java/tech/pegasys/artemis/networking/p2p/hobbits/BlockBodies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.artemis.networking.p2p.hobbits; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
@JsonDeserialize(using = BlockBodies.BlockBodiesDeserializer.class) | ||
final class BlockBodies { | ||
|
||
static class BlockBodiesDeserializer extends StdDeserializer<BlockBodies> { | ||
|
||
protected BlockBodiesDeserializer() { | ||
super(BlockBodies.class); | ||
} | ||
|
||
@Override | ||
public BlockBodies deserialize(JsonParser jp, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
JsonNode node = jp.getCodec().readTree(jp); | ||
Iterator<JsonNode> iterator = node.iterator(); | ||
List<BlockBody> elts = new ArrayList<>(); | ||
while (iterator.hasNext()) { | ||
JsonNode child = iterator.next(); | ||
elts.add(new BlockBody()); | ||
} | ||
|
||
return new BlockBodies(elts); | ||
} | ||
} | ||
|
||
static class BlockBody { | ||
|
||
/* | ||
'randao_reveal': 'bytes96', | ||
'eth1_data': Eth1Data, | ||
'proposer_slashings': [ProposerSlashing], | ||
'attester_slashings': [AttesterSlashing], | ||
'attestations': [Attestation], | ||
'deposits': [Deposit], | ||
'voluntary_exits': [VoluntaryExit], | ||
'transfers': [Transfer], | ||
*/ | ||
|
||
BlockBody() { | ||
// TODO fill body with the right info | ||
} | ||
} | ||
|
||
private final List<BlockBody> bodies; | ||
|
||
BlockBodies(List<BlockBody> rootsAndSlots) { | ||
this.bodies = rootsAndSlots; | ||
} | ||
|
||
@JsonValue | ||
public List<BlockBody> bodies() { | ||
return bodies; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
networking/p2p/src/main/java/tech/pegasys/artemis/networking/p2p/hobbits/BlockHeaders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.artemis.networking.p2p.hobbits; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import net.consensys.cava.bytes.Bytes; | ||
import net.consensys.cava.bytes.Bytes32; | ||
|
||
@JsonDeserialize(using = BlockHeaders.BlockHeadersDeserializer.class) | ||
final class BlockHeaders { | ||
|
||
static class BlockHeadersDeserializer extends StdDeserializer<BlockHeaders> { | ||
|
||
protected BlockHeadersDeserializer() { | ||
super(BlockHeaders.class); | ||
} | ||
|
||
@Override | ||
public BlockHeaders deserialize(JsonParser jp, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
JsonNode node = jp.getCodec().readTree(jp); | ||
Iterator<JsonNode> iterator = node.iterator(); | ||
List<BlockHeader> elts = new ArrayList<>(); | ||
while (iterator.hasNext()) { | ||
JsonNode child = iterator.next(); | ||
elts.add( | ||
new BlockHeader( | ||
child.get("slot").asLong(), | ||
Bytes32.fromHexString(child.get("previous_block_root").asText()), | ||
Bytes32.fromHexString(child.get("state_root").asText()), | ||
Bytes32.fromHexString(child.get("block_body_root").asText()), | ||
Bytes.fromHexString(child.get("signature").asText()))); | ||
} | ||
|
||
return new BlockHeaders(elts); | ||
} | ||
} | ||
|
||
static class BlockHeader { | ||
|
||
private final long slot; | ||
private final Bytes32 previousBlockRoot; | ||
private final Bytes32 stateRoot; | ||
private final Bytes32 blockBodyRoot; | ||
private final Bytes signature; | ||
|
||
BlockHeader( | ||
long slot, | ||
Bytes32 previousBlockRoot, | ||
Bytes32 stateRoot, | ||
Bytes32 blockBodyRoot, | ||
Bytes signature) { | ||
this.slot = slot; | ||
this.previousBlockRoot = previousBlockRoot; | ||
this.stateRoot = stateRoot; | ||
this.blockBodyRoot = blockBodyRoot; | ||
this.signature = signature; | ||
} | ||
|
||
@JsonProperty("slot") | ||
public long slot() { | ||
return slot; | ||
} | ||
|
||
@JsonProperty("previous_block_root") | ||
public Bytes32 previousBlockRoot() { | ||
return previousBlockRoot; | ||
} | ||
|
||
@JsonProperty("state_root") | ||
public Bytes32 stateRoot() { | ||
return stateRoot; | ||
} | ||
|
||
@JsonProperty("block_body_root") | ||
public Bytes32 blockBodyRoot() { | ||
return blockBodyRoot; | ||
} | ||
|
||
@JsonProperty("signature") | ||
public Bytes signature() { | ||
return signature; | ||
} | ||
} | ||
|
||
private final List<BlockHeader> headers; | ||
|
||
BlockHeaders(List<BlockHeader> headers) { | ||
this.headers = headers; | ||
} | ||
|
||
@JsonValue | ||
public List<BlockHeader> headers() { | ||
return headers; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
networking/p2p/src/main/java/tech/pegasys/artemis/networking/p2p/hobbits/BlockRoots.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.artemis.networking.p2p.hobbits; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import net.consensys.cava.bytes.Bytes32; | ||
|
||
@JsonDeserialize(using = BlockRoots.BlockRootsDeserializer.class) | ||
final class BlockRoots { | ||
|
||
static class BlockRootsDeserializer extends StdDeserializer<BlockRoots> { | ||
|
||
protected BlockRootsDeserializer() { | ||
super(BlockRoots.class); | ||
} | ||
|
||
@Override | ||
public BlockRoots deserialize(JsonParser jp, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
JsonNode node = jp.getCodec().readTree(jp); | ||
Iterator<JsonNode> iterator = node.iterator(); | ||
List<BlockRootAndSlot> elts = new ArrayList<>(); | ||
while (iterator.hasNext()) { | ||
JsonNode child = iterator.next(); | ||
elts.add( | ||
new BlockRootAndSlot( | ||
Bytes32.fromHexString(child.get("block_root").asText()), | ||
child.get("slot").asLong())); | ||
} | ||
|
||
return new BlockRoots(elts); | ||
} | ||
} | ||
|
||
static class BlockRootAndSlot { | ||
|
||
private final Bytes32 blockRoot; | ||
private final long slot; | ||
|
||
BlockRootAndSlot(Bytes32 blockRoot, long slot) { | ||
this.blockRoot = blockRoot; | ||
this.slot = slot; | ||
} | ||
|
||
@JsonProperty("block_root") | ||
public Bytes32 blockRoot() { | ||
return blockRoot; | ||
} | ||
|
||
@JsonProperty("slot") | ||
public long slot() { | ||
return slot; | ||
} | ||
} | ||
|
||
private final List<BlockRootAndSlot> rootsAndSlots; | ||
|
||
BlockRoots(List<BlockRootAndSlot> rootsAndSlots) { | ||
this.rootsAndSlots = rootsAndSlots; | ||
} | ||
|
||
@JsonValue | ||
public List<BlockRootAndSlot> rootsAndSlots() { | ||
return rootsAndSlots; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.