Skip to content

Commit

Permalink
Process arbitrum nitro eth_syncing message
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Sizov committed Jun 14, 2024
1 parent a6facbf commit 10f4c6b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.emeraldpay.dshackle.upstream.arbitrum.json;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@JsonDeserialize(using = NitroSyncingJsonDeserializer.class)
@JsonSerialize(using = NitroSyncingJsonSerializer.class)
public class NitroSyncingJson {

private boolean syncing;

private Long syncTargetMsgCount;
private Long feedPendingMessageCount;
private Long msgCount;

public boolean isSyncing() {
return syncing;
}

public void setSyncing(boolean syncing) {
this.syncing = syncing;
}

public Long getSyncTargetMsgCount() {
return syncTargetMsgCount;
}

public void setSyncTargetMsgCount(Long syncTargetMsgCount) {
this.syncTargetMsgCount = syncTargetMsgCount;
}

public Long getFeedPendingMessageCount() {
return feedPendingMessageCount;
}

public void setFeedPendingMessageCount(Long feedPendingMessageCount) {
this.feedPendingMessageCount = feedPendingMessageCount;
}

public Long getMsgCount() {
return msgCount;
}

public void setMsgCount(Long msgCount) {
this.msgCount = msgCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.emeraldpay.dshackle.upstream.arbitrum.json;

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 io.emeraldpay.dshackle.upstream.arbitrum.json.NitroSyncingJson;
import io.emeraldpay.dshackle.upstream.ethereum.json.EtherJsonDeserializer;

import java.io.IOException;

public class NitroSyncingJsonDeserializer extends EtherJsonDeserializer<NitroSyncingJson> {

@Override
public NitroSyncingJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = jp.readValueAsTree();
NitroSyncingJson resp = new NitroSyncingJson();
if (node.isBoolean()) {
resp.setSyncing(node.asBoolean());
} else {
resp.setSyncing(true);
resp.setSyncTargetMsgCount(getLong(node, "syncTargetMsgCount"));
resp.setFeedPendingMessageCount(getLong(node, "feedPendingMessageCount"));
resp.setMsgCount(getLong(node, "msgCount"));
}
return resp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.emeraldpay.dshackle.upstream.arbitrum.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import io.emeraldpay.dshackle.upstream.ethereum.json.EtherJsonSerializer;

import java.io.IOException;

public class NitroSyncingJsonSerializer extends EtherJsonSerializer<NitroSyncingJson> {

@Override
public void serialize(NitroSyncingJson value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value == null) {
gen.writeNull();
} else if (value.isSyncing()) {
gen.writeStartObject();
writeField(gen, "syncTargetMsgCount", value.getSyncTargetMsgCount());
writeField(gen, "feedPendingMessageCount", value.getFeedPendingMessageCount());
writeField(gen, "msgCount", value.getMsgCount());
gen.writeEndObject();
} else {
gen.writeBoolean(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.emeraldpay.dshackle.upstream.ChainResponse
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
import io.emeraldpay.dshackle.upstream.ValidateUpstreamSettingsResult
import io.emeraldpay.dshackle.upstream.arbitrum.json.NitroSyncingJson
import io.emeraldpay.dshackle.upstream.ethereum.domain.Address
import io.emeraldpay.dshackle.upstream.ethereum.hex.HexData
import io.emeraldpay.dshackle.upstream.ethereum.json.SyncingJson
Expand Down Expand Up @@ -58,7 +59,13 @@ open class EthereumUpstreamValidator @JvmOverloads constructor(
override fun validateSyncingRequest(): ValidateSyncingRequest {
return ValidateSyncingRequest(
ChainRequest("eth_syncing", ListParams()),
) { bytes -> objectMapper.readValue(bytes, SyncingJson::class.java).isSyncing }
) { bytes ->
if (listOf(Chain.ARBITRUM__MAINNET, Chain.ARBITRUM__SEPOLIA, Chain.ARBITRUM_NOVA__MAINNET).contains(chain)) {
objectMapper.readValue(bytes, NitroSyncingJson::class.java).isSyncing
} else {
objectMapper.readValue(bytes, SyncingJson::class.java).isSyncing
}
}
}

override fun validatePeersRequest(): ValidatePeersRequest {
Expand Down

0 comments on commit 10f4c6b

Please sign in to comment.