diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/GroupStatus.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/GroupStatus.java new file mode 100644 index 000000000..6804d0994 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/GroupStatus.java @@ -0,0 +1,77 @@ +/* + * Copyright 2014-2020 [fisco-dev] + * + * 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 org.fisco.bcos.sdk.client.protocol.model; + +import java.util.Objects; + +public class GroupStatus { + private String code; + private String message; + private String status; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GroupStatus that = (GroupStatus) o; + return Objects.equals(code, that.code) + && Objects.equals(message, that.message) + && Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(code, message, status); + } + + @Override + public String toString() { + return "GroupStatus{" + + "code='" + + code + + '\'' + + ", message='" + + message + + '\'' + + ", status='" + + status + + '\'' + + '}'; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/JsonTransactionResponse.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/JsonTransactionResponse.java new file mode 100644 index 000000000..c5993ca2a --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/JsonTransactionResponse.java @@ -0,0 +1,199 @@ +/* + * Copyright 2014-2020 [fisco-dev] + * + * 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 org.fisco.bcos.sdk.client.protocol.model; + +import java.math.BigInteger; +import java.util.Objects; +import org.fisco.bcos.sdk.utils.Numeric; + +public class JsonTransactionResponse { + // the fields related to get-transaction + private String blockHash; + private String blockNumber; + private String from; + private String gas; + private String hash; + private String input; + private String nonce; + private String to; + private String transactionIndex; + private String value; + + // the fields related to get-block + private String gasPrice; + + public String getBlockHash() { + return blockHash; + } + + public void setBlockHash(String blockHash) { + this.blockHash = blockHash; + } + + public BigInteger getBlockNumber() { + return Numeric.decodeQuantity(blockNumber); + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getGas() { + return gas; + } + + public void setGas(String gas) { + this.gas = gas; + } + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getNonce() { + return nonce; + } + + public void setNonce(String nonce) { + this.nonce = nonce; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String getTransactionIndex() { + return transactionIndex; + } + + public void setTransactionIndex(String transactionIndex) { + this.transactionIndex = transactionIndex; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getGasPrice() { + return gasPrice; + } + + public void setGasPrice(String gasPrice) { + this.gasPrice = gasPrice; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + JsonTransactionResponse that = (JsonTransactionResponse) o; + return Objects.equals(blockHash, that.blockHash) + && Objects.equals( + Numeric.decodeQuantity(blockNumber), + Numeric.decodeQuantity(that.blockNumber)) + && Objects.equals(from, that.from) + && Objects.equals(gas, that.gas) + && Objects.equals(hash, that.hash) + && Objects.equals(input, that.input) + && Objects.equals(nonce, that.nonce) + && Objects.equals(to, that.to) + && Objects.equals(transactionIndex, that.transactionIndex) + && Objects.equals(value, that.value) + && Objects.equals(gasPrice, that.gasPrice); + } + + @Override + public int hashCode() { + return Objects.hash( + blockHash, + Numeric.decodeQuantity(blockNumber), + from, + gas, + hash, + input, + nonce, + to, + transactionIndex, + value, + gasPrice); + } + + @Override + public String toString() { + return "JsonTransactionResponse{" + + "blockHash='" + + blockHash + + '\'' + + ", blockNumber='" + + blockNumber + + '\'' + + ", from='" + + from + + '\'' + + ", gas='" + + gas + + '\'' + + ", hash='" + + hash + + '\'' + + ", input='" + + input + + '\'' + + ", nonce='" + + nonce + + '\'' + + ", to='" + + to + + '\'' + + ", transactionIndex='" + + transactionIndex + + '\'' + + ", value='" + + value + + '\'' + + ", gasPrice='" + + gasPrice + + '\'' + + '}'; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/MerkleProofUnit.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/MerkleProofUnit.java new file mode 100644 index 000000000..c81022bc8 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/MerkleProofUnit.java @@ -0,0 +1,58 @@ +/* + * Copyright 2014-2020 [fisco-dev] + * + * 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 org.fisco.bcos.sdk.client.protocol.model; + +import java.util.List; +import java.util.Objects; + +public class MerkleProofUnit { + private List left; + private List right; + + public List getLeft() { + return left; + } + + public void setLeft(List left) { + this.left = left; + } + + public List getRight() { + return right; + } + + public void setRight(List right) { + this.right = right; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MerkleProofUnit that = (MerkleProofUnit) o; + return Objects.equals(left, that.left) && Objects.equals(right, that.right); + } + + @Override + public int hashCode() { + return Objects.hash(left, right); + } + + @Override + public String toString() { + return "MerkleProofUnit{" + "left=" + left + ", right=" + right + '}'; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/TransactionReceipt.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/TransactionReceipt.java new file mode 100644 index 000000000..54e1515b3 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/model/TransactionReceipt.java @@ -0,0 +1,319 @@ +/* + * Copyright 2014-2020 [fisco-dev] + * + * 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 org.fisco.bcos.sdk.client.protocol.model; + +import java.util.List; +import java.util.Objects; + +public class TransactionReceipt { + private String transactionHash; + private String transactionIndex; + private String root; + private String blockNumber; + private String blockHash; + private String from; + private String to; + private String gasUsed; + private String contractAddress; + private List logs; + private String logsBloom; + private String status; + private String input; + private String output; + private List txProof; + private List receiptProof; + + public static class Logs { + private String address; + private List topics; + private String data; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public List getTopics() { + return topics; + } + + public void setTopics(List topics) { + this.topics = topics; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Logs logs = (Logs) o; + return Objects.equals(address, logs.address) + && Objects.equals(topics, logs.topics) + && Objects.equals(data, logs.data); + } + + @Override + public int hashCode() { + return Objects.hash(address, topics, data); + } + + @Override + public String toString() { + return "Logs{" + + "address='" + + address + + '\'' + + ", topics=" + + topics + + ", data='" + + data + + '\'' + + '}'; + } + } + + public List getReceiptProof() { + return receiptProof; + } + + public void setReceiptProof(List receiptProof) { + this.receiptProof = receiptProof; + } + + public String getTransactionHash() { + return transactionHash; + } + + public void setTransactionHash(String transactionHash) { + this.transactionHash = transactionHash; + } + + public String getTransactionIndex() { + return transactionIndex; + } + + public void setTransactionIndex(String transactionIndex) { + this.transactionIndex = transactionIndex; + } + + public String getRoot() { + return root; + } + + public void setRoot(String root) { + this.root = root; + } + + public String getBlockNumber() { + return blockNumber; + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public String getBlockHash() { + return blockHash; + } + + public void setBlockHash(String blockHash) { + this.blockHash = blockHash; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String getGasUsed() { + return gasUsed; + } + + public void setGasUsed(String gasUsed) { + this.gasUsed = gasUsed; + } + + public String getContractAddress() { + return contractAddress; + } + + public void setContractAddress(String contractAddress) { + this.contractAddress = contractAddress; + } + + public List getLogs() { + return logs; + } + + public void setLogs(List logs) { + this.logs = logs; + } + + public String getLogsBloom() { + return logsBloom; + } + + public void setLogsBloom(String logsBloom) { + this.logsBloom = logsBloom; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } + + public List getTxProof() { + return txProof; + } + + public void setTxProof(List txProof) { + this.txProof = txProof; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TransactionReceipt that = (TransactionReceipt) o; + return Objects.equals(transactionHash, that.transactionHash) + && Objects.equals(transactionIndex, that.transactionIndex) + && Objects.equals(root, that.root) + && Objects.equals(blockNumber, that.blockNumber) + && Objects.equals(blockHash, that.blockHash) + && Objects.equals(from, that.from) + && Objects.equals(to, that.to) + && Objects.equals(gasUsed, that.gasUsed) + && Objects.equals(contractAddress, that.contractAddress) + && Objects.equals(logs, that.logs) + && Objects.equals(logsBloom, that.logsBloom) + && Objects.equals(status, that.status) + && Objects.equals(input, that.input) + && Objects.equals(output, that.output) + && Objects.equals(txProof, that.txProof) + && Objects.equals(receiptProof, that.receiptProof); + } + + @Override + public int hashCode() { + return Objects.hash( + transactionHash, + transactionIndex, + root, + blockNumber, + blockHash, + from, + to, + gasUsed, + contractAddress, + logs, + logsBloom, + status, + input, + output, + txProof, + receiptProof); + } + + @Override + public String toString() { + return "TransactionReceipt{" + + "transactionHash='" + + transactionHash + + '\'' + + ", transactionIndex='" + + transactionIndex + + '\'' + + ", root='" + + root + + '\'' + + ", blockNumber='" + + blockNumber + + '\'' + + ", blockHash='" + + blockHash + + '\'' + + ", from='" + + from + + '\'' + + ", to='" + + to + + '\'' + + ", gasUsed='" + + gasUsed + + '\'' + + ", contractAddress='" + + contractAddress + + '\'' + + ", logs=" + + logs + + ", logsBloom='" + + logsBloom + + '\'' + + ", status='" + + status + + '\'' + + ", input='" + + input + + '\'' + + ", output='" + + output + + '\'' + + ", txProof=" + + txProof + + ", receiptProof=" + + receiptProof + + '}'; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/request/JsonRpcMethods.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/request/JsonRpcMethods.java index d791f0024..999e74f60 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/request/JsonRpcMethods.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/request/JsonRpcMethods.java @@ -18,7 +18,7 @@ public class JsonRpcMethods { // the interface related to the group public static final String GET_BLOCK_NUMBER = "getBlockNumber"; - public static final String GET_NODE_VERSION = "getNodeVersion"; + public static final String GET_NODE_VERSION = "getClientVersion"; public static final String GET_PBFT_VIEW = "getPbftView"; public static final String GET_SEALER_LIST = "getSealerList"; public static final String GET_SYSTEM_CONFIG_BY_KEY = "getSystemConfigByKey"; diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlock.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlock.java index 9fd707f23..222ee4d58 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlock.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlock.java @@ -15,4 +15,160 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class BcosBlock extends JsonRpcResponse {} +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import org.fisco.bcos.sdk.client.protocol.model.JsonTransactionResponse; +import org.fisco.bcos.sdk.utils.ObjectMapperFactory; + +public class BcosBlock extends JsonRpcResponse { + @Override + @JsonDeserialize(using = BcosBlock.BlockDeserialiser.class) + public void setResult(Block result) { + super.setResult(result); + } + + public Block getBlock() { + return getResult(); + } + + public interface TransactionResult {} + + public static class TransactionHash implements TransactionResult {} + + public static class TransactionObject extends JsonTransactionResponse + implements TransactionResult {} + + public static class Block extends BcosBlockHeader.BlockHeader { + private List transactions; + + public List getTransactions() { + return transactions; + } + + @JsonDeserialize(using = TransactionResultDeserialiser.class) + public void setTransactions(List transactions) { + this.transactions = transactions; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Block block = (Block) o; + return Objects.equals(transactions, block.transactions); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), transactions); + } + + @Override + public String toString() { + return "Block{" + + "transactions=" + + transactions + + ", number='" + + number + + '\'' + + ", hash='" + + hash + + '\'' + + ", parentHash='" + + parentHash + + '\'' + + ", logsBloom='" + + logsBloom + + '\'' + + ", transactionsRoot='" + + transactionsRoot + + '\'' + + ", receiptsRoot='" + + receiptsRoot + + '\'' + + ", dbHash='" + + dbHash + + '\'' + + ", stateRoot='" + + stateRoot + + '\'' + + ", sealer='" + + sealer + + '\'' + + ", sealerList=" + + sealerList + + ", extraData=" + + extraData + + ", gasLimit='" + + gasLimit + + '\'' + + ", gasUsed='" + + gasUsed + + '\'' + + ", timestamp='" + + timestamp + + '\'' + + ", signatureList=" + + signatureList + + '}'; + } + } + + // decode transactionResult + public static class TransactionResultDeserialiser + extends JsonDeserializer> { + + private ObjectReader objectReader = ObjectMapperFactory.getObjectReader(); + + @Override + public List deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException { + List transactionResults = new ArrayList<>(); + JsonToken nextToken = jsonParser.nextToken(); + + if (nextToken == JsonToken.START_OBJECT) { + Iterator transactionObjectIterator = + objectReader.readValues(jsonParser, TransactionObject.class); + while (transactionObjectIterator.hasNext()) { + transactionResults.add(transactionObjectIterator.next()); + } + } else if (nextToken == JsonToken.VALUE_STRING) { + jsonParser.getValueAsString(); + + Iterator transactionHashIterator = + objectReader.readValues(jsonParser, TransactionHash.class); + while (transactionHashIterator.hasNext()) { + transactionResults.add(transactionHashIterator.next()); + } + } + return transactionResults; + } + } + + // decode the block + public static class BlockDeserialiser extends JsonDeserializer { + private ObjectReader objectReader = ObjectMapperFactory.getObjectReader(); + + @Override + public Block deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException { + if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) { + return objectReader.readValue(jsonParser, Block.class); + } else { + return null; // null is wrapped by Optional in above getter + } + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlockHeader.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlockHeader.java index a1d664a07..215d8e331 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlockHeader.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosBlockHeader.java @@ -18,6 +18,7 @@ import java.math.BigInteger; import java.util.List; import java.util.Objects; +import org.fisco.bcos.sdk.utils.Numeric; public class BcosBlockHeader extends JsonRpcResponse { @@ -80,21 +81,21 @@ public String toString() { } public static class BlockHeader { - private BigInteger number; - private String hash; - private String parentHash; - private String logsBloom; - private String transactionsRoot; - private String receiptsRoot; - private String dbHash; - private String stateRoot; - private String sealer; - private List sealerList; - private List extraData; - private String gasLimit; - private String gasUsed; - private String timestamp; - private List signatureList; + protected String number; + protected String hash; + protected String parentHash; + protected String logsBloom; + protected String transactionsRoot; + protected String receiptsRoot; + protected String dbHash; + protected String stateRoot; + protected String sealer; + protected List sealerList; + protected List extraData; + protected String gasLimit; + protected String gasUsed; + protected String timestamp; + protected List signatureList; public void setSignatureList(List signatureList) { this.signatureList = signatureList; @@ -104,7 +105,7 @@ public List getSignatureList() { return this.signatureList; } - public void setNumber(BigInteger number) { + public void setNumber(String number) { this.number = number; } @@ -161,7 +162,7 @@ public void setTimestamp(String timestamp) { } public BigInteger getNumber() { - return number; + return Numeric.decodeQuantity(number); } public String getHash() { @@ -221,7 +222,8 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BlockHeader that = (BlockHeader) o; - return Objects.equals(number, that.number) + return Objects.equals( + Numeric.decodeQuantity(number), Numeric.decodeQuantity(that.number)) && Objects.equals(hash, that.hash) && Objects.equals(parentHash, that.parentHash) && Objects.equals(logsBloom, that.logsBloom) @@ -241,7 +243,7 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash( - number, + Numeric.decodeQuantity(number), hash, parentHash, logsBloom, diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransaction.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransaction.java index 77e58e979..7928d9aa8 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransaction.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransaction.java @@ -1,3 +1,32 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class BcosTransaction extends JsonRpcResponse {} +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectReader; +import java.io.IOException; +import java.util.Optional; +import org.fisco.bcos.sdk.client.protocol.model.JsonTransactionResponse; +import org.fisco.bcos.sdk.utils.ObjectMapperFactory; + +public class BcosTransaction extends JsonRpcResponse { + public Optional getTransaction() { + return Optional.ofNullable(getResult()); + } + + public static class ResponseDeserialiser extends JsonDeserializer { + private ObjectReader objectReader = ObjectMapperFactory.getObjectReader(); + + @Override + public JsonTransactionResponse deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException { + if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) { + return objectReader.readValue(jsonParser, JsonTransactionResponse.class); + } else { + return null; // null is wrapped by Optional in above getter + } + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java index 711f5166e..d46636ece 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java @@ -15,5 +15,34 @@ package org.fisco.bcos.sdk.client.protocol.response; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectReader; +import java.io.IOException; +import java.util.Optional; +import org.fisco.bcos.sdk.client.protocol.model.TransactionReceipt; +import org.fisco.bcos.sdk.utils.ObjectMapperFactory; + /** getTransactionReceipt. */ -public class BcosTransactionReceipt extends JsonRpcResponse {} +public class BcosTransactionReceipt extends JsonRpcResponse { + public Optional getTransactionReceipt() { + return Optional.ofNullable(getResult()); + } + + public static class ResponseDeserialiser extends JsonDeserializer { + private ObjectReader objectReader = ObjectMapperFactory.getObjectReader(); + + @Override + public TransactionReceipt deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException { + if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) { + return objectReader.readValue(jsonParser, TransactionReceipt.class); + } else { + return null; // null is wrapped by Optional in above getter + } + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockHash.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockHash.java index d11e3f75b..1287267f7 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockHash.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockHash.java @@ -16,4 +16,8 @@ package org.fisco.bcos.sdk.client.protocol.response; /** getBlockHashByNumber */ -public class BlockHash extends JsonRpcResponse {} +public class BlockHash extends JsonRpcResponse { + public String getBlockHashByNumber() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockNumber.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockNumber.java index f1703036a..7c125985d 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockNumber.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BlockNumber.java @@ -15,5 +15,12 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.math.BigInteger; +import org.fisco.bcos.sdk.utils.Numeric; + /** getblockNumber. */ -public class BlockNumber extends JsonRpcResponse {} +public class BlockNumber extends JsonRpcResponse { + public BigInteger getBlockNumber() { + return Numeric.decodeQuantity(getResult()); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Call.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Call.java index efff92780..f3d8777c7 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Call.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Call.java @@ -15,6 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.math.BigInteger; +import java.util.Objects; +import org.fisco.bcos.sdk.utils.Numeric; + /** * RPC response of ledger call * @@ -23,15 +27,23 @@ public class Call extends JsonRpcResponse { public static class CallOutput { private String currentBlockNumber; - private String output; private String status; + private String output; - public String getCurrentBlockNumber() { - return currentBlockNumber; + public BigInteger getCurrentBlockNumber() { + return Numeric.decodeQuantity(currentBlockNumber); } - public void setCurrentBlockNumber(String number) { - this.currentBlockNumber = number; + public void setCurrentBlockNumber(String currentBlockNumber) { + this.currentBlockNumber = currentBlockNumber; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; } public String getOutput() { @@ -42,20 +54,44 @@ public void setOutput(String output) { this.output = output; } - public String getStatus() { - return status; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CallOutput that = (CallOutput) o; + return Objects.equals( + Numeric.decodeQuantity(currentBlockNumber), + Numeric.decodeQuantity(that.currentBlockNumber)) + && Objects.equals(status, that.status) + && Objects.equals(output, that.output); } - public void setStatus(String status) { - this.status = status; + @Override + public int hashCode() { + return Objects.hash(Numeric.decodeQuantity(currentBlockNumber), status, output); } - } - public CallOutput getValue() { - return getResult(); + @Override + public String toString() { + return "CallOutput{" + + "currentBlockNumber='" + + currentBlockNumber + + '\'' + + ", status='" + + status + + '\'' + + ", output='" + + output + + '\'' + + '}'; + } } public void setResult(CallOutput result) { super.setResult(result); } + + public CallOutput getCallResult() { + return getResult(); + } } diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Code.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Code.java index 346eef8a5..2820f4130 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Code.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Code.java @@ -20,4 +20,8 @@ * * @author Maggie */ -public class Code extends JsonRpcResponse {} +public class Code extends JsonRpcResponse { + public String getCode() { + return this.getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ConsensusStatus.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ConsensusStatus.java index d657f3d10..89035a786 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ConsensusStatus.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ConsensusStatus.java @@ -15,5 +15,460 @@ package org.fisco.bcos.sdk.client.protocol.response; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import org.fisco.bcos.sdk.utils.ObjectMapperFactory; + /** getConsensusStatus */ -public class ConsensusStatus extends JsonRpcResponse {} +public class ConsensusStatus extends JsonRpcResponse { + @Override + @JsonDeserialize(using = ConsensusStatusDeserializer.class) + public void setResult(ConsensusStatus.ConsensusInfo result) { + super.setResult(result); + } + + public ConsensusInfo getConsensusStatus() { + return getResult(); + } + + public static class ViewInfo { + private String nodeId; + private String view; + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getView() { + return view; + } + + public void setView(String view) { + this.view = view; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ViewInfo viewInfo = (ViewInfo) o; + return Objects.equals(nodeId, viewInfo.nodeId) && Objects.equals(view, viewInfo.view); + } + + @Override + public int hashCode() { + return Objects.hash(nodeId, view); + } + + @Override + public String toString() { + return "ViewInfo{" + "nodeId='" + nodeId + '\'' + ", view='" + view + '\'' + '}'; + } + } + + public static class BasicConsensusInfo { + private String nodeNum; + + @JsonProperty("node_index") + private String nodeIndex; + + @JsonProperty("node index") + private String raftNodeIndex; + + @JsonProperty("max_faulty_leader") + private String maxFaultyNodeNum; + + @JsonProperty("sealer.") + private List sealerList; + + private String consensusedBlockNumber; + private String highestblockNumber; + private String groupId; + private String protocolId; + private String accountType; + private String cfgErr; + private String omitEmptyBlock; + private String nodeId; + private String allowFutureBlocks; + private String connectedNodes; + private String currentView; + private String toView; + private String leaderFailed; + private String highestblockHash; + private String leaderId; + private String leaderIdx; + + public String getRaftNodeIndex() { + return raftNodeIndex; + } + + public void setRaftNodeIndex(String raftNodeIndex) { + this.raftNodeIndex = raftNodeIndex; + } + + public String getLeaderId() { + return leaderId; + } + + public void setLeaderId(String leaderId) { + this.leaderId = leaderId; + } + + public String getLeaderIdx() { + return leaderIdx; + } + + public void setLeaderIdx(String leaderIdx) { + this.leaderIdx = leaderIdx; + } + + public String getNodeIndex() { + return nodeIndex; + } + + public void setNodeIndex(String nodeIndex) { + this.nodeIndex = nodeIndex; + } + + public String getHighestblockHash() { + return highestblockHash; + } + + public void setHighestblockHash(String highestblockHash) { + this.highestblockHash = highestblockHash; + } + + public String getNodeNum() { + return nodeNum; + } + + public void setNodeNum(String nodeNum) { + this.nodeNum = nodeNum; + } + + public String getMaxFaultyNodeNum() { + return maxFaultyNodeNum; + } + + public void setMaxFaultyNodeNum(String maxFaultyNodeNum) { + this.maxFaultyNodeNum = maxFaultyNodeNum; + } + + public List getSealerList() { + return sealerList; + } + + public void setSealerList(List sealerList) { + this.sealerList = sealerList; + } + + public String getConsensusedBlockNumber() { + return consensusedBlockNumber; + } + + public void setConsensusedBlockNumber(String consensusedBlockNumber) { + this.consensusedBlockNumber = consensusedBlockNumber; + } + + public String getHighestblockNumber() { + return highestblockNumber; + } + + public void setHighestblockNumber(String highestblockNumber) { + this.highestblockNumber = highestblockNumber; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getProtocolId() { + return protocolId; + } + + public void setProtocolId(String protocolId) { + this.protocolId = protocolId; + } + + public String getAccountType() { + return accountType; + } + + public void setAccountType(String accountType) { + this.accountType = accountType; + } + + public String getCfgErr() { + return cfgErr; + } + + public void setCfgErr(String cfgErr) { + this.cfgErr = cfgErr; + } + + public String getOmitEmptyBlock() { + return omitEmptyBlock; + } + + public void setOmitEmptyBlock(String omitEmptyBlock) { + this.omitEmptyBlock = omitEmptyBlock; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getAllowFutureBlocks() { + return allowFutureBlocks; + } + + public void setAllowFutureBlocks(String allowFutureBlocks) { + this.allowFutureBlocks = allowFutureBlocks; + } + + public String getConnectedNodes() { + return connectedNodes; + } + + public void setConnectedNodes(String connectedNodes) { + this.connectedNodes = connectedNodes; + } + + public String getCurrentView() { + return currentView; + } + + public void setCurrentView(String currentView) { + this.currentView = currentView; + } + + public String getToView() { + return toView; + } + + public void setToView(String toView) { + this.toView = toView; + } + + public String getLeaderFailed() { + return leaderFailed; + } + + public void setLeaderFailed(String leaderFailed) { + this.leaderFailed = leaderFailed; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BasicConsensusInfo that = (BasicConsensusInfo) o; + return Objects.equals(nodeNum, that.nodeNum) + && Objects.equals(nodeIndex, that.nodeIndex) + && Objects.equals(maxFaultyNodeNum, that.maxFaultyNodeNum) + && Objects.equals(sealerList, that.sealerList) + && Objects.equals(consensusedBlockNumber, that.consensusedBlockNumber) + && Objects.equals(highestblockNumber, that.highestblockNumber) + && Objects.equals(groupId, that.groupId) + && Objects.equals(protocolId, that.protocolId) + && Objects.equals(accountType, that.accountType) + && Objects.equals(cfgErr, that.cfgErr) + && Objects.equals(omitEmptyBlock, that.omitEmptyBlock) + && Objects.equals(nodeId, that.nodeId) + && Objects.equals(allowFutureBlocks, that.allowFutureBlocks) + && Objects.equals(connectedNodes, that.connectedNodes) + && Objects.equals(currentView, that.currentView) + && Objects.equals(toView, that.toView) + && Objects.equals(leaderFailed, that.leaderFailed) + && Objects.equals(highestblockHash, that.highestblockHash); + } + + @Override + public int hashCode() { + return Objects.hash( + nodeNum, + nodeIndex, + maxFaultyNodeNum, + sealerList, + consensusedBlockNumber, + highestblockNumber, + groupId, + protocolId, + accountType, + cfgErr, + omitEmptyBlock, + nodeId, + allowFutureBlocks, + connectedNodes, + currentView, + toView, + leaderFailed, + highestblockHash); + } + + @Override + public String toString() { + return "BasicConsensusInfo{" + + "nodeNum='" + + nodeNum + + '\'' + + ", nodeIndex='" + + nodeIndex + + '\'' + + ", maxFaultyNodeNum='" + + maxFaultyNodeNum + + '\'' + + ", sealerList=" + + sealerList + + ", consensusedBlockNumber='" + + consensusedBlockNumber + + '\'' + + ", highestblockNumber='" + + highestblockNumber + + '\'' + + ", groupId='" + + groupId + + '\'' + + ", protocolId='" + + protocolId + + '\'' + + ", accountType='" + + accountType + + '\'' + + ", cfgErr='" + + cfgErr + + '\'' + + ", omitEmptyBlock='" + + omitEmptyBlock + + '\'' + + ", nodeId='" + + nodeId + + '\'' + + ", allowFutureBlocks='" + + allowFutureBlocks + + '\'' + + ", connectedNodes='" + + connectedNodes + + '\'' + + ", currentView='" + + currentView + + '\'' + + ", toView='" + + toView + + '\'' + + ", leaderFailed='" + + leaderFailed + + '\'' + + ", highestblockHash='" + + highestblockHash + + '\'' + + '}'; + } + } + + public static class ConsensusInfo { + private BasicConsensusInfo baseConsensusInfo; + private List viewInfos; + + public ConsensusInfo() {} + + public ConsensusInfo(BasicConsensusInfo baseConsensusInfo, List viewInfos) { + this.baseConsensusInfo = baseConsensusInfo; + this.viewInfos = viewInfos; + } + + public BasicConsensusInfo getBaseConsensusInfo() { + return baseConsensusInfo; + } + + public void setBaseConsensusInfo(BasicConsensusInfo baseConsensusInfo) { + this.baseConsensusInfo = baseConsensusInfo; + } + + public List getViewInfos() { + return viewInfos; + } + + public void setViewInfos(List viewInfos) { + this.viewInfos = viewInfos; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ConsensusInfo that = (ConsensusInfo) o; + return Objects.equals(baseConsensusInfo, that.baseConsensusInfo) + && Objects.equals(viewInfos, that.viewInfos); + } + + @Override + public int hashCode() { + return Objects.hash(baseConsensusInfo, viewInfos); + } + + @Override + public String toString() { + return "ConsensusInfo{" + + "baseConsensusInfo=" + + baseConsensusInfo + + ", viewInfos=" + + viewInfos + + '}'; + } + } + + public static class ConsensusStatusDeserializer extends JsonDeserializer { + private ObjectMapper objecMapper = ObjectMapperFactory.getObjectMapper(); + + @Override + public ConsensusInfo deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException { + JsonNode node = jsonParser.getCodec().readTree(jsonParser); + BasicConsensusInfo baseConsensusInfo = null; + List viewInfos = null; + if (node.size() > 0) { + baseConsensusInfo = + objecMapper.readValue(node.get(0).toString(), BasicConsensusInfo.class); + Integer sealersNum = Integer.valueOf(baseConsensusInfo.getNodeNum()); + baseConsensusInfo.setSealerList(new ArrayList(sealersNum)); + // parse sealerList + for (Integer i = 0; i < sealersNum; i++) { + String key = "sealer." + String.valueOf(i); + if (node.get(0).has(key)) { + baseConsensusInfo.getSealerList().add(i, node.get(0).get(key).asText()); + } + } + } + if (node.size() > 1) { + viewInfos = + objecMapper.readValue( + node.get(1).toString(), new TypeReference>() {}); + } + return new ConsensusInfo(baseConsensusInfo, viewInfos); + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GenerateGroup.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GenerateGroup.java index 928dea3c3..b80328daf 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GenerateGroup.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GenerateGroup.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class GenerateGroup extends JsonRpcResponse {} +import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; + +public class GenerateGroup extends JsonRpcResponse { + public GroupStatus getGroupStatus() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupList.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupList.java index dd482f691..1f7622d27 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupList.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupList.java @@ -15,5 +15,11 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.util.List; + /** getGroupList */ -public class GroupList extends JsonRpcResponse {} +public class GroupList extends JsonRpcResponse> { + public List getGroupList() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupPeers.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupPeers.java index 5be37f6cd..83385ddb9 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupPeers.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/GroupPeers.java @@ -15,5 +15,11 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.util.List; + /** getGroupPeers */ -public class GroupPeers extends JsonRpcResponse {} +public class GroupPeers extends JsonRpcResponse> { + public List getGroupPeers() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeIDList.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeIDList.java index f85510373..3225dd36d 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeIDList.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeIDList.java @@ -15,5 +15,11 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.util.List; + /** getNodeIDList */ -public class NodeIDList extends JsonRpcResponse {} +public class NodeIDList extends JsonRpcResponse> { + public List getNodeIDList() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeVersion.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeVersion.java index af1321734..5f017e940 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeVersion.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/NodeVersion.java @@ -15,5 +15,144 @@ package org.fisco.bcos.sdk.client.protocol.response; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Objects; + /** getNodeVersion. */ -public class NodeVersion extends JsonRpcResponse {} +public class NodeVersion extends JsonRpcResponse { + public ClientVersion getNodeVersion() { + return getResult(); + } + + public static class ClientVersion { + @JsonProperty("FISCO-BCOS Version") + private String version; + + @JsonProperty("Supported Version") + private String supportedVersion; + + @JsonProperty("Chain Id") + private String chainId; + + @JsonProperty("Build Time") + private String buildTime; + + @JsonProperty("Build Type") + private String buildType; + + @JsonProperty("Git Branch") + private String gitBranch; + + @JsonProperty("Git Commit Hash") + private String gitCommitHash; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getSupportedVersion() { + return supportedVersion; + } + + public void setSupportedVersion(String supportedVersion) { + this.supportedVersion = supportedVersion; + } + + public String getChainId() { + return chainId; + } + + public void setChainId(String chainId) { + this.chainId = chainId; + } + + public String getBuildTime() { + return buildTime; + } + + public void setBuildTime(String buildTime) { + this.buildTime = buildTime; + } + + public String getBuildType() { + return buildType; + } + + public void setBuildType(String buildType) { + this.buildType = buildType; + } + + public String getGitBranch() { + return gitBranch; + } + + public void setGitBranch(String gitBranch) { + this.gitBranch = gitBranch; + } + + public String getGitCommitHash() { + return gitCommitHash; + } + + public void setGitCommitHash(String gitCommitHash) { + this.gitCommitHash = gitCommitHash; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClientVersion that = (ClientVersion) o; + return Objects.equals(version, that.version) + && Objects.equals(supportedVersion, that.supportedVersion) + && Objects.equals(chainId, that.chainId) + && Objects.equals(buildTime, that.buildTime) + && Objects.equals(buildType, that.buildType) + && Objects.equals(gitBranch, that.gitBranch) + && Objects.equals(gitCommitHash, that.gitCommitHash); + } + + @Override + public int hashCode() { + return Objects.hash( + version, + supportedVersion, + chainId, + buildTime, + buildType, + gitBranch, + gitCommitHash); + } + + @Override + public String toString() { + return "ClientVersion{" + + "version='" + + version + + '\'' + + ", supportedVersion='" + + supportedVersion + + '\'' + + ", chainId='" + + chainId + + '\'' + + ", buildTime='" + + buildTime + + '\'' + + ", buildType='" + + buildType + + '\'' + + ", gitBranch='" + + gitBranch + + '\'' + + ", gitCommitHash='" + + gitCommitHash + + '\'' + + '}'; + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ObserverList.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ObserverList.java index 1ff3383fa..04f2ba158 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ObserverList.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/ObserverList.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class ObserverList extends JsonRpcResponse {} +import java.util.List; + +public class ObserverList extends JsonRpcResponse> { + public List getObserverList() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PbftView.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PbftView.java index b8f90b188..c70e1fa37 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PbftView.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PbftView.java @@ -15,5 +15,12 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.math.BigInteger; +import org.fisco.bcos.sdk.utils.Numeric; + /** getPbftView */ -public class PbftView extends JsonRpcResponse {} +public class PbftView extends JsonRpcResponse { + public BigInteger getPbftView() { + return Numeric.decodeQuantity(getResult()); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Peers.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Peers.java index a2a42f437..728413bd7 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Peers.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/Peers.java @@ -15,5 +15,107 @@ package org.fisco.bcos.sdk.client.protocol.response; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.Objects; + /** getPeers */ -public class Peers extends JsonRpcResponse {} +public class Peers extends JsonRpcResponse> { + public List getPeers() { + return getResult(); + } + + public static class PeerInfo { + @JsonProperty("NodeID") + private String nodeID; + + @JsonProperty("IPAndPort") + private String ipAndPort; + + @JsonProperty("Agency") + private String agency; + + @JsonProperty("Topic") + private List topic; + + @JsonProperty("Node") + private String node; + + public String getNode() { + return node; + } + + public void setNode(String node) { + this.node = node; + } + + public String getNodeID() { + return nodeID; + } + + public void setNodeID(String nodeID) { + this.nodeID = nodeID; + } + + public String getIpAndPort() { + return ipAndPort; + } + + public void setIpAndPort(String ipAndPort) { + this.ipAndPort = ipAndPort; + } + + public String getAgency() { + return agency; + } + + public void setAgency(String agency) { + this.agency = agency; + } + + public List getTopic() { + return topic; + } + + public void setTopic(List topic) { + this.topic = topic; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PeerInfo peerInfo = (PeerInfo) o; + return Objects.equals(nodeID, peerInfo.nodeID) + && Objects.equals(ipAndPort, peerInfo.ipAndPort) + && Objects.equals(agency, peerInfo.agency) + && Objects.equals(topic, peerInfo.topic) + && Objects.equals(node, peerInfo.node); + } + + @Override + public int hashCode() { + return Objects.hash(nodeID, ipAndPort, agency, topic, node); + } + + @Override + public String toString() { + return "PeerInfo{" + + "nodeID='" + + nodeID + + '\'' + + ", ipAndPort='" + + ipAndPort + + '\'' + + ", agency='" + + agency + + '\'' + + ", topic=" + + topic + + ", node='" + + node + + '\'' + + '}'; + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTransactions.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTransactions.java index 5b779b704..c8c4ded91 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTransactions.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTransactions.java @@ -15,5 +15,12 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.util.List; +import org.fisco.bcos.sdk.client.protocol.model.JsonTransactionResponse; + /** getPendingTransactions */ -public class PendingTransactions extends JsonRpcResponse {} +public class PendingTransactions extends JsonRpcResponse> { + public List getPendingTransactions() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTxSize.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTxSize.java index d392b0293..45b6af4fd 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTxSize.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/PendingTxSize.java @@ -15,5 +15,12 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.math.BigInteger; +import org.fisco.bcos.sdk.utils.Numeric; + /** getPendingTxSize */ -public class PendingTxSize extends JsonRpcResponse {} +public class PendingTxSize extends JsonRpcResponse { + public BigInteger getPendingTxSize() { + return Numeric.decodeQuantity(getResult()); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/QueryGroupStatus.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/QueryGroupStatus.java index 05c5b10aa..2184a0170 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/QueryGroupStatus.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/QueryGroupStatus.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class QueryGroupStatus extends JsonRpcResponse {} +import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; + +public class QueryGroupStatus extends JsonRpcResponse { + public GroupStatus getGroupStatus() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RecoverGroup.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RecoverGroup.java index 8057c7525..25d0e855e 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RecoverGroup.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RecoverGroup.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class RecoverGroup extends JsonRpcResponse {} +import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; + +public class RecoverGroup extends JsonRpcResponse { + public GroupStatus getGroupStatus() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RemoveGroup.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RemoveGroup.java index 2cd417266..3b88e07b6 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RemoveGroup.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/RemoveGroup.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class RemoveGroup extends JsonRpcResponse {} +import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; + +public class RemoveGroup extends JsonRpcResponse { + public GroupStatus getGroupStatus() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SealerList.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SealerList.java index 695afdc3b..a82a3db35 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SealerList.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SealerList.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class SealerList extends JsonRpcResponse {} +import java.util.List; + +public class SealerList extends JsonRpcResponse> { + public List getSealerList() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SendTransaction.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SendTransaction.java index c271aea5b..70b4a754f 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SendTransaction.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SendTransaction.java @@ -16,4 +16,8 @@ package org.fisco.bcos.sdk.client.protocol.response; /** Return data structure of send transaction */ -public class SendTransaction extends JsonRpcResponse {} +public class SendTransaction extends JsonRpcResponse { + public String getTransactionHash() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StartGroup.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StartGroup.java index a8bc944cb..13651b520 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StartGroup.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StartGroup.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class StartGroup extends JsonRpcResponse {} +import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; + +public class StartGroup extends JsonRpcResponse { + public GroupStatus getGroupStatus() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StopGroup.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StopGroup.java index 9c85f4f57..87a790ac8 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StopGroup.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/StopGroup.java @@ -15,4 +15,10 @@ package org.fisco.bcos.sdk.client.protocol.response; -public class StopGroup extends JsonRpcResponse {} +import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; + +public class StopGroup extends JsonRpcResponse { + public GroupStatus getGroupStatus() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SyncStatus.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SyncStatus.java index 341cd8606..68a48a9f5 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SyncStatus.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SyncStatus.java @@ -15,9 +15,249 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.util.List; +import java.util.Objects; + /** * getSyncStatus. * *

Returns an object with data about the sync status or false. */ -public class SyncStatus extends JsonRpcResponse {} +public class SyncStatus extends JsonRpcResponse { + public SyncStatus.SyncStatusInfo getSyncStatus() { + return getResult(); + } + + public static class PeersInfo { + private String nodeId; + private String genesisHash; + private String blockNumber; + private String latestHash; + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getGenesisHash() { + return genesisHash; + } + + public void setGenesisHash(String genesisHash) { + this.genesisHash = genesisHash; + } + + public String getBlockNumber() { + return blockNumber; + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public String getLatestHash() { + return latestHash; + } + + public void setLatestHash(String latestHash) { + this.latestHash = latestHash; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PeersInfo peersInfo = (PeersInfo) o; + return Objects.equals(nodeId, peersInfo.nodeId) + && Objects.equals(genesisHash, peersInfo.genesisHash) + && Objects.equals(blockNumber, peersInfo.blockNumber) + && Objects.equals(latestHash, peersInfo.latestHash); + } + + @Override + public int hashCode() { + return Objects.hash(nodeId, genesisHash, blockNumber, latestHash); + } + + @Override + public String toString() { + return "PeersInfo{" + + "nodeId='" + + nodeId + + '\'' + + ", genesisHash='" + + genesisHash + + '\'' + + ", blockNumber='" + + blockNumber + + '\'' + + ", latestHash='" + + latestHash + + '\'' + + '}'; + } + } + + public static class SyncStatusInfo { + private String isSyncing; + private String protocolId; + private String genesisHash; + private String nodeId; + private String blockNumber; + private String latestHash; + private String knownHighestNumber; + private String txPoolSize; + private List peers; + private String knownLatestHash; + + public String getKnownLatestHash() { + return knownLatestHash; + } + + public void setKnownLatestHash(String knownLatestHash) { + this.knownLatestHash = knownLatestHash; + } + + public String getIsSyncing() { + return isSyncing; + } + + public void setIsSyncing(String isSyncing) { + this.isSyncing = isSyncing; + } + + public String getProtocolId() { + return protocolId; + } + + public void setProtocolId(String protocolId) { + this.protocolId = protocolId; + } + + public String getGenesisHash() { + return genesisHash; + } + + public void setGenesisHash(String genesisHash) { + this.genesisHash = genesisHash; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getBlockNumber() { + return blockNumber; + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public String getLatestHash() { + return latestHash; + } + + public void setLatestHash(String latestHash) { + this.latestHash = latestHash; + } + + public String getKnownHighestNumber() { + return knownHighestNumber; + } + + public void setKnownHighestNumber(String knownHighestNumber) { + this.knownHighestNumber = knownHighestNumber; + } + + public String getTxPoolSize() { + return txPoolSize; + } + + public void setTxPoolSize(String txPoolSize) { + this.txPoolSize = txPoolSize; + } + + public List getPeers() { + return peers; + } + + public void setPeers(List peers) { + this.peers = peers; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SyncStatusInfo that = (SyncStatusInfo) o; + return Objects.equals(isSyncing, that.isSyncing) + && Objects.equals(protocolId, that.protocolId) + && Objects.equals(genesisHash, that.genesisHash) + && Objects.equals(nodeId, that.nodeId) + && Objects.equals(blockNumber, that.blockNumber) + && Objects.equals(latestHash, that.latestHash) + && Objects.equals(knownHighestNumber, that.knownHighestNumber) + && Objects.equals(txPoolSize, that.txPoolSize) + && Objects.equals(peers, that.peers) + && Objects.equals(knownLatestHash, that.knownLatestHash); + } + + @Override + public int hashCode() { + return Objects.hash( + isSyncing, + protocolId, + genesisHash, + nodeId, + blockNumber, + latestHash, + knownHighestNumber, + txPoolSize, + peers, + knownLatestHash); + } + + @Override + public String toString() { + return "SyncStatusInfo{" + + "isSyncing='" + + isSyncing + + '\'' + + ", protocolId='" + + protocolId + + '\'' + + ", genesisHash='" + + genesisHash + + '\'' + + ", nodeId='" + + nodeId + + '\'' + + ", blockNumber='" + + blockNumber + + '\'' + + ", latestHash='" + + latestHash + + '\'' + + ", knownHighestNumber='" + + knownHighestNumber + + '\'' + + ", txPoolSize='" + + txPoolSize + + '\'' + + ", peers=" + + peers + + ", knownLatestHash='" + + knownLatestHash + + '\'' + + '}'; + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SystemConfig.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SystemConfig.java index 1ae960609..abf9416d4 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SystemConfig.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/SystemConfig.java @@ -16,4 +16,8 @@ package org.fisco.bcos.sdk.client.protocol.response; /** getSystemConfigByKey */ -public class SystemConfig extends JsonRpcResponse {} +public class SystemConfig extends JsonRpcResponse { + public String getSystemConfig() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TotalTransactionCount.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TotalTransactionCount.java index 3574195b2..b89913172 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TotalTransactionCount.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TotalTransactionCount.java @@ -15,5 +15,72 @@ package org.fisco.bcos.sdk.client.protocol.response; +import java.util.Objects; + /** getTotalTransactionCount */ -public class TotalTransactionCount extends JsonRpcResponse {} +public class TotalTransactionCount + extends JsonRpcResponse { + public TransactionCountInfo getTotalTransactionCount() { + return getResult(); + } + + public static class TransactionCountInfo { + private String txSum; + private String blockNumber; + private String failedTxSum; + + public String getTxSum() { + return txSum; + } + + public void setTxSum(String txSum) { + this.txSum = txSum; + } + + public String getBlockNumber() { + return blockNumber; + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public String getFailedTxSum() { + return failedTxSum; + } + + public void setFailedTxSum(String failedTxSum) { + this.failedTxSum = failedTxSum; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TransactionCountInfo that = (TransactionCountInfo) o; + return Objects.equals(txSum, that.txSum) + && Objects.equals(blockNumber, that.blockNumber) + && Objects.equals(failedTxSum, that.failedTxSum); + } + + @Override + public int hashCode() { + return Objects.hash(txSum, blockNumber, failedTxSum); + } + + @Override + public String toString() { + return "TransactionCountInfo{" + + "txSum='" + + txSum + + '\'' + + ", blockNumber='" + + blockNumber + + '\'' + + ", failedTxSum='" + + failedTxSum + + '\'' + + '}'; + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java index dd9ca01b6..833806588 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java @@ -15,5 +15,64 @@ package org.fisco.bcos.sdk.client.protocol.response; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.Objects; +import org.fisco.bcos.sdk.client.protocol.model.MerkleProofUnit; +import org.fisco.bcos.sdk.client.protocol.model.TransactionReceipt; + /** getTransactionReceiptWithProof. */ -public class TransactionReceiptWithProof extends JsonRpcResponse {} +public class TransactionReceiptWithProof + extends JsonRpcResponse { + public ReceiptAndProof getTransactionReceiptWithProof() { + return getResult(); + } + + public static class ReceiptAndProof { + @JsonProperty("transactionReceipt") + private TransactionReceipt receipt; + + @JsonProperty("receiptProof") + private List receiptProof; + + public TransactionReceipt getReceipt() { + return receipt; + } + + public void setReceipt(TransactionReceipt receipt) { + this.receipt = receipt; + } + + public List getReceiptProof() { + return receiptProof; + } + + public void setReceiptProof(List receiptProof) { + this.receiptProof = receiptProof; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReceiptAndProof that = (ReceiptAndProof) o; + return Objects.equals(receipt, that.receipt) + && Objects.equals(receiptProof, that.receiptProof); + } + + @Override + public int hashCode() { + return Objects.hash(receipt, receiptProof); + } + + @Override + public String toString() { + return "ReceiptAndProof{" + + "receipt=" + + receipt + + ", receiptProof=" + + receiptProof + + '}'; + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java index 4a69c159c..29bc70728 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java @@ -15,5 +15,64 @@ package org.fisco.bcos.sdk.client.protocol.response; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.Objects; +import org.fisco.bcos.sdk.client.protocol.model.JsonTransactionResponse; +import org.fisco.bcos.sdk.client.protocol.model.MerkleProofUnit; + /** getTransactionWithProof. */ -public class TransactionWithProof extends JsonRpcResponse {} +public class TransactionWithProof + extends JsonRpcResponse { + public TransactionWithProof.TransactionAndProof getTransactionWithProof() { + return getResult(); + } + + public static class TransactionAndProof { + @JsonProperty("transaction") + private JsonTransactionResponse transaction; + + @JsonProperty("txProof") + private List transactionProof; + + public JsonTransactionResponse getTransaction() { + return transaction; + } + + public void setTransaction(JsonTransactionResponse transaction) { + this.transaction = transaction; + } + + public List getTransactionProof() { + return transactionProof; + } + + public void setTransactionProof(List transactionProof) { + this.transactionProof = transactionProof; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TransactionAndProof that = (TransactionAndProof) o; + return Objects.equals(transaction, that.transaction) + && Objects.equals(transactionProof, that.transactionProof); + } + + @Override + public int hashCode() { + return Objects.hash(transaction, transactionProof); + } + + @Override + public String toString() { + return "TransactionAndProof{" + + "transaction=" + + transaction + + ", transactionProof=" + + transactionProof + + '}'; + } + } +} diff --git a/src/test/java/org/fisco/bcos/sdk/test/client/ResponseTest.java b/src/test/java/org/fisco/bcos/sdk/test/client/ResponseTest.java index 0e56bd1b1..8a4378196 100644 --- a/src/test/java/org/fisco/bcos/sdk/test/client/ResponseTest.java +++ b/src/test/java/org/fisco/bcos/sdk/test/client/ResponseTest.java @@ -14,11 +14,44 @@ package org.fisco.bcos.sdk.test.client; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; +import org.fisco.bcos.sdk.client.protocol.response.BcosBlock; import org.fisco.bcos.sdk.client.protocol.response.BcosBlockHeader; +import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; +import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; +import org.fisco.bcos.sdk.client.protocol.response.BlockHash; +import org.fisco.bcos.sdk.client.protocol.response.BlockNumber; +import org.fisco.bcos.sdk.client.protocol.response.Call; +import org.fisco.bcos.sdk.client.protocol.response.Code; +import org.fisco.bcos.sdk.client.protocol.response.ConsensusStatus; +import org.fisco.bcos.sdk.client.protocol.response.GenerateGroup; +import org.fisco.bcos.sdk.client.protocol.response.GroupList; +import org.fisco.bcos.sdk.client.protocol.response.GroupPeers; +import org.fisco.bcos.sdk.client.protocol.response.NodeIDList; +import org.fisco.bcos.sdk.client.protocol.response.NodeVersion; +import org.fisco.bcos.sdk.client.protocol.response.ObserverList; +import org.fisco.bcos.sdk.client.protocol.response.PbftView; +import org.fisco.bcos.sdk.client.protocol.response.Peers; +import org.fisco.bcos.sdk.client.protocol.response.PendingTransactions; +import org.fisco.bcos.sdk.client.protocol.response.PendingTxSize; +import org.fisco.bcos.sdk.client.protocol.response.RecoverGroup; +import org.fisco.bcos.sdk.client.protocol.response.SealerList; +import org.fisco.bcos.sdk.client.protocol.response.SendTransaction; +import org.fisco.bcos.sdk.client.protocol.response.StartGroup; +import org.fisco.bcos.sdk.client.protocol.response.StopGroup; +import org.fisco.bcos.sdk.client.protocol.response.SyncStatus; +import org.fisco.bcos.sdk.client.protocol.response.SystemConfig; +import org.fisco.bcos.sdk.client.protocol.response.TotalTransactionCount; +import org.fisco.bcos.sdk.client.protocol.response.TransactionReceiptWithProof; +import org.fisco.bcos.sdk.client.protocol.response.TransactionWithProof; import org.fisco.bcos.sdk.utils.ObjectMapperFactory; import org.junit.Assert; import org.junit.Test; @@ -120,4 +153,1264 @@ public void testBlockHeaderResponse() { e.printStackTrace(); } } + + @Test + public void testTransacation() throws IOException { + String transactionString = + "{\n" + + " \"id\": 100,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"blockHash\": \"0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82\",\n" + + " \"blockNumber\": \"0x1001\",\n" + + " \"from\": \"0x2d6300a8f067872ebc87252d711b83a0c9325d35\",\n" + + " \"gas\": \"0x2faf080\",\n" + + " \"gasPrice\": \"0xa\",\n" + + " \"hash\": \"0x83ae369e15e1aafb18df7da2ff30de009bf53a1ff72ced3d1c342182409c4f87\",\n" + + " \"input\": \"0x4ed3885e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a464953434f2042434f5300000000000000000000000000000000000000000000\",\n" + + " \"nonce\": \"0x3eb675ec791c2d19858c91d0046821c27d815e2e9c151595296779000016038\",\n" + + " \"to\": \"0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744\",\n" + + " \"transactionIndex\": \"0x199\",\n" + + " \"value\": \"0x010\"\n" + + " }\n" + + "}"; + // decode the BcosTransaction object from the given string + BcosTransaction transaction = + objectMapper.readValue(transactionString.getBytes(), BcosTransaction.class); + Assert.assertEquals("2.0", transaction.getJsonrpc()); + Assert.assertEquals(100, transaction.getId()); + Assert.assertEquals(null, transaction.getError()); + Assert.assertEquals( + "0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82", + transaction.getTransaction().get().getBlockHash()); + Assert.assertEquals( + BigInteger.valueOf(0x1001), transaction.getTransaction().get().getBlockNumber()); + Assert.assertEquals( + "0x2d6300a8f067872ebc87252d711b83a0c9325d35", + transaction.getTransaction().get().getFrom()); + Assert.assertEquals("0x2faf080", transaction.getTransaction().get().getGas()); + Assert.assertEquals("0xa", transaction.getTransaction().get().getGasPrice()); + Assert.assertEquals( + "0x83ae369e15e1aafb18df7da2ff30de009bf53a1ff72ced3d1c342182409c4f87", + transaction.getTransaction().get().getHash()); + Assert.assertEquals( + "0x4ed3885e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a464953434f2042434f5300000000000000000000000000000000000000000000", + transaction.getTransaction().get().getInput()); + Assert.assertEquals( + "0x3eb675ec791c2d19858c91d0046821c27d815e2e9c151595296779000016038", + transaction.getTransaction().get().getNonce()); + Assert.assertEquals( + "0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744", + transaction.getTransaction().get().getTo()); + Assert.assertEquals("0x199", transaction.getTransaction().get().getTransactionIndex()); + Assert.assertEquals("0x010", transaction.getTransaction().get().getValue()); + + // encode the transaction + byte[] encodedData = objectMapper.writeValueAsBytes(transaction); + // decode the transaction + BcosTransaction decodedTransaction = + objectMapper.readValue(encodedData, BcosTransaction.class); + + // check `hashCode` and `equals` + Assert.assertEquals( + transaction.getTransaction().get(), decodedTransaction.getTransaction().get()); + Assert.assertEquals( + transaction.getTransaction().get().hashCode(), + decodedTransaction.getTransaction().get().hashCode()); + } + + @Test + public void testBcosBlockWithTransaction() throws IOException { + String blockString = + "{\n" + + " \"id\": 10001,\n" + + " \"jsonrpc\": \"3.0\",\n" + + " \"result\": {\n" + + " \"dbHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"extraData\": [],\n" + + " \"gasLimit\": \"0x0\",\n" + + " \"gasUsed\": \"0x0\",\n" + + " \"hash\": \"0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82\",\n" + + " \"logsBloom\": \"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"number\": \"0x100\",\n" + + " \"parentHash\": \"0x3d161a0302bb05d97d68e129c552a83f171e673d0b6b866c1f687c3da98d9a08\",\n" + + " \"receiptsRoot\": \"0x69a04fa6073e4fc0947bac7ee6990e788d1e2c5ec0fe6c2436d0892e7f3c09d2\",\n" + + " \"sealer\": \"0x4\",\n" + + " \"sealerList\": [\n" + + " \"11e1be251ca08bb44f36fdeedfaeca40894ff80dfd80084607a75509edeaf2a9c6fee914f1e9efda571611cf4575a1577957edfd2baa9386bd63eb034868625f\",\n" + + " \"b8acb51b9fe84f88d670646be36f31c52e67544ce56faf3dc8ea4cf1b0ebff0864c6b218fdcd9cf9891ebd414a995847911bd26a770f429300085f37e1131f36\"\n" + + " ],\n" + + " \"stateRoot\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"timestamp\": \"0x1736f190efb\",\n" + + " \"transactions\": [\n" + + " {\n" + + " \"blockHash\": \"0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82\",\n" + + " \"blockNumber\": \"0x100\",\n" + + " \"from\": \"0x2d6300a8f067872ebc87252d711b83a0c9325d35\",\n" + + " \"gas\": \"0x2faf080\",\n" + + " \"gasPrice\": \"0xa\",\n" + + " \"hash\": \"0x83ae369e15e1aafb18df7da2ff30de009bf53a1ff72ced3d1c342182409c4f87\",\n" + + " \"input\": \"0x4ed3885e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a464953434f2042434f5300000000000000000000000000000000000000000000\",\n" + + " \"nonce\": \"0x3eb675ec791c2d19858c91d0046821c27d815e2e9c151595296779000016038\",\n" + + " \"to\": \"0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744\",\n" + + " \"transactionIndex\": \"0x0\",\n" + + " \"value\": \"0x0\"\n" + + " }\n" + + " ],\n" + + " \"transactionsRoot\": \"0x9eec1be2effb2d7934928d4ccab1bd2886b920b1cf29f8744e3be1d253102cd7\"\n" + + " }\n" + + " }"; + // encode the string into object + BcosBlock bcosBlock = objectMapper.readValue(blockString.getBytes(), BcosBlock.class); + checkBlockHeader(bcosBlock); + // check the transaction + checkTransactionsForBlock(bcosBlock); + checkEncodeDecode(bcosBlock); + } + + public void testBcosBlockWithoutTransaction() throws IOException { + String blockString = + "{\n" + + " \"id\": 10001,\n" + + " \"jsonrpc\": \"3.0\",\n" + + " \"result\": {\n" + + " \"dbHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"extraData\": [],\n" + + " \"gasLimit\": \"0x0\",\n" + + " \"gasUsed\": \"0x0\",\n" + + " \"hash\": \"0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82\",\n" + + " \"logsBloom\": \"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"number\": \"0x100\",\n" + + " \"parentHash\": \"0x3d161a0302bb05d97d68e129c552a83f171e673d0b6b866c1f687c3da98d9a08\",\n" + + " \"receiptsRoot\": \"0x69a04fa6073e4fc0947bac7ee6990e788d1e2c5ec0fe6c2436d0892e7f3c09d2\",\n" + + " \"sealer\": \"0x4\",\n" + + " \"sealerList\": [\n" + + " \"11e1be251ca08bb44f36fdeedfaeca40894ff80dfd80084607a75509edeaf2a9c6fee914f1e9efda571611cf4575a1577957edfd2baa9386bd63eb034868625f\",\n" + + " \"b8acb51b9fe84f88d670646be36f31c52e67544ce56faf3dc8ea4cf1b0ebff0864c6b218fdcd9cf9891ebd414a995847911bd26a770f429300085f37e1131f36\"\n" + + " ],\n" + + " \"stateRoot\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"timestamp\": \"0x1736f190efb\",\n" + + " \"transactions\": [ \n" + + " \"0x19e5f919888038fcb16c7d75bb86945e1bf6349c591d33e3b5fdcda973577875\" \n" + + " ],\n" + + " \"transactionsRoot\": \"0x9eec1be2effb2d7934928d4ccab1bd2886b920b1cf29f8744e3be1d253102cd7\"\n" + + " }\n" + + " }"; + BcosBlock bcosBlock = objectMapper.readValue(blockString.getBytes(), BcosBlock.class); + checkBlockHeader(bcosBlock); + // check transaction + BcosBlock.TransactionHash transactionHash = + ((BcosBlock.TransactionHash) bcosBlock.getBlock().getTransactions().get(0)); + // check the transactionHash + Assert.assertEquals( + "0x19e5f919888038fcb16c7d75bb86945e1bf6349c591d33e3b5fdcda973577875", + transactionHash); + checkEncodeDecode(bcosBlock); + } + + private void checkEncodeDecode(BcosBlock bcosBlock) throws IOException { + // encode the block + byte[] encodedData = objectMapper.writeValueAsBytes(bcosBlock); + // decode the block + BcosBlock decodedBlock = objectMapper.readValue(encodedData, BcosBlock.class); + // check the block + Assert.assertEquals(bcosBlock.getBlock(), decodedBlock.getBlock()); + Assert.assertEquals(bcosBlock.getBlock().hashCode(), decodedBlock.getBlock().hashCode()); + } + + private void checkBlockHeader(BcosBlock bcosBlock) { + // check the BcosBlock object + Assert.assertEquals("3.0", bcosBlock.getJsonrpc()); + Assert.assertEquals(10001, bcosBlock.getId()); + Assert.assertEquals(BigInteger.valueOf(0x100), bcosBlock.getBlock().getNumber()); + Assert.assertEquals( + "0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82", + bcosBlock.getBlock().getHash()); + Assert.assertEquals( + "0x3d161a0302bb05d97d68e129c552a83f171e673d0b6b866c1f687c3da98d9a08", + bcosBlock.getBlock().getParentHash()); + Assert.assertEquals( + "0x69a04fa6073e4fc0947bac7ee6990e788d1e2c5ec0fe6c2436d0892e7f3c09d2", + bcosBlock.getBlock().getReceiptsRoot()); + Assert.assertEquals(2, bcosBlock.getBlock().getSealerList().size()); + Assert.assertEquals( + "11e1be251ca08bb44f36fdeedfaeca40894ff80dfd80084607a75509edeaf2a9c6fee914f1e9efda571611cf4575a1577957edfd2baa9386bd63eb034868625f", + bcosBlock.getBlock().getSealerList().get(0)); + Assert.assertEquals("0x4", bcosBlock.getBlock().getSealer()); + Assert.assertEquals("0x1736f190efb", bcosBlock.getBlock().getTimestamp()); + Assert.assertEquals(0, bcosBlock.getBlock().getExtraData().size()); + } + + private void checkTransactionsForBlock(BcosBlock bcosBlock) { + Assert.assertEquals(1, bcosBlock.getBlock().getTransactions().size()); + BcosBlock.TransactionObject transaction = + ((BcosBlock.TransactionObject) bcosBlock.getBlock().getTransactions().get(0)); + Assert.assertEquals( + "0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82", + transaction.getBlockHash()); + Assert.assertEquals(BigInteger.valueOf(0x100), transaction.getBlockNumber()); + Assert.assertEquals("0x2d6300a8f067872ebc87252d711b83a0c9325d35", transaction.getFrom()); + Assert.assertEquals("0x2faf080", transaction.getGas()); + Assert.assertEquals("0xa", transaction.getGasPrice()); + Assert.assertEquals( + "0x83ae369e15e1aafb18df7da2ff30de009bf53a1ff72ced3d1c342182409c4f87", + transaction.getHash()); + Assert.assertEquals( + "0x4ed3885e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a464953434f2042434f5300000000000000000000000000000000000000000000", + transaction.getInput()); + Assert.assertEquals( + "0x3eb675ec791c2d19858c91d0046821c27d815e2e9c151595296779000016038", + transaction.getNonce()); + Assert.assertEquals("0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744", transaction.getTo()); + Assert.assertEquals("0x0", transaction.getTransactionIndex()); + Assert.assertEquals("0x0", transaction.getValue()); + } + + @Test + public void testBlockHash() throws IOException { + // test BlockHash + String blockHashString = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": \"0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82\"\n" + + "}"; + BlockHash blockHash = objectMapper.readValue(blockHashString.getBytes(), BlockHash.class); + // check the blockHash + Assert.assertEquals( + "0xc558dd020df46dd3c2753dc8e1f85b79bf7849005dd4b84e3c8b5c1f6f642a82", + blockHash.getBlockHashByNumber()); + + // encode the blockHash + byte[] encodedData = objectMapper.writeValueAsBytes(blockHash); + BlockHash decodedBlockHash = objectMapper.readValue(encodedData, BlockHash.class); + Assert.assertEquals( + blockHash.getBlockHashByNumber(), decodedBlockHash.getBlockHashByNumber()); + Assert.assertEquals( + blockHash.getBlockHashByNumber().hashCode(), + decodedBlockHash.getBlockHashByNumber().hashCode()); + } + + @Test + public void testBlockNumber() throws IOException { + // test BlockNumber + String blockNumberString = + "{\n" + + " \"id\": 11,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": \"0x200\"\n" + + "}"; + BlockNumber blockNumber = + objectMapper.readValue(blockNumberString.getBytes(), BlockNumber.class); + Assert.assertEquals(BigInteger.valueOf(0x200), blockNumber.getBlockNumber()); + Assert.assertEquals("2.0", blockNumber.getJsonrpc()); + Assert.assertEquals(11, blockNumber.getId()); + + // encode the block number + byte[] encodedData = objectMapper.writeValueAsBytes(blockNumber); + BlockNumber decodedBlockNumber = objectMapper.readValue(encodedData, BlockNumber.class); + Assert.assertEquals(blockNumber.getBlockNumber(), decodedBlockNumber.getBlockNumber()); + Assert.assertEquals( + blockNumber.getBlockNumber().hashCode(), + decodedBlockNumber.getBlockNumber().hashCode()); + } + + @Test + public void testCall() throws IOException { + String callString = + "{\n" + + " \"id\": 102,\n" + + " \"jsonrpc\": \"3.0\",\n" + + " \"result\": {\n" + + " \"currentBlockNumber\": \"0xb\",\n" + + " \"output\": \"0x\",\n" + + " \"status\": \"0x0\"\n" + + " }\n" + + "}"; + Call callResult = objectMapper.readValue(callString.getBytes(), Call.class); + Assert.assertEquals("3.0", callResult.getJsonrpc()); + Assert.assertEquals(102, callResult.getId()); + // check callResult + Call.CallOutput callOutput = callResult.getCallResult(); + Assert.assertEquals(BigInteger.valueOf(0xb), callOutput.getCurrentBlockNumber()); + Assert.assertEquals("0x", callOutput.getOutput()); + Assert.assertEquals("0x0", callOutput.getStatus()); + + // encode the callResult + byte[] encodedData = objectMapper.writeValueAsBytes(callResult); + Call decodedCallResult = objectMapper.readValue(encodedData, Call.class); + Assert.assertEquals(callResult.getCallResult(), decodedCallResult.getCallResult()); + Assert.assertEquals( + callResult.getCallResult().hashCode(), + decodedCallResult.getCallResult().hashCode()); + } + + @Test + public void testGetCode() throws IOException { + String codeStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": \"0x60606040523415600b57fe5b5b60928061001a6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680636d4ce63c14603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b60004290505b905600a165627a7a723058203d9c292921247163d180a161baa8db840c9da6764cab1d23f1e11a5cff13c7910029\"\n" + + "}"; + Code code = objectMapper.readValue(codeStr.getBytes(), Code.class); + Assert.assertEquals("2.0", code.getJsonrpc()); + Assert.assertEquals(1, code.getId()); + // check result + Assert.assertEquals( + "0x60606040523415600b57fe5b5b60928061001a6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680636d4ce63c14603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b60004290505b905600a165627a7a723058203d9c292921247163d180a161baa8db840c9da6764cab1d23f1e11a5cff13c7910029", + code.getCode()); + // encode the code + byte[] encodedData = objectMapper.writeValueAsBytes(code); + Code decodedCode = objectMapper.readValue(encodedData, Code.class); + Assert.assertEquals(code.getCode(), decodedCode.getCode()); + Assert.assertEquals(code.getCode().hashCode(), decodedCode.getCode().hashCode()); + } + + @Test + public void testPBFTConsensusStatus() throws IOException { + String pbftConsensusStatusString = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " {\n" + + " \"accountType\": 1,\n" + + " \"allowFutureBlocks\": true,\n" + + " \"cfgErr\": false,\n" + + " \"connectedNodes\": 3,\n" + + " \"consensusedBlockNumber\": 38207,\n" + + " \"currentView\": 54477,\n" + + " \"groupId\": 1,\n" + + " \"highestblockHash\": \"0x19a16e8833e671aa11431de589c866a6442ca6c8548ba40a44f50889cd785069\",\n" + + " \"highestblockNumber\": 38206,\n" + + " \"leaderFailed\": false,\n" + + " \"max_faulty_leader\": 1,\n" + + " \"nodeId\": \"f72648fe165da17a889bece08ca0e57862cb979c4e3661d6a77bcc2de85cb766af5d299fec8a4337eedd142dca026abc2def632f6e456f80230902f93e2bea13\",\n" + + " \"nodeNum\": 4,\n" + + " \"node_index\": 3,\n" + + " \"omitEmptyBlock\": true,\n" + + " \"protocolId\": 65544,\n" + + " \"sealer.0\": \"6a99f357ecf8a001e03b68aba66f68398ee08f3ce0f0147e777ec77995369aac470b8c9f0f85f91ebb58a98475764b7ca1be8e37637dd6cb80b3355749636a3d\",\n" + + " \"sealer.1\": \"8a453f1328c80b908b2d02ba25adca6341b16b16846d84f903c4f4912728c6aae1050ce4f24cd9c13e010ce922d3393b846f6f5c42f6af59c65a814de733afe4\",\n" + + " \"sealer.2\": \"ed483837e73ee1b56073b178f5ac0896fa328fc0ed418ae3e268d9e9109721421ec48d68f28d6525642868b40dd26555c9148dbb8f4334ca071115925132889c\",\n" + + " \"sealer.3\": \"f72648fe165da17a889bece08ca0e57862cb979c4e3661d6a77bcc2de85cb766af5d299fec8a4337eedd142dca026abc2def632f6e456f80230902f93e2bea13\",\n" + + " \"toView\": 54477\n" + + " },\n" + + " [\n" + + " {\n" + + " \"nodeId\": \"6a99f357ecf8a001e03b68aba66f68398ee08f3ce0f0147e777ec77995369aac470b8c9f0f85f91ebb58a98475764b7ca1be8e37637dd6cb80b3355749636a3d\",\n" + + " \"view\": 54474\n" + + " },\n" + + " {\n" + + " \"nodeId\": \"8a453f1328c80b908b2d02ba25adca6341b16b16846d84f903c4f4912728c6aae1050ce4f24cd9c13e010ce922d3393b846f6f5c42f6af59c65a814de733afe4\",\n" + + " \"view\": 54475\n" + + " },\n" + + " {\n" + + " \"nodeId\": \"ed483837e73ee1b56073b178f5ac0896fa328fc0ed418ae3e268d9e9109721421ec48d68f28d6525642868b40dd26555c9148dbb8f4334ca071115925132889c\",\n" + + " \"view\": 54476\n" + + " },\n" + + " {\n" + + " \"nodeId\": \"f72648fe165da17a889bece08ca0e57862cb979c4e3661d6a77bcc2de85cb766af5d299fec8a4337eedd142dca026abc2def632f6e456f80230902f93e2bea13\",\n" + + " \"view\": 54477\n" + + " }\n" + + " ]\n" + + " ]\n" + + "}"; + ConsensusStatus status = + objectMapper.readValue(pbftConsensusStatusString.getBytes(), ConsensusStatus.class); + Assert.assertEquals("2.0", status.getJsonrpc()); + Assert.assertEquals(1, status.getId()); + ConsensusStatus.BasicConsensusInfo basicConsensusInfo = + status.getConsensusStatus().getBaseConsensusInfo(); + Assert.assertEquals( + "6a99f357ecf8a001e03b68aba66f68398ee08f3ce0f0147e777ec77995369aac470b8c9f0f85f91ebb58a98475764b7ca1be8e37637dd6cb80b3355749636a3d", + basicConsensusInfo.getSealerList().get(0).toString()); + Assert.assertEquals("1", basicConsensusInfo.getAccountType()); + Assert.assertEquals("4", basicConsensusInfo.getNodeNum()); + Assert.assertEquals(4, basicConsensusInfo.getSealerList().size()); + Assert.assertEquals( + "f72648fe165da17a889bece08ca0e57862cb979c4e3661d6a77bcc2de85cb766af5d299fec8a4337eedd142dca026abc2def632f6e456f80230902f93e2bea13", + basicConsensusInfo.getNodeId()); + Assert.assertEquals("54477", basicConsensusInfo.getCurrentView()); + Assert.assertEquals("1", basicConsensusInfo.getGroupId()); + Assert.assertEquals("38206", basicConsensusInfo.getHighestblockNumber()); + Assert.assertEquals( + "0x19a16e8833e671aa11431de589c866a6442ca6c8548ba40a44f50889cd785069", + basicConsensusInfo.getHighestblockHash()); + Assert.assertEquals("38206", basicConsensusInfo.getHighestblockNumber()); + Assert.assertEquals("false", basicConsensusInfo.getLeaderFailed()); + Assert.assertEquals("1", basicConsensusInfo.getMaxFaultyNodeNum()); + Assert.assertEquals("3", basicConsensusInfo.getNodeIndex()); + Assert.assertEquals("true", basicConsensusInfo.getOmitEmptyBlock()); + Assert.assertEquals("65544", basicConsensusInfo.getProtocolId()); + Assert.assertEquals("54477", basicConsensusInfo.getToView()); + + // check ViewInfo + List viewInfoList = status.getConsensusStatus().getViewInfos(); + Assert.assertEquals(4, viewInfoList.size()); + Assert.assertEquals( + "6a99f357ecf8a001e03b68aba66f68398ee08f3ce0f0147e777ec77995369aac470b8c9f0f85f91ebb58a98475764b7ca1be8e37637dd6cb80b3355749636a3d", + viewInfoList.get(0).getNodeId()); + Assert.assertEquals("54474", viewInfoList.get(0).getView()); + Assert.assertEquals("54475", viewInfoList.get(1).getView()); + Assert.assertEquals("54476", viewInfoList.get(2).getView()); + Assert.assertEquals("54477", viewInfoList.get(3).getView()); + + ConsensusStatus status2 = + objectMapper.readValue(pbftConsensusStatusString.getBytes(), ConsensusStatus.class); + Assert.assertEquals(status.getConsensusStatus(), status2.getConsensusStatus()); + Assert.assertEquals( + status.getConsensusStatus().hashCode(), status2.getConsensusStatus().hashCode()); + } + + @Test + public void testRaftConsensusStatus() throws IOException { + String raftConsenusStatus = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " {\n" + + " \"accountType\": 1,\n" + + " \"allowFutureBlocks\": true,\n" + + " \"cfgErr\": false,\n" + + " \"consensusedBlockNumber\": 1,\n" + + " \"groupId\": 1,\n" + + " \"highestblockHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"highestblockNumber\": 0,\n" + + " \"leaderId\": \"d5b3a9782c6aca271c9642aea391415d8b258e3a6d92082e59cc5b813ca123745440792ae0b29f4962df568f8ad58b75fc7cea495684988e26803c9c5198f3f8\",\n" + + " \"leaderIdx\": 3,\n" + + " \"max_faulty_leader\": 1,\n" + + " \"sealer.0\": \"29c34347a190c1ec0c4507c6eed6a5bcd4d7a8f9f54ef26da616e81185c0af11a8cea4eacb74cf6f61820292b24bc5d9e426af24beda06fbd71c217960c0dff0\",\n" + + " \"sealer.1\": \"41285429582cbfe6eed501806391d2825894b3696f801e945176c7eb2379a1ecf03b36b027d72f480e89d15bacd43462d87efd09fb0549e0897f850f9eca82ba\",\n" + + " \"sealer.2\": \"87774114e4a496c68f2482b30d221fa2f7b5278876da72f3d0a75695b81e2591c1939fc0d3fadb15cc359c997bafc9ea6fc37345346acaf40b6042b5831c97e1\",\n" + + " \"sealer.3\": \"d5b3a9782c6aca271c9642aea391415d8b258e3a6d92082e59cc5b813ca123745440792ae0b29f4962df568f8ad58b75fc7cea495684988e26803c9c5198f3f8\",\n" + + " \"node index\": 1,\n" + + " \"nodeId\": \"41285429582cbfe6eed501806391d2825894b3696f801e945176c7eb2379a1ecf03b36b027d72f480e89d15bacd43462d87efd09fb0549e0897f850f9eca82ba\",\n" + + " \"nodeNum\": 4,\n" + + " \"omitEmptyBlock\": true,\n" + + " \"protocolId\": 267\n" + + " }\n" + + " ]\n" + + "}"; + ConsensusStatus status = + objectMapper.readValue(raftConsenusStatus.getBytes(), ConsensusStatus.class); + ConsensusStatus.BasicConsensusInfo basicConsensusInfo = + status.getConsensusStatus().getBaseConsensusInfo(); + Assert.assertEquals("1", basicConsensusInfo.getAccountType()); + Assert.assertEquals("true", basicConsensusInfo.getAllowFutureBlocks()); + Assert.assertEquals( + "d5b3a9782c6aca271c9642aea391415d8b258e3a6d92082e59cc5b813ca123745440792ae0b29f4962df568f8ad58b75fc7cea495684988e26803c9c5198f3f8", + basicConsensusInfo.getLeaderId()); + Assert.assertEquals("3", basicConsensusInfo.getLeaderIdx()); + Assert.assertEquals("267", basicConsensusInfo.getProtocolId()); + Assert.assertEquals(4, basicConsensusInfo.getSealerList().size()); + Assert.assertEquals("1", basicConsensusInfo.getMaxFaultyNodeNum()); + Assert.assertEquals("1", basicConsensusInfo.getRaftNodeIndex()); + Assert.assertEquals(null, status.getConsensusStatus().getViewInfos()); + } + + @Test + public void testGroupStatus() throws IOException { + String groupStatusStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"code\": \"0x0\",\n" + + " \"message\": \"\",\n" + + " \"status\": \"STOPPED\"\n" + + " }\n" + + "}"; + // test generateGropu + GroupStatus groupStatus = + objectMapper + .readValue(groupStatusStr.getBytes(), GenerateGroup.class) + .getGroupStatus(); + checkGroupStatus(groupStatus, "0x0", "", "STOPPED"); + + groupStatus = + objectMapper + .readValue(groupStatusStr.getBytes(), StartGroup.class) + .getGroupStatus(); + checkGroupStatus(groupStatus, "0x0", "", "STOPPED"); + + groupStatus = + objectMapper.readValue(groupStatusStr.getBytes(), StopGroup.class).getGroupStatus(); + checkGroupStatus(groupStatus, "0x0", "", "STOPPED"); + + groupStatus = + objectMapper + .readValue(groupStatusStr.getBytes(), RecoverGroup.class) + .getGroupStatus(); + checkGroupStatus(groupStatus, "0x0", "", "STOPPED"); + } + + private void checkGroupStatus( + GroupStatus status, String expectedCode, String expectedMsg, String expectedStatus) + throws IOException { + Assert.assertEquals(expectedCode, status.getCode()); + Assert.assertEquals(expectedMsg, status.getMessage()); + Assert.assertEquals(expectedStatus, status.getStatus()); + + // check encode/decode + byte[] encodedData = objectMapper.writeValueAsBytes(status); + GroupStatus decodedStatus = objectMapper.readValue(encodedData, GroupStatus.class); + Assert.assertEquals(status, decodedStatus); + Assert.assertEquals(status.hashCode(), decodedStatus.hashCode()); + } + + @Test + public void testGroupList() throws IOException { + String groupListStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [1,2,3]\n" + + "}"; + GroupList groupList = objectMapper.readValue(groupListStr.getBytes(), GroupList.class); + Assert.assertEquals(3, groupList.getGroupList().size()); + List parsedGroupList = Arrays.asList("1", "2", "3"); + Assert.assertTrue(groupList.getGroupList().equals(parsedGroupList)); + + // encode + byte[] encodedBytes = objectMapper.writeValueAsBytes(groupList.getGroupList()); + List decodedGroupList = + objectMapper.readValue(encodedBytes, new TypeReference>() {}); + encodedBytes = objectMapper.writeValueAsBytes(decodedGroupList); + + Assert.assertEquals(groupList.getGroupList(), decodedGroupList); + Assert.assertEquals(groupList.getGroupList().hashCode(), decodedGroupList.hashCode()); + } + + @Test + public void testGroupPeers() throws IOException { + String groupPeersStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " \"0c0bbd25152d40969d3d3cee3431fa28287e07cff2330df3258782d3008b876d146ddab97eab42796495bfbb281591febc2a0069dcc7dfe88c8831801c5b5801\",\n" + + " \"037c255c06161711b6234b8c0960a6979ef039374ccc8b723afea2107cba3432dbbc837a714b7da20111f74d5a24e91925c773a72158fa066f586055379a1772\",\n" + + " \"622af37b2bd29c60ae8f15d467b67c0a7fe5eb3e5c63fdc27a0ee8066707a25afa3aa0eb5a3b802d3a8e5e26de9d5af33806664554241a3de9385d3b448bcd73\",\n" + + " \"10b3a2d4b775ec7f3c2c9e8dc97fa52beb8caab9c34d026db9b95a72ac1d1c1ad551c67c2b7fdc34177857eada75836e69016d1f356c676a6e8b15c45fc9bc34\"\n" + + " ]\n" + + "}"; + GroupPeers groupPeers = objectMapper.readValue(groupPeersStr.getBytes(), GroupPeers.class); + Assert.assertEquals(4, groupPeers.getGroupPeers().size()); + Assert.assertEquals( + "0c0bbd25152d40969d3d3cee3431fa28287e07cff2330df3258782d3008b876d146ddab97eab42796495bfbb281591febc2a0069dcc7dfe88c8831801c5b5801", + groupPeers.getGroupPeers().get(0)); + Assert.assertEquals( + "10b3a2d4b775ec7f3c2c9e8dc97fa52beb8caab9c34d026db9b95a72ac1d1c1ad551c67c2b7fdc34177857eada75836e69016d1f356c676a6e8b15c45fc9bc34", + groupPeers.getGroupPeers().get(3)); + } + + @Test + public void testNodeIDList() throws IOException { + String nodeIdListStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " \"0c0bbd25152d40969d3d3cee3431fa28287e07cff2330df3258782d3008b876d146ddab97eab42796495bfbb281591febc2a0069dcc7dfe88c8831801c5b5801\",\n" + + " \"037c255c06161711b6234b8c0960a6979ef039374ccc8b723afea2107cba3432dbbc837a714b7da20111f74d5a24e91925c773a72158fa066f586055379a1772\",\n" + + " \"622af37b2bd29c60ae8f15d467b67c0a7fe5eb3e5c63fdc27a0ee8066707a25afa3aa0eb5a3b802d3a8e5e26de9d5af33806664554241a3de9385d3b448bcd73\",\n" + + " \"10b3a2d4b775ec7f3c2c9e8dc97fa52beb8caab9c34d026db9b95a72ac1d1c1ad551c67c2b7fdc34177857eada75836e69016d1f356c676a6e8b15c45fc9bc34\"\n" + + " ]\n" + + "}"; + NodeIDList nodeIDList = objectMapper.readValue(nodeIdListStr.getBytes(), NodeIDList.class); + Assert.assertEquals(4, nodeIDList.getNodeIDList().size()); + Assert.assertEquals( + "0c0bbd25152d40969d3d3cee3431fa28287e07cff2330df3258782d3008b876d146ddab97eab42796495bfbb281591febc2a0069dcc7dfe88c8831801c5b5801", + nodeIDList.getNodeIDList().get(0)); + Assert.assertEquals( + "622af37b2bd29c60ae8f15d467b67c0a7fe5eb3e5c63fdc27a0ee8066707a25afa3aa0eb5a3b802d3a8e5e26de9d5af33806664554241a3de9385d3b448bcd73", + nodeIDList.getNodeIDList().get(2)); + } + + @Test + public void testNodeVersion() throws IOException { + String nodeVersionStr = + "{\n" + + " \"id\": 83,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"Build Time\": \"20190106 20:49:10\",\n" + + " \"Build Type\": \"Linux/g++/RelWithDebInfo\",\n" + + " \"FISCO-BCOS Version\": \"2.0.0\",\n" + + " \"Git Branch\": \"master\",\n" + + " \"Git Commit Hash\": \"693a709ddab39965d9c39da0104836cfb4a72054\"\n" + + " }\n" + + "}\n"; + NodeVersion nodeVersion = + objectMapper.readValue(nodeVersionStr.getBytes(), NodeVersion.class); + Assert.assertEquals("20190106 20:49:10", nodeVersion.getNodeVersion().getBuildTime()); + Assert.assertEquals( + "Linux/g++/RelWithDebInfo", nodeVersion.getNodeVersion().getBuildType()); + Assert.assertEquals("2.0.0", nodeVersion.getNodeVersion().getVersion()); + Assert.assertEquals("master", nodeVersion.getNodeVersion().getGitBranch()); + Assert.assertEquals( + "693a709ddab39965d9c39da0104836cfb4a72054", + nodeVersion.getNodeVersion().getGitCommitHash()); + } + + @Test + public void testObserverList() throws IOException { + String observerListStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " \"10b3a2d4b775ec7f3c2c9e8dc97fa52beb8caab9c34d026db9b95a72ac1d1c1ad551c67c2b7fdc34177857eada75836e69016d1f356c676a6e8b15c45fc9bc34\"\n" + + " ]\n" + + "}"; + + ObserverList observerList = + objectMapper.readValue(observerListStr.getBytes(), ObserverList.class); + Assert.assertEquals(1, observerList.getObserverList().size()); + Assert.assertEquals( + "10b3a2d4b775ec7f3c2c9e8dc97fa52beb8caab9c34d026db9b95a72ac1d1c1ad551c67c2b7fdc34177857eada75836e69016d1f356c676a6e8b15c45fc9bc34", + observerList.getObserverList().get(0)); + } + + @Test + public void testPbftView() throws IOException { + String pbftViewStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": \"0x1a0\"\n" + + "}"; + PbftView pbftView = objectMapper.readValue(pbftViewStr.getBytes(), PbftView.class); + Assert.assertEquals(BigInteger.valueOf(0x1a0), pbftView.getPbftView()); + } + + @Test + public void testPeers() throws IOException { + String peerStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " {\n" + + " \"Agency\": \"agency\",\n" + + " \"IPAndPort\": \"127.0.0.1:51869\",\n" + + " \"Node\": \"node2\",\n" + + " \"NodeID\": \"78a313b426c3de3267d72b53c044fa9fe70c2a27a00af7fea4a549a7d65210ed90512fc92b6194c14766366d434235c794289d66deff0796f15228e0e14a9191\",\n" + + " \"Topic\": []\n" + + " },\n" + + " {\n" + + " \"Agency\": \"agency\",\n" + + " \"IPAndPort\": \"127.0.0.1:30303\",\n" + + " \"Node\": \"node3\",\n" + + " \"NodeID\": \"95b7ff064f91de76598f90bc059bec1834f0d9eeb0d05e1086d49af1f9c2f321062d011ee8b0df7644bd54c4f9ca3d8515a3129bbb9d0df8287c9fa69552887e\",\n" + + " \"Topic\": []\n" + + " },\n" + + " {\n" + + " \"Agency\": \"agency\",\n" + + " \"IPAndPort\": \"127.0.0.1:30301\",\n" + + " \"Node\": \"node1\",\n" + + " \"NodeID\": \"11e1be251ca08bb44f36fdeedfaeca40894ff80dfd80084607a75509edeaf2a9c6fee914f1e9efda571611cf4575a1577957edfd2baa9386bd63eb034868625f\",\n" + + " \"Topic\": []\n" + + " }\n" + + " ]\n" + + "}"; + Peers peers = objectMapper.readValue(peerStr.getBytes(), Peers.class); + Assert.assertEquals(3, peers.getPeers().size()); + Assert.assertEquals("127.0.0.1:51869", peers.getPeers().get(0).getIpAndPort()); + Assert.assertEquals( + "95b7ff064f91de76598f90bc059bec1834f0d9eeb0d05e1086d49af1f9c2f321062d011ee8b0df7644bd54c4f9ca3d8515a3129bbb9d0df8287c9fa69552887e", + peers.getPeers().get(1).getNodeID()); + Assert.assertTrue(peers.getPeers().get(0).getTopic().isEmpty()); + Assert.assertEquals("node1", peers.getPeers().get(2).getNode()); + Assert.assertEquals("agency", peers.getPeers().get(2).getAgency()); + } + + @Test + public void testPendingTransactions() throws IOException { + String pendingListStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " {\n" + + " \"from\": \"0x6bc952a2e4db9c0c86a368d83e9df0c6ab481102\",\n" + + " \"gas\": \"0x9184e729fff\",\n" + + " \"gasPrice\": \"0x174876e7ff\",\n" + + " \"hash\": \"0x7536cf1286b5ce6c110cd4fea5c891467884240c9af366d678eb4191e1c31c6f\",\n" + + " \"input\": \"0x48f85bce000000000000000000000000000000000000000000000000000000000000001bf5bd8a9e7ba8b936ea704292ff4aaa5797bf671fdc8526dcd159f23c1f5a05f44e9fa862834dc7cb4541558f2b4961dc39eaaf0af7f7395028658d0e01b86a37\",\n" + + " \"nonce\": \"0x65f0d06e39dc3c08e32ac10a5070858962bc6c0f5760baca823f2d5582d03f\",\n" + + " \"to\": \"0xd6f1a71052366dbae2f7ab2d5d5845e77965cf0d\",\n" + + " \"value\": \"0x0\"\n" + + " }\n" + + " ]\n" + + "}"; + PendingTransactions pendingTransactions = + objectMapper.readValue(pendingListStr.getBytes(), PendingTransactions.class); + Assert.assertEquals(1, pendingTransactions.getPendingTransactions().size()); + Assert.assertEquals( + "0x7536cf1286b5ce6c110cd4fea5c891467884240c9af366d678eb4191e1c31c6f", + pendingTransactions.getPendingTransactions().get(0).getHash()); + Assert.assertEquals( + "0x48f85bce000000000000000000000000000000000000000000000000000000000000001bf5bd8a9e7ba8b936ea704292ff4aaa5797bf671fdc8526dcd159f23c1f5a05f44e9fa862834dc7cb4541558f2b4961dc39eaaf0af7f7395028658d0e01b86a37", + pendingTransactions.getPendingTransactions().get(0).getInput()); + Assert.assertEquals( + "0xd6f1a71052366dbae2f7ab2d5d5845e77965cf0d", + pendingTransactions.getPendingTransactions().get(0).getTo()); + Assert.assertEquals( + "0x6bc952a2e4db9c0c86a368d83e9df0c6ab481102", + pendingTransactions.getPendingTransactions().get(0).getFrom()); + } + + @Test + public void testPendingTxSize() throws IOException { + String pendingTxSizeStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": \"0x100\"\n" + + "}"; + PendingTxSize pendingTxSize = + objectMapper.readValue(pendingTxSizeStr.getBytes(), PendingTxSize.class); + Assert.assertEquals(BigInteger.valueOf(0x100), pendingTxSize.getPendingTxSize()); + } + + @Test + public void testSealerList() throws JsonProcessingException { + String sealerListStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": [\n" + + " \"037c255c06161711b6234b8c0960a6979ef039374ccc8b723afea2107cba3432dbbc837a714b7da20111f74d5a24e91925c773a72158fa066f586055379a1772\",\n" + + " \"0c0bbd25152d40969d3d3cee3431fa28287e07cff2330df3258782d3008b876d146ddab97eab42796495bfbb281591febc2a0069dcc7dfe88c8831801c5b5801\",\n" + + " \"622af37b2bd29c60ae8f15d467b67c0a7fe5eb3e5c63fdc27a0ee8066707a25afa3aa0eb5a3b802d3a8e5e26de9d5af33806664554241a3de9385d3b448bcd73\"\n" + + " ]\n" + + "}"; + SealerList sealerList = objectMapper.readValue(sealerListStr, SealerList.class); + Assert.assertEquals(3, sealerList.getSealerList().size()); + Assert.assertEquals( + "0c0bbd25152d40969d3d3cee3431fa28287e07cff2330df3258782d3008b876d146ddab97eab42796495bfbb281591febc2a0069dcc7dfe88c8831801c5b5801", + sealerList.getSealerList().get(1)); + Assert.assertEquals( + "037c255c06161711b6234b8c0960a6979ef039374ccc8b723afea2107cba3432dbbc837a714b7da20111f74d5a24e91925c773a72158fa066f586055379a1772", + sealerList.getSealerList().get(0)); + Assert.assertEquals( + "622af37b2bd29c60ae8f15d467b67c0a7fe5eb3e5c63fdc27a0ee8066707a25afa3aa0eb5a3b802d3a8e5e26de9d5af33806664554241a3de9385d3b448bcd73", + sealerList.getSealerList().get(2)); + } + + @Test + public void testSendTransaction() throws JsonProcessingException { + String sendRawTransactionStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": \"0x0accad4228274b0d78939f48149767883a6e99c95941baa950156e926f1c96ba\"\n" + + "}"; + SendTransaction sendTransaction = + objectMapper.readValue(sendRawTransactionStr, SendTransaction.class); + Assert.assertEquals( + "0x0accad4228274b0d78939f48149767883a6e99c95941baa950156e926f1c96ba", + sendTransaction.getTransactionHash()); + } + + @Test + public void testSyncStatus() throws JsonProcessingException { + String syncStatusStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"blockNumber\": 100,\n" + + " \"genesisHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"isSyncing\": false,\n" + + " \"knownHighestNumber\":0,\n" + + " \"knownLatestHash\":\"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"latestHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"nodeId\": \"41285429582cbfe6eed501806391d2825894b3696f801e945176c7eb2379a1ecf03b36b027d72f480e89d15bacd43462d87efd09fb0549e0897f850f9eca82ba\",\n" + + " \"peers\": [\n" + + " {\n" + + " \"blockNumber\": 0,\n" + + " \"genesisHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"latestHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"nodeId\": \"29c34347a190c1ec0c4507c6eed6a5bcd4d7a8f9f54ef26da616e81185c0af11a8cea4eacb74cf6f61820292b24bc5d9e426af24beda06fbd71c217960c0dff0\"\n" + + " },\n" + + " {\n" + + " \"blockNumber\": 0,\n" + + " \"genesisHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"latestHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"nodeId\": \"87774114e4a496c68f2482b30d221fa2f7b5278876da72f3d0a75695b81e2591c1939fc0d3fadb15cc359c997bafc9ea6fc37345346acaf40b6042b5831c97e1\"\n" + + " },\n" + + " {\n" + + " \"blockNumber\": 0,\n" + + " \"genesisHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"latestHash\": \"0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2\",\n" + + " \"nodeId\": \"d5b3a9782c6aca271c9642aea391415d8b258e3a6d92082e59cc5b813ca123745440792ae0b29f4962df568f8ad58b75fc7cea495684988e26803c9c5198f3f8\"\n" + + " }\n" + + " ],\n" + + " \"protocolId\": 265,\n" + + " \"txPoolSize\": \"0\"\n" + + " }\n" + + "}"; + SyncStatus syncStatus = objectMapper.readValue(syncStatusStr, SyncStatus.class); + Assert.assertEquals("100", syncStatus.getSyncStatus().getBlockNumber()); + Assert.assertEquals( + "0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2", + syncStatus.getSyncStatus().getGenesisHash()); + Assert.assertEquals("false", syncStatus.getSyncStatus().getIsSyncing()); + Assert.assertEquals("0", syncStatus.getSyncStatus().getKnownHighestNumber()); + Assert.assertEquals( + "0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2", + syncStatus.getSyncStatus().getKnownLatestHash()); + Assert.assertEquals( + "0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2", + syncStatus.getSyncStatus().getLatestHash()); + Assert.assertEquals( + "41285429582cbfe6eed501806391d2825894b3696f801e945176c7eb2379a1ecf03b36b027d72f480e89d15bacd43462d87efd09fb0549e0897f850f9eca82ba", + syncStatus.getSyncStatus().getNodeId()); + Assert.assertEquals("265", syncStatus.getSyncStatus().getProtocolId()); + Assert.assertEquals("0", syncStatus.getSyncStatus().getTxPoolSize()); + // check peers + Assert.assertEquals(3, syncStatus.getSyncStatus().getPeers().size()); + Assert.assertEquals("0", syncStatus.getSyncStatus().getPeers().get(2).getBlockNumber()); + Assert.assertEquals( + "0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2", + syncStatus.getSyncStatus().getPeers().get(2).getGenesisHash()); + Assert.assertEquals( + "0x4765a126a9de8d876b87f01119208be507ec28495bef09c1e30a8ab240cf00f2", + syncStatus.getSyncStatus().getPeers().get(2).getLatestHash()); + Assert.assertEquals( + "d5b3a9782c6aca271c9642aea391415d8b258e3a6d92082e59cc5b813ca123745440792ae0b29f4962df568f8ad58b75fc7cea495684988e26803c9c5198f3f8", + syncStatus.getSyncStatus().getPeers().get(2).getNodeId()); + } + + @Test + public void testSystemConfig() throws IOException { + String systemConfigStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": \"1000\"\n" + + "}"; + SystemConfig systemConfig = + objectMapper.readValue(systemConfigStr.getBytes(), SystemConfig.class); + Assert.assertEquals("1000", systemConfig.getSystemConfig().toString()); + } + + @Test + public void testTotalTransactionCount() throws JsonProcessingException { + String totalTxCountStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"blockNumber\": \"0x1\",\n" + + " \"failedTxSum\": \"0x0\",\n" + + " \"txSum\": \"0x20\"\n" + + " }\n" + + "}"; + TotalTransactionCount txCount = + objectMapper.readValue(totalTxCountStr, TotalTransactionCount.class); + Assert.assertEquals("0x1", txCount.getTotalTransactionCount().getBlockNumber()); + Assert.assertEquals("0x0", txCount.getTotalTransactionCount().getFailedTxSum()); + Assert.assertEquals("0x20", txCount.getTotalTransactionCount().getTxSum()); + } + + @Test + public void testTransactionReceipt() throws JsonProcessingException { + String receiptStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"blockHash\": \"0x977efec48c248ea4be87016446b40d7785d7b71b7d4e3aa0b103b9cf0f5fe19e\",\n" + + " \"blockNumber\": \"0xa\",\n" + + " \"contractAddress\": \"0x0000000000000000000000000000000000000000\",\n" + + " \"from\": \"0xcdcce60801c0a2e6bb534322c32ae528b9dec8d2\",\n" + + " \"gasUsed\": \"0x1fb8d\",\n" + + " \"input\": \"0xb602109a000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000203078313030303030303030303030303030303030303030303030303030303030000000000000000000000000000000000000000000000000000000000000000832303139303733300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002616100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026262000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"logs\": [ ],\n" + + " \"logsBloom\": \"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"output\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"root\":\"0x38723a2e5e8a17aa7950dc008209944e898f69a7bd10a23c839d341e935fd5ca\",\n" + + " \"status\": \"0xc\",\n" + + " \"to\": \"0x15538acd403ac1b2ff09083c70d04856b8c0bdfd\",\n" + + " \"transactionHash\": \"0x708b5781b62166bd86e543217be6cd954fd815fd192b9a124ee9327580df8f3f\",\n" + + " \"transactionIndex\": \"0x10\"\n" + + " }\n" + + "}"; + BcosTransactionReceipt transactionReceipt = + objectMapper.readValue(receiptStr, BcosTransactionReceipt.class); + Assert.assertEquals( + "0x977efec48c248ea4be87016446b40d7785d7b71b7d4e3aa0b103b9cf0f5fe19e", + transactionReceipt.getTransactionReceipt().get().getBlockHash()); + Assert.assertEquals( + "0xa", transactionReceipt.getTransactionReceipt().get().getBlockNumber()); + Assert.assertEquals( + "0x0000000000000000000000000000000000000000", + transactionReceipt.getTransactionReceipt().get().getContractAddress()); + Assert.assertEquals( + "0xcdcce60801c0a2e6bb534322c32ae528b9dec8d2", + transactionReceipt.getTransactionReceipt().get().getFrom()); + Assert.assertEquals( + "0x1fb8d", transactionReceipt.getTransactionReceipt().get().getGasUsed()); + Assert.assertEquals( + "0xb602109a000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000203078313030303030303030303030303030303030303030303030303030303030000000000000000000000000000000000000000000000000000000000000000832303139303733300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002616100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026262000000000000000000000000000000000000000000000000000000000000", + transactionReceipt.getTransactionReceipt().get().getInput()); + Assert.assertEquals(0, transactionReceipt.getTransactionReceipt().get().getLogs().size()); + Assert.assertEquals( + "0x0000000000000000000000000000000000000000000000000000000000000000", + transactionReceipt.getTransactionReceipt().get().getOutput()); + Assert.assertEquals( + "0x38723a2e5e8a17aa7950dc008209944e898f69a7bd10a23c839d341e935fd5ca", + transactionReceipt.getTransactionReceipt().get().getRoot()); + Assert.assertEquals("0xc", transactionReceipt.getTransactionReceipt().get().getStatus()); + Assert.assertEquals( + "0x15538acd403ac1b2ff09083c70d04856b8c0bdfd", + transactionReceipt.getTransactionReceipt().get().getTo()); + Assert.assertEquals( + "0x708b5781b62166bd86e543217be6cd954fd815fd192b9a124ee9327580df8f3f", + transactionReceipt.getTransactionReceipt().get().getTransactionHash()); + Assert.assertEquals( + "0x10", transactionReceipt.getTransactionReceipt().get().getTransactionIndex()); + } + + @Test + public void testTransactionReceiptWithProof() throws JsonProcessingException { + String receiptWithProofStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"receiptProof\": [\n" + + " {\n" + + " \"left\": [\n" + + " \"3088b5c8f9d92a3411a911f35ff0119a02e8f8f04852cf2fdfaa659843eac6a3ad\",\n" + + " \"31170ac8fd555dc50e59050841da0d96e4c4bc7e6266e1c6865c08c3b2391801dd\"\n" + + " ],\n" + + " \"right\": [\n" + + " \"33c572c8f961e0c56689d641fcf274916857819769a74e6424c58659bf530e90e3\",\n" + + " \"341233933ea3d357b4fdd6b3d1ed732dcff15cfd54e527c93c15a4e0238585ed11\",\n" + + " \"351e7ba09965cce1cfb820aced1d37204b06d96a21c5c2cf36850ffc62cf1fc84c\",\n" + + " \"361f65633d9ae843d4d3679b255fd448546a7b531c0056e8161ea0adbf1af12c0f\",\n" + + " \"37744f6e0d320314536b230d28b2fd6ac90b0111fb1e3bf4a750689abc282d8589\",\n" + + " \"386e60d9daa0be9825019fcf3d08cdaf51a90dc62a22a6e11371f94a8e516679cc\",\n" + + " \"391ef2f2cee81f3561a9900d5333af18f59aa3cd14e70241b5e86305ba697bf5f2\",\n" + + " \"3ac9999d4f36d76c95c61761879eb9ec60b964a489527f5af844398ffaa8617f0d\",\n" + + " \"3b0039ce903e275170640f3a464ce2e1adc2a7caee41267c195469365074032401\",\n" + + " \"3ca53017502028a0cb5bbf6c47c4779f365138da6910ffcfebf9591b45b89abd48\",\n" + + " \"3de04fc8766a344bb73d3fe6360c61d036e2eeedfd9ecdb86a0498d7849ed591f0\",\n" + + " \"3e2fc73ee22c4986111423dd20e8db317a313c9df29fa5aa3090f27097ecc4e1a9\",\n" + + " \"3fa7d31ad5c6e7bba3f99f9efc03ed8dd97cb1504003c34ad6bde5a662481f00a0\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"left\": [\n" + + " \"cd46118c0e99be585ffcf50423630348dbc486e54e9d9293a6a8754020a68a92\",\n" + + " \"3be78209b3e3c83af3668ec3192b5bf232531323ef66b66de80a11f386270132\",\n" + + " \"bd3a11d74a3fd79b1e1ea17e45b76eda4d25f6a5ec7fc5f067ea0d086b1ce70f\"\n" + + " ],\n" + + " \"right\": [\n" + + " \"6a6cefef8b48e455287a8c8694b06f4f7cb7950017ab048d6e6bdd8029f9f8c9\",\n" + + " \"0a27c5ee02e618d919d228e6a754dc201d299c91c9e4420a48783bb6fcd09be5\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"left\": [],\n" + + " \"right\": []\n" + + " }\n" + + " ],\n" + + " \"transactionReceipt\": {\n" + + " \"blockHash\": \"0xcd31b05e466bce99460b1ed70d6069fdfbb15e6eef84e9b9e4534358edb3899a\",\n" + + " \"blockNumber\": \"0x5\",\n" + + " \"contractAddress\": \"0x0000000000000000000000000000000000000000\",\n" + + " \"from\": \"0x148947262ec5e21739fe3a931c29e8b84ee34a0f\",\n" + + " \"gasUsed\": \"0x21dc1b\",\n" + + " \"input\": \"0x8a42ebe90000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000000a3564646636663863653800000000000000000000000000000000000000000000\",\n" + + " \"logs\": [],\n" + + " \"logsBloom\": \"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\n" + + " \"output\": \"0x\",\n" + + " \"root\": \"0xc3b4185963c78a4ca8eb90240e5cd95371d7217a9ce2bfa1149d53f79c73afbb\",\n" + + " \"status\": \"0x0\",\n" + + " \"to\": \"0xd6c8a04b8826b0a37c6d4aa0eaa8644d8e35b79f\",\n" + + " \"transactionHash\": \"0xd2c12e211315ef09dbad53407bc820d062780232841534954f9c23ab11d8ab4c\",\n" + + " \"transactionIndex\": \"0x32\"\n" + + " }\n" + + " }\n" + + "}"; + TransactionReceiptWithProof receiptWithProof = + objectMapper.readValue(receiptWithProofStr, TransactionReceiptWithProof.class); + Assert.assertEquals( + 3, receiptWithProof.getTransactionReceiptWithProof().getReceiptProof().size()); + Assert.assertEquals( + 2, + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(0) + .getLeft() + .size()); + Assert.assertEquals( + 13, + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(0) + .getRight() + .size()); + Assert.assertEquals( + 3, + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(1) + .getLeft() + .size()); + Assert.assertEquals( + 2, + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(1) + .getRight() + .size()); + Assert.assertEquals( + 0, + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(2) + .getLeft() + .size()); + Assert.assertEquals( + 0, + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(2) + .getRight() + .size()); + Assert.assertEquals( + "cd46118c0e99be585ffcf50423630348dbc486e54e9d9293a6a8754020a68a92", + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(1) + .getLeft() + .get(0)); + Assert.assertEquals( + "6a6cefef8b48e455287a8c8694b06f4f7cb7950017ab048d6e6bdd8029f9f8c9", + receiptWithProof + .getTransactionReceiptWithProof() + .getReceiptProof() + .get(1) + .getRight() + .get(0)); + // check receipt + Assert.assertEquals( + "0xcd31b05e466bce99460b1ed70d6069fdfbb15e6eef84e9b9e4534358edb3899a", + receiptWithProof.getTransactionReceiptWithProof().getReceipt().getBlockHash()); + Assert.assertEquals( + "0x5", + receiptWithProof.getTransactionReceiptWithProof().getReceipt().getBlockNumber()); + Assert.assertEquals( + "0x0000000000000000000000000000000000000000", + receiptWithProof + .getTransactionReceiptWithProof() + .getReceipt() + .getContractAddress()); + Assert.assertEquals( + "0x148947262ec5e21739fe3a931c29e8b84ee34a0f", + receiptWithProof.getTransactionReceiptWithProof().getReceipt().getFrom()); + Assert.assertEquals( + "0x21dc1b", + receiptWithProof.getTransactionReceiptWithProof().getReceipt().getGasUsed()); + Assert.assertEquals( + "0xc3b4185963c78a4ca8eb90240e5cd95371d7217a9ce2bfa1149d53f79c73afbb", + receiptWithProof.getTransactionReceiptWithProof().getReceipt().getRoot()); + Assert.assertEquals( + "0x0", receiptWithProof.getTransactionReceiptWithProof().getReceipt().getStatus()); + Assert.assertEquals( + "0xd6c8a04b8826b0a37c6d4aa0eaa8644d8e35b79f", + receiptWithProof.getTransactionReceiptWithProof().getReceipt().getTo()); + Assert.assertEquals( + null, receiptWithProof.getTransactionReceiptWithProof().getReceipt().getTxProof()); + Assert.assertEquals( + null, + receiptWithProof.getTransactionReceiptWithProof().getReceipt().getReceiptProof()); + } + + @Test + public void testTransactionWithProof() throws IOException { + String transactionWithProofStr = + "{\n" + + " \"id\": 1,\n" + + " \"jsonrpc\": \"2.0\",\n" + + " \"result\": {\n" + + " \"transaction\": {\n" + + " \"blockHash\": \"0xcd31b05e466bce99460b1ed70d6069fdfbb15e6eef84e9b9e4534358edb3899a\",\n" + + " \"blockNumber\": \"0x5\",\n" + + " \"from\": \"0x148947262ec5e21739fe3a931c29e8b84ee34a0f\",\n" + + " \"gas\": \"0x1c9c380\",\n" + + " \"gasPrice\": \"0x1c9c380\",\n" + + " \"hash\": \"0xd2c12e211315ef09dbad53407bc820d062780232841534954f9c23ab11d8ab4c\",\n" + + " \"input\": \"0x8a42ebe90000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000000a3564646636663863653800000000000000000000000000000000000000000000\",\n" + + " \"nonce\": \"0x208f6fd78d48aad370df51c6fdf866f8ab022de765c2959841ff2e81bfd9af9\",\n" + + " \"to\": \"0xd6c8a04b8826b0a37c6d4aa0eaa8644d8e35b79f\",\n" + + " \"transactionIndex\": \"0x32\",\n" + + " \"value\": \"0x0\"\n" + + " },\n" + + " \"txProof\": [\n" + + " {\n" + + " \"left\": [\n" + + " \"30f0abfcf4ca152815548620e33d21fd0feaa7c78867791c751e57cb5aa38248c2\",\n" + + " \"31a864156ca9841da8176738bb981d5da9102d9703746039b3e5407fa987e5183e\"\n" + + " ],\n" + + " \"right\": [\n" + + " \"33d8078d7e71df3544f8845a9db35aa35b2638e8468a321423152e64b9004367b4\",\n" + + " \"34343a4bce325ec8f6cf48517588830cd15f69b60a05598b78b03c3656d1fbf2f5\",\n" + + " \"35ac231554047ce77c0b31cd1c469f1f39ebe23404fa8ff6cc7819ad83e2c029e7\",\n" + + " \"361f6c588e650323e03afe6460dd89a9c061583e0d62c117ba64729d2c9d79317c\",\n" + + " \"377606f79f3e08b1ba3759eceada7fde3584f01822467855aa6356652f2499c738\",\n" + + " \"386722fe270659232c5572ba54ce23b474c85d8b709e7c08e85230afb1c155fe18\",\n" + + " \"39a9441d668e5e09a5619c365577c8c31365f44a984bde04300d4dbba190330c0b\",\n" + + " \"3a78a8c288120cbe612c24a33cce2731dd3a8fe6927d9ee25cb2350dba08a541f5\",\n" + + " \"3bd9b67256e201b5736f6081f39f83bcb917261144384570bdbb8766586c3bb417\",\n" + + " \"3c3158e5a82a1ac1ed41c4fd78d5be06bf79327f60b094895b886e7aae57cff375\",\n" + + " \"3de9a4d98c5ae658ffe764fbfa81edfdd4774e01b35ccb42beacb67064a5457863\",\n" + + " \"3e525e60c0f7eb935125f1156a692eb455ab4038c6b16390ce30937b0d1b314298\",\n" + + " \"3f1600afe67dec2d21582b8c7b76a15e569371d736d7bfc7a96c0327d280b91dfc\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"left\": [\n" + + " \"3577673b86ad4d594d86941d731f17d1515f4669483aed091d49f279d677cb19\",\n" + + " \"75603bfea5b44df4c41fbb99268364641896334f006af3a3f67edaa4b26477ca\",\n" + + " \"1339d43c526f0f34d8a0f4fb3bb47b716fdfde8d35697be5992e0888e4d794c9\"\n" + + " ],\n" + + " \"right\": [\n" + + " \"63c8e574fb2ef52e995427a8acaa72c27073dd8e37736add8dbf36be4f609ecb\",\n" + + " \"e65353d911d6cc8ead3fad53ab24cab69a1e31df8397517b124f578ba908558d\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"left\": [],\n" + + " \"right\": []\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; + TransactionWithProof transactionWithProof = + objectMapper.readValue( + transactionWithProofStr.getBytes(), TransactionWithProof.class); + Assert.assertEquals( + 3, transactionWithProof.getTransactionWithProof().getTransactionProof().size()); + Assert.assertEquals( + 2, + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(0) + .getLeft() + .size()); + Assert.assertEquals( + 13, + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(0) + .getRight() + .size()); + + Assert.assertEquals( + 3, + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(1) + .getLeft() + .size()); + Assert.assertEquals( + 2, + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(1) + .getRight() + .size()); + + Assert.assertEquals( + 0, + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(2) + .getLeft() + .size()); + Assert.assertEquals( + 0, + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(2) + .getRight() + .size()); + + Assert.assertEquals( + "3577673b86ad4d594d86941d731f17d1515f4669483aed091d49f279d677cb19", + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(1) + .getLeft() + .get(0)); + Assert.assertEquals( + "63c8e574fb2ef52e995427a8acaa72c27073dd8e37736add8dbf36be4f609ecb", + transactionWithProof + .getTransactionWithProof() + .getTransactionProof() + .get(1) + .getRight() + .get(0)); + + // check transaction + Assert.assertEquals( + "0xcd31b05e466bce99460b1ed70d6069fdfbb15e6eef84e9b9e4534358edb3899a", + transactionWithProof.getTransactionWithProof().getTransaction().getBlockHash()); + Assert.assertEquals( + BigInteger.valueOf(0x5), + transactionWithProof.getTransactionWithProof().getTransaction().getBlockNumber()); + Assert.assertEquals( + "0x148947262ec5e21739fe3a931c29e8b84ee34a0f", + transactionWithProof.getTransactionWithProof().getTransaction().getFrom()); + Assert.assertEquals( + "0x1c9c380", + transactionWithProof.getTransactionWithProof().getTransaction().getGas()); + Assert.assertEquals( + "0x1c9c380", + transactionWithProof.getTransactionWithProof().getTransaction().getGasPrice()); + Assert.assertEquals( + "0xd2c12e211315ef09dbad53407bc820d062780232841534954f9c23ab11d8ab4c", + transactionWithProof.getTransactionWithProof().getTransaction().getHash()); + Assert.assertEquals( + "0x8a42ebe90000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000000a3564646636663863653800000000000000000000000000000000000000000000", + transactionWithProof.getTransactionWithProof().getTransaction().getInput()); + Assert.assertEquals( + "0x208f6fd78d48aad370df51c6fdf866f8ab022de765c2959841ff2e81bfd9af9", + transactionWithProof.getTransactionWithProof().getTransaction().getNonce()); + Assert.assertEquals( + "0xd6c8a04b8826b0a37c6d4aa0eaa8644d8e35b79f", + transactionWithProof.getTransactionWithProof().getTransaction().getTo()); + Assert.assertEquals( + "0x32", + transactionWithProof + .getTransactionWithProof() + .getTransaction() + .getTransactionIndex()); + Assert.assertEquals( + "0x0", transactionWithProof.getTransactionWithProof().getTransaction().getValue()); + } }