-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process arbitrum nitro eth_syncing message
- Loading branch information
Mike Sizov
committed
Jun 14, 2024
1 parent
a6facbf
commit 10f4c6b
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJson.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,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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonDeserializer.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,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; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/io/emeraldpay/dshackle/upstream/arbitrum/json/NitroSyncingJsonSerializer.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,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); | ||
} | ||
} | ||
} |
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