diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJson.java b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJson.java new file mode 100644 index 00000000..ddfeaff9 --- /dev/null +++ b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJson.java @@ -0,0 +1,373 @@ +package io.emeraldpay.dshackle.upstream.ethereum.json; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import io.emeraldpay.etherjar.domain.Address; +import io.emeraldpay.etherjar.domain.BlockHash; +import io.emeraldpay.etherjar.domain.Bloom; +import io.emeraldpay.etherjar.domain.Wei; +import io.emeraldpay.etherjar.hex.HexData; +import io.emeraldpay.etherjar.rpc.json.TransactionJson; +import io.emeraldpay.etherjar.rpc.json.TransactionRefJson; + +import java.io.Serializable; +import java.math.BigInteger; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +@JsonDeserialize(using = BlockJsonDeserializer.class) +@JsonSerialize(using = BlockJsonSerializer.class) +public class BlockJson implements Serializable { + + //TODO nonce or sealFields + + /** + * the block number. null when its pending block. + */ + private Long number; + + /** + * hash of the block. null when its pending block. + */ + private BlockHash hash; + + /** + * hash of the parent block. + */ + private BlockHash parentHash; + + /** + * SHA3 of the uncles data in the block. + */ + private HexData sha3Uncles; + + /** + * the bloom filter for the logs of the block. null when its pending block. + */ + private Bloom logsBloom; + + /** + * the root of the transaction trie of the block. + */ + private HexData transactionsRoot; + + /** + * the root of the final state trie of the block. + */ + private HexData stateRoot; + + /** + * the root of the receipts trie of the block. + */ + private HexData receiptsRoot; + + /** + * the address of the beneficiary to whom the mining rewards were given. + */ + private Address miner; + + /** + * the difficulty for this block. + */ + private BigInteger difficulty; + + /** + * total difficulty of the chain until this block. + */ + private BigInteger totalDifficulty; + + /** + * the "extra data" field of this block. + */ + private HexData extraData; + + /** + * the size of this block in bytes. + */ + private Long size; + + /** + * the maximum gas allowed in this block. + */ + private Long gasLimit; + + /** + * the total used gas by all transactions in this block. + */ + private Long gasUsed; + + /** + * when the block was collated + */ + private Instant timestamp; + + /** + * List of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter. + * + * HexData or TransactionJson + */ + private List transactions; + + /** + * list of uncle hashes. + */ + private List uncles; + + /** + * basefee value for that block, as per EIP-1559 + */ + private Wei baseFeePerGas; + + + private HexData mixHash; + + private HexData nonce; + + private HexData withdrawalsRoot; + + public HexData getMixHash() { + return mixHash; + } + + public void setMixHash(HexData mixHash) { + this.mixHash = mixHash; + } + + public HexData getNonce() { + return nonce; + } + + public void setNonce(HexData nonce) { + this.nonce = nonce; + } + + public HexData getWithdrawalsRoot() { + return withdrawalsRoot; + } + + public void setWithdrawalsRoot(HexData withdrawalsRoot) { + this.withdrawalsRoot = withdrawalsRoot; + } + + public Long getNumber() { + return number; + } + + public void setNumber(Long number) { + this.number = number; + } + + public BlockHash getHash() { + return hash; + } + + public void setHash(BlockHash hash) { + this.hash = hash; + } + + public BlockHash getParentHash() { + return parentHash; + } + + public void setParentHash(BlockHash parentHash) { + this.parentHash = parentHash; + } + + public HexData getSha3Uncles() { + return sha3Uncles; + } + + public void setSha3Uncles(HexData sha3Uncles) { + this.sha3Uncles = sha3Uncles; + } + + public Bloom getLogsBloom() { + return logsBloom; + } + + public void setLogsBloom(Bloom logsBloom) { + this.logsBloom = logsBloom; + } + + public HexData getTransactionsRoot() { + return transactionsRoot; + } + + public void setTransactionsRoot(HexData transactionsRoot) { + this.transactionsRoot = transactionsRoot; + } + + public HexData getStateRoot() { + return stateRoot; + } + + public void setStateRoot(HexData stateRoot) { + this.stateRoot = stateRoot; + } + + public HexData getReceiptsRoot() { + return receiptsRoot; + } + + public void setReceiptsRoot(HexData receiptsRoot) { + this.receiptsRoot = receiptsRoot; + } + + public Address getMiner() { + return miner; + } + + public void setMiner(Address miner) { + this.miner = miner; + } + + public BigInteger getDifficulty() { + return difficulty; + } + + public void setDifficulty(BigInteger difficulty) { + this.difficulty = difficulty; + } + + public BigInteger getTotalDifficulty() { + return totalDifficulty; + } + + public void setTotalDifficulty(BigInteger totalDifficulty) { + this.totalDifficulty = totalDifficulty; + } + + public HexData getExtraData() { + return extraData; + } + + public void setExtraData(HexData extraData) { + this.extraData = extraData; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public Long getGasLimit() { + return gasLimit; + } + + public void setGasLimit(Long gasLimit) { + this.gasLimit = gasLimit; + } + + public Long getGasUsed() { + return gasUsed; + } + + public void setGasUsed(Long gasUsed) { + this.gasUsed = gasUsed; + } + + public Instant getTimestamp() { + return timestamp; + } + + public void setTimestamp(Instant timestamp) { + this.timestamp = timestamp; + } + + public List getTransactions() { + return transactions; + } + + public void setTransactions(List transactions) { + this.transactions = transactions; + } + + public List getUncles() { + return uncles; + } + + public void setUncles(List uncles) { + this.uncles = uncles; + } + + public Wei getBaseFeePerGas() { + return baseFeePerGas; + } + + public void setBaseFeePerGas(Wei baseFeePerGas) { + this.baseFeePerGas = baseFeePerGas; + } + + /** + * If this instance is empty or contains only references, then return as is. Otherwise + * returns a copy of the BlockJson with transactions fields replaced with id references + * + * @return BlockJson instance with transactions ids only. + */ + @SuppressWarnings("unchecked") + public BlockJson withoutTransactionDetails() { + // if empty then type doesn't matter + if (this.transactions == null || this.transactions.isEmpty()) { + return (BlockJson) this; + } + // if it's already just a reference + if (this.transactions.stream().noneMatch((tx) -> tx instanceof TransactionJson)) { + return (BlockJson) this; + } + BlockJson copy = (BlockJson) copy(); + copy.transactions = new ArrayList<>(this.transactions.size()); + for (T tx: this.transactions) { + copy.transactions.add(new TransactionRefJson(tx.getHash())); + } + return copy; + } + + /** + * + * @return copy of the current instance + */ + public BlockJson copy() { + BlockJson copy = new BlockJson<>(); + copy.number = this.number; + copy.hash = this.hash; + copy.parentHash = this.parentHash; + copy.sha3Uncles = this.sha3Uncles; + copy.logsBloom = this.logsBloom; + copy.transactionsRoot = this.transactionsRoot; + copy.stateRoot = this.stateRoot; + copy.receiptsRoot = this.receiptsRoot; + copy.miner = this.miner; + copy.difficulty = this.difficulty; + copy.totalDifficulty = this.totalDifficulty; + copy.extraData = this.extraData; + copy.size = this.size; + copy.gasLimit = this.gasLimit; + copy.gasUsed = this.gasUsed; + copy.timestamp = this.timestamp; + copy.transactions = this.transactions; + copy.uncles = this.uncles; + copy.baseFeePerGas = this.baseFeePerGas; + copy.withdrawalsRoot = this.withdrawalsRoot; + copy.mixHash = this.mixHash; + copy.nonce = this.nonce; + return copy; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BlockJson blockJson = (BlockJson) o; + return Objects.equals(number, blockJson.number) && Objects.equals(hash, blockJson.hash) && Objects.equals(parentHash, blockJson.parentHash) && Objects.equals(sha3Uncles, blockJson.sha3Uncles) && Objects.equals(logsBloom, blockJson.logsBloom) && Objects.equals(transactionsRoot, blockJson.transactionsRoot) && Objects.equals(stateRoot, blockJson.stateRoot) && Objects.equals(receiptsRoot, blockJson.receiptsRoot) && Objects.equals(miner, blockJson.miner) && Objects.equals(difficulty, blockJson.difficulty) && Objects.equals(totalDifficulty, blockJson.totalDifficulty) && Objects.equals(extraData, blockJson.extraData) && Objects.equals(size, blockJson.size) && Objects.equals(gasLimit, blockJson.gasLimit) && Objects.equals(gasUsed, blockJson.gasUsed) && Objects.equals(timestamp, blockJson.timestamp) && Objects.equals(transactions, blockJson.transactions) && Objects.equals(uncles, blockJson.uncles) && Objects.equals(baseFeePerGas, blockJson.baseFeePerGas) && Objects.equals(mixHash, blockJson.mixHash) && Objects.equals(nonce, blockJson.nonce) && Objects.equals(withdrawalsRoot, blockJson.withdrawalsRoot); + } + + @Override + public int hashCode() { + return Objects.hash(number, hash, parentHash, sha3Uncles, logsBloom, transactionsRoot, stateRoot, receiptsRoot, miner, difficulty, totalDifficulty, extraData, size, gasLimit, gasUsed, timestamp, transactions, uncles, baseFeePerGas, mixHash, nonce, withdrawalsRoot); + } +} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJsonDeserializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJsonDeserializer.java new file mode 100644 index 00000000..63b1df62 --- /dev/null +++ b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJsonDeserializer.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2020 EmeraldPay Inc, All Rights Reserved. + * Copyright (c) 2016-2017 Infinitape Inc, All Rights Reserved. + * + * 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 io.emeraldpay.dshackle.upstream.ethereum.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.etherjar.domain.BlockHash; +import io.emeraldpay.etherjar.domain.Bloom; +import io.emeraldpay.etherjar.domain.TransactionId; +import io.emeraldpay.etherjar.hex.HexData; +import io.emeraldpay.etherjar.rpc.json.EtherJsonDeserializer; +import io.emeraldpay.etherjar.rpc.json.TransactionJsonDeserializer; +import io.emeraldpay.etherjar.rpc.json.TransactionRefJson; + +import java.io.IOException; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +public class BlockJsonDeserializer extends EtherJsonDeserializer> { + + private TransactionJsonDeserializer transactionJsonDeserializer = new TransactionJsonDeserializer(); + + @Override @SuppressWarnings("unchecked") + public BlockJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { + JsonNode node = jp.readValueAsTree(); + return deserialize(node); + } + + public BlockJson deserialize(JsonNode node) { + BlockJson blockJson = new BlockJson<>(); + Long number = getLong(node, "number"); + if (number != null) { + blockJson.setNumber(number); + } + blockJson.setHash(getBlockHash(node, "hash")); + Long timestamp = getLong(node, "timestamp"); + if (timestamp != null) { + blockJson.setTimestamp(Instant.ofEpochSecond(timestamp)); + } else { + System.err.println("Null timestamp for block " + number); + } + + if (node.has("transactions")) { + List txes = new ArrayList<>(); + for (JsonNode tx: node.get("transactions")) { + if (tx.isObject()) { + txes.add(transactionJsonDeserializer.deserialize(tx)); + } else { + txes.add(new TransactionRefJson(TransactionId.from(tx.textValue()))); + } + } + blockJson.setTransactions(txes); + } + + blockJson.setParentHash(getBlockHash(node, "parentHash")); + blockJson.setSha3Uncles(getData(node, "sha3Uncles")); + blockJson.setMiner(getAddress(node, "miner")); + blockJson.setDifficulty(getQuantity(node, "difficulty")); + blockJson.setTotalDifficulty(getQuantity(node, "totalDifficulty")); + Long size = getLong(node, "size"); + if (size != null) { + blockJson.setSize(size); + } + blockJson.setGasLimit(getLong(node, "gasLimit")); + blockJson.setGasUsed(getLong(node, "gasUsed")); + blockJson.setExtraData(getData(node, "extraData")); + HexData logsBloom = getData(node, "logsBloom"); + if (logsBloom != null) { + blockJson.setLogsBloom(Bloom.from(logsBloom)); + } + + List uncles = new ArrayList<>(); + JsonNode unclesNode = node.get("uncles"); + if (unclesNode != null && unclesNode.isArray()) { + for (JsonNode tx: unclesNode) { + uncles.add(BlockHash.from(tx.textValue())); + } + } + blockJson.setUncles(uncles); + + blockJson.setBaseFeePerGas(getWei(node, "baseFeePerGas")); + + blockJson.setReceiptsRoot(getData(node, "receiptsRoot")); + blockJson.setStateRoot(getData(node, "stateRoot")); + blockJson.setTransactionsRoot(getData(node, "transactionsRoot")); + blockJson.setNonce(getData(node, "nonce")); + blockJson.setMixHash(getData(node, "mixHash")); + blockJson.setWithdrawalsRoot(getData(node, "withdrawalsRoot")); + + return blockJson; + } + +} diff --git a/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJsonSerializer.java b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJsonSerializer.java new file mode 100644 index 00000000..b312c875 --- /dev/null +++ b/src/main/java/io/emeraldpay/dshackle/upstream/ethereum/json/BlockJsonSerializer.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016-2019 Igor Artamonov, All Rights Reserved. + * + * 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 io.emeraldpay.dshackle.upstream.ethereum.json; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import io.emeraldpay.etherjar.domain.BlockHash; +import io.emeraldpay.etherjar.domain.Wei; +import io.emeraldpay.etherjar.rpc.json.EtherJsonSerializer; +import io.emeraldpay.etherjar.rpc.json.TransactionJson; +import io.emeraldpay.etherjar.rpc.json.TransactionJsonSerializer; +import io.emeraldpay.etherjar.rpc.json.TransactionRefJson; + +import java.io.IOException; + +public class BlockJsonSerializer extends EtherJsonSerializer> { + + private TransactionJsonSerializer transactionJsonSerializer = new TransactionJsonSerializer(); + + @Override + public void serialize(BlockJson value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + writeField(gen, "number", value.getNumber()); + writeField(gen, "hash", value.getHash()); + writeField(gen, "timestamp", value.getTimestamp()); + + Wei baseFeePerGas = value.getBaseFeePerGas(); + if (baseFeePerGas != null) { + writeField(gen, "baseFeePerGas", baseFeePerGas); + } + + gen.writeFieldName("transactions"); + gen.writeStartArray(); + if (value.getTransactions() != null) { + for (Object tx: value.getTransactions()) { + if (tx == null) { + gen.writeNull(); + } else if (tx instanceof TransactionJson) { + transactionJsonSerializer.serialize((TransactionJson) tx, gen, serializers); + } else if (tx instanceof TransactionRefJson) { + gen.writeString(((TransactionRefJson) tx).getHash().toHex()); + } + } + } + gen.writeEndArray(); + + writeField(gen, "parentHash", value.getParentHash()); + writeField(gen, "sha3Uncles", value.getSha3Uncles()); + writeField(gen, "miner", value.getMiner()); + writeField(gen, "difficulty", value.getDifficulty()); + writeField(gen, "totalDifficulty", value.getTotalDifficulty()); + if (value.getSize() != null) { + writeFieldNumber(gen, "size", value.getSize().intValue()); + } + writeField(gen, "gasLimit", value.getGasLimit()); + writeField(gen, "gasUsed", value.getGasUsed()); + writeField(gen, "extraData", value.getExtraData()); + writeField(gen, "stateRoot", value.getStateRoot()); + writeField(gen, "receiptsRoot", value.getReceiptsRoot()); + writeField(gen, "transactionsRoot", value.getTransactionsRoot()); + writeField(gen, "logsBloom", value.getLogsBloom()); + writeField(gen, "mixHash", value.getMixHash()); + writeField(gen, "nonce", value.getNonce()); + writeField(gen, "withdrawalsRoot", value.getWithdrawalsRoot()); + + gen.writeFieldName("uncles"); + gen.writeStartArray(); + if (value.getUncles() != null) { + for (BlockHash uncle: value.getUncles()) { + gen.writeString(uncle.toHex()); + } + } + gen.writeEndArray(); + + gen.writeEndObject(); + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt index 2fff5c47..8b9a6fbc 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt @@ -24,7 +24,7 @@ import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.reader.CompoundReader import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.Head -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt index 025636ff..bb2a31f8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt @@ -17,11 +17,11 @@ package io.emeraldpay.dshackle.data import io.emeraldpay.dshackle.Global +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.Bloom import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import java.math.BigInteger diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt index d4f1a0ab..b16540b9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt @@ -16,8 +16,8 @@ */ package io.emeraldpay.dshackle.data +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson import org.bouncycastle.util.encoders.Hex class BlockId( diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt index 2d5db6f4..1fbcdb52 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt @@ -25,10 +25,10 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.rpc.RpcException -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt index 81d41144..42cd66de 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt @@ -10,7 +10,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.RLP.Companion.encodeBigInt import io.emeraldpay.dshackle.upstream.ethereum.RLP.Companion.encodeList import io.emeraldpay.dshackle.upstream.ethereum.RLP.Companion.fromHexString import io.emeraldpay.dshackle.upstream.ethereum.RLP.Companion.fromHexStringI -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import org.bouncycastle.jcajce.provider.digest.Keccak import org.slf4j.LoggerFactory import java.math.BigDecimal diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt index 57dff0b3..c0ba9601 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt @@ -39,11 +39,11 @@ import io.emeraldpay.dshackle.reader.TransformingReader import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.CallMethods +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import org.apache.commons.collections4.Factory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt index 0bc57048..8efcf65b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt @@ -15,6 +15,7 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.calls.CallMethods +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash @@ -23,7 +24,6 @@ import io.emeraldpay.etherjar.domain.Wei import io.emeraldpay.etherjar.hex.HexQuantity import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.etherjar.rpc.RpcResponseError -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt index b6f935e2..40f34242 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt @@ -18,8 +18,8 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.dshackle.upstream.AbstractChainFees import io.emeraldpay.dshackle.upstream.ChainFees import io.emeraldpay.dshackle.upstream.Multistream +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt index 0afa5c6a..93cf69f5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt @@ -16,8 +16,8 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.api.proto.BlockchainOuterClass +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt index 648a66d7..72aeb0c8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt @@ -17,8 +17,8 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.dshackle.upstream.Multistream +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt index 216d86d3..6c3a5e5e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt @@ -23,10 +23,10 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.reader.JsonRpcReader import io.emeraldpay.dshackle.upstream.BlockValidator import io.emeraldpay.dshackle.upstream.Lifecycle +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import reactor.core.Disposable import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt index 28c90088..b26a8ab2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt @@ -43,6 +43,14 @@ class ProduceNewHeads( block.logsBloom, block.miner, block.baseFeePerGas?.amount, + block.extraData, + block.mixHash, + block.nonce, + block.receiptsRoot, + block.sha3Uncles, + block.stateRoot, + block.transactionsRoot, + block.withdrawalsRoot, it.upstreamId ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessage.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessage.kt index 5dd5b175..f6fd348f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessage.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessage.kt @@ -21,14 +21,15 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.Bloom +import io.emeraldpay.etherjar.domain.TransactionId +import io.emeraldpay.etherjar.hex.HexData import io.emeraldpay.etherjar.rpc.json.HexDataSerializer import java.math.BigInteger import java.time.Instant /** * Common fields for newHeads event. IT's different from Block JSON and doesn't include many fields, most notable is - * list of transactions. Also, our JSON doesn't include rarely used fields such as extraData, sha3uncles, stateRoot, - * transactionRoot and some others. + * list of transactions. */ data class NewHeadMessage( @get:JsonSerialize(using = NumberAsHexSerializer::class) @@ -52,6 +53,30 @@ data class NewHeadMessage( @get:JsonSerialize(using = NumberAsHexSerializer::class) @get:JsonInclude(JsonInclude.Include.NON_NULL) val baseFeePerGas: BigInteger?, + + @get:JsonSerialize(using = HexDataSerializer::class) + val extraData: HexData, + @get:JsonSerialize(using = HexDataSerializer::class) + val mixHash: HexData?, + @get:JsonSerialize(using = HexDataSerializer::class) + val nonce: HexData, + @get:JsonSerialize(using = HexDataSerializer::class) + val receiptsRoot: HexData, + @get:JsonSerialize(using = HexDataSerializer::class) + val sha3Uncles: HexData, + @get:JsonSerialize(using = HexDataSerializer::class) + val stateRoot: HexData, + @get:JsonSerialize(using = HexDataSerializer::class) + val transactionsRoot: HexData, + @get:JsonSerialize(using = HexDataSerializer::class) + @get:JsonInclude(JsonInclude.Include.NON_NULL) + val withdrawalsRoot: HexData?, + @get:JsonIgnore - override val upstreamId: String + override val upstreamId: String, + + // lists always empty + val transactions: List = emptyList(), + val uncles: List = emptyList(), + val sealFields: List = emptyList(), ) : HasUpstream diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/BlockByHeightSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/BlockByHeightSpec.groovy index 0ba19034..098a8215 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/BlockByHeightSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/BlockByHeightSpec.groovy @@ -20,7 +20,7 @@ import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksMemCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksMemCacheSpec.groovy index 0a3a1463..7b403165 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksMemCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksMemCacheSpec.groovy @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy index b0cacce2..37572c75 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.test.IntegrationTestingCommons import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import io.lettuce.core.api.StatefulRedisConnection import spock.lang.IgnoreIf diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/CachesSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/CachesSpec.groovy index d926414e..17fcf684 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/CachesSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/CachesSpec.groovy @@ -26,7 +26,7 @@ import io.emeraldpay.dshackle.upstream.Head import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/HeightCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/HeightCacheSpec.groovy index 8577f3a5..cb8ceadc 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/HeightCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/HeightCacheSpec.groovy @@ -17,7 +17,7 @@ package io.emeraldpay.dshackle.cache import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/TxMemCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/TxMemCacheSpec.groovy index 982a5547..263c9752 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/TxMemCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/TxMemCacheSpec.groovy @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.data.TxContainer import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy index 58696a30..bf64a2bb 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy @@ -26,7 +26,7 @@ import io.emeraldpay.dshackle.test.IntegrationTestingCommons import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import io.lettuce.core.api.StatefulRedisConnection diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy index 93899680..e1b24299 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy @@ -28,7 +28,7 @@ import io.emeraldpay.dshackle.test.MultistreamHolderMock import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import reactor.core.publisher.Mono import reactor.test.StepVerifier diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy index 7d5ae6c0..4ea6d290 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy @@ -24,7 +24,7 @@ import io.emeraldpay.dshackle.test.MultistreamHolderMock import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import reactor.test.StepVerifier import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy index 4838df0b..7265110f 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy @@ -29,7 +29,7 @@ import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import reactor.core.publisher.Flux diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy index 33a67133..e670774e 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy @@ -33,7 +33,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.micrometer.core.instrument.MeterRegistry import io.micrometer.core.instrument.logging.LoggingMeterRegistry import org.apache.commons.lang3.StringUtils diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/DistanceExtractorSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/DistanceExtractorSpec.groovy index 69dba530..a07b29e6 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/DistanceExtractorSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/DistanceExtractorSpec.groovy @@ -2,7 +2,7 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import spock.lang.Specification import java.time.Instant diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/HeadLagObserverSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/HeadLagObserverSpec.groovy index b21bda45..9c156a67 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/HeadLagObserverSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/HeadLagObserverSpec.groovy @@ -18,7 +18,7 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import org.jetbrains.annotations.NotNull import reactor.core.publisher.Flux import reactor.core.publisher.Sinks diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy index a6d019c4..eb1651e7 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy @@ -32,7 +32,7 @@ import io.emeraldpay.dshackle.upstream.grpc.EthereumPosGrpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import org.jetbrains.annotations.NotNull import reactor.core.publisher.Flux diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DefaultEthereumHeadSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DefaultEthereumHeadSpec.groovy index d9afc122..98a7ef48 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DefaultEthereumHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/DefaultEthereumHeadSpec.groovy @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.upstream.BlockValidator import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import reactor.core.publisher.Flux import reactor.core.scheduler.Schedulers import reactor.test.StepVerifier diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidatorSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidatorSpec.groovy index 71c35a48..e607dd16 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidatorSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidatorSpec.groovy @@ -4,7 +4,7 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import org.apache.commons.io.FileUtils import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy index d81a6b26..08b8723c 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReaderSpec.groovy @@ -19,7 +19,7 @@ import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson import org.apache.commons.collections4.Factory diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFeesSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFeesSpec.groovy index f2dd9284..8c9e8225 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFeesSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFeesSpec.groovy @@ -16,7 +16,7 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReaderSpec.groovy index a3e19dac..e5639b7d 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReaderSpec.groovy @@ -10,7 +10,7 @@ import io.emeraldpay.dshackle.upstream.EmptyHead import io.emeraldpay.dshackle.upstream.Head import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import org.apache.commons.collections4.functors.ConstantFactory import reactor.core.publisher.Mono import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFeesSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFeesSpec.groovy index c2fd0a85..517c9813 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFeesSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFeesSpec.groovy @@ -20,7 +20,7 @@ import io.emeraldpay.dshackle.upstream.ChainFees import io.emeraldpay.dshackle.upstream.Head import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import reactor.core.publisher.Flux diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHeadSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHeadSpec.groovy index 065cd656..871576da 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHeadSpec.groovy @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.upstream.BlockValidator import io.emeraldpay.dshackle.upstream.forkchoice.AlwaysForkChoice import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import reactor.core.publisher.Flux import reactor.core.publisher.Mono diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdatesSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdatesSpec.groovy index 0a2e8798..13ff8503 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdatesSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdatesSpec.groovy @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import reactor.core.publisher.Flux import reactor.core.scheduler.Schedulers diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessageSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessageSpec.groovy index f0db8a88..3982693b 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessageSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/NewHeadMessageSpec.groovy @@ -5,6 +5,7 @@ import io.emeraldpay.dshackle.Global import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.Bloom +import io.emeraldpay.etherjar.hex.HexData import spock.lang.Specification import java.time.Instant @@ -24,19 +25,41 @@ class NewHeadMessageSpec extends Specification { Bloom.from("0x012040020880820356a20b8e980a2004c19f1291800501040001180bb029d0002d8c49440e002048ca00d48581000d900a458100c90139056140880582f22a0a8050224c020c233be8c3080c0a016aa4226a2001446c800822080445a2454118139804001202068401841900840c484222420c4b2022046052c0011e81a9e450085883708545810592e40040010411442300080b0130711f602880600a30c90702cb420a0102a644820650908802840810948142541404884300acc69d000840702020224c000020200880c10858418408098a61445b0ab0480234862655a5000434311b91044849c165040411aa0400b00008222642d24313020d9022219120"), Address.from("0x829bd824b016326a401d083b33d092293333a830"), null, - "NewHeadMessageSpec" + HexData.from("0x0000000000000001"), // extra data + HexData.from("0x0000000000000002"), // mixHash + HexData.from("0x0000000000000003"), // nonce + HexData.from("0x0000000000000004"), // receiptsRoot + HexData.from("0x0000000000000005"), // sha3Uncles + HexData.from("0x0000000000000006"), // stateRoot + HexData.from("0x0000000000000007"), // transactionsRoot + HexData.from("0x0000000000000008"), // withdrawalsRoot + "NewHeadMessageSpec", + [], + [], + [] ) ObjectMapper objectMapper = Global.getObjectMapper() - def exp = '{' + + def exp = '{'+ '"number":"0xc7f3b4",' + - '"hash":"0xd3b7ae1a79f5418debae9b8e9318094298c087183be0f7a0151b0e76ba38d6bc",' + - '"parentHash":"0xcda7fd1d6ee2d5da7505a0634e27f41d5ae87a344cd75bb64c1dc0863fbe9c0a",' + - '"timestamp":"0x6128264d",' + - '"difficulty":"0x1de7f7a458cc08",' + - '"gasLimit":"0x1ca35ef",' + - '"gasUsed":"0x7bb33e",' + - '"logsBloom":"0x012040020880820356a20b8e980a2004c19f1291800501040001180bb029d0002d8c49440e002048ca00d48581000d900a458100c90139056140880582f22a0a8050224c020c233be8c3080c0a016aa4226a2001446c800822080445a2454118139804001202068401841900840c484222420c4b2022046052c0011e81a9e450085883708545810592e40040010411442300080b0130711f602880600a30c90702cb420a0102a644820650908802840810948142541404884300acc69d000840702020224c000020200880c10858418408098a61445b0ab0480234862655a5000434311b91044849c165040411aa0400b00008222642d24313020d9022219120",' + - '"miner":"0x829bd824b016326a401d083b33d092293333a830"' + + '"hash":"0xd3b7ae1a79f5418debae9b8e9318094298c087183be0f7a0151b0e76ba38d6bc",'+ + '"parentHash":"0xcda7fd1d6ee2d5da7505a0634e27f41d5ae87a344cd75bb64c1dc0863fbe9c0a",'+ + '"timestamp":"0x6128264d",'+ + '"difficulty":"0x1de7f7a458cc08",'+ + '"gasLimit":"0x1ca35ef",'+ + '"gasUsed":"0x7bb33e",'+ + '"logsBloom":"0x012040020880820356a20b8e980a2004c19f1291800501040001180bb029d0002d8c49440e002048ca00d48581000d900a458100c90139056140880582f22a0a8050224c020c233be8c3080c0a016aa4226a2001446c800822080445a2454118139804001202068401841900840c484222420c4b2022046052c0011e81a9e450085883708545810592e40040010411442300080b0130711f602880600a30c90702cb420a0102a644820650908802840810948142541404884300acc69d000840702020224c000020200880c10858418408098a61445b0ab0480234862655a5000434311b91044849c165040411aa0400b00008222642d24313020d9022219120",'+ + '"miner":"0x829bd824b016326a401d083b33d092293333a830",'+ + '"extraData":"0x0000000000000001",'+ + '"mixHash":"0x0000000000000002",'+ + '"nonce":"0x0000000000000003",'+ + '"receiptsRoot":"0x0000000000000004",'+ + '"sha3Uncles":"0x0000000000000005",'+ + '"stateRoot":"0x0000000000000006",'+ + '"transactionsRoot":"0x0000000000000007",'+ + '"withdrawalsRoot":"0x0000000000000008",'+ + '"transactions":[],'+ + '"uncles":[],'+ + '"sealFields":[]'+ '}' when: def json = objectMapper.writeValueAsString(obj) diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy index 3798883d..2eae2dd0 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy @@ -33,7 +33,7 @@ import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient import io.emeraldpay.dshackle.upstream.rpcclient.RpcMetrics import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.json.BlockJson +import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson import io.grpc.stub.StreamObserver import io.micrometer.core.instrument.Counter import io.micrometer.core.instrument.Timer