diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionBuilder.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionBuilder.java index 4e07c532b..e899bad6d 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionBuilder.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionBuilder.java @@ -15,13 +15,13 @@ package org.fisco.bcos.sdk.transaction.core.impl.executor; import java.math.BigInteger; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; import org.fisco.bcos.sdk.transaction.core.interf.executor.TransactionBuilderInterface; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; public class TransactionBuilder implements TransactionBuilderInterface { @Override - public BcosTransaction createTransaction( + public RawTransaction createTransaction( BigInteger gasPrice, BigInteger gasLimit, String to, @@ -35,7 +35,7 @@ public BcosTransaction createTransaction( } @Override - public BcosTransaction createTransaction(String to, String data, BigInteger groupId) { + public RawTransaction createTransaction(String to, String data, BigInteger groupId) { // TODO Auto-generated method stub return null; } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java index 701b01b47..4298b5c0c 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java @@ -16,18 +16,18 @@ import java.util.List; import java.util.Map; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; import org.fisco.bcos.sdk.transaction.core.interf.executor.TransactionDecoderInterface; import org.fisco.bcos.sdk.transaction.domain.EventLog; import org.fisco.bcos.sdk.transaction.domain.EventResultEntity; import org.fisco.bcos.sdk.transaction.domain.InputAndOutputResult; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; +import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.TransactionResponse; public class TransactionDecoder implements TransactionDecoderInterface { @Override - public BcosTransaction decodeRlp(String hex) { + public RawTransaction decodeRlp(String hex) { // TODO Auto-generated method stub return null; } @@ -53,14 +53,14 @@ public InputAndOutputResult decodeOutputReturnObject( @Override public String decodeEventReturnJson( - String contractName, BcosTransactionReceipt transactionReceipt) { + String contractName, TransactionReceipt transactionReceipt) { // TODO Auto-generated method stub return null; } @Override public Map>> decodeEventReturnObject( - String contractName, BcosTransactionReceipt transactionReceipt) { + String contractName, TransactionReceipt transactionReceipt) { // TODO Auto-generated method stub return null; } @@ -100,7 +100,7 @@ public String decodeReceiptMessage(String input) { @Override public TransactionResponse decodeTransactionReceipt( - String contractName, BcosTransactionReceipt transactionReceipt) { + String contractName, TransactionReceipt transactionReceipt) { // TODO Auto-generated method stub return null; } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionEncoder.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionEncoder.java index b1f4cdbbe..04e0875bf 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionEncoder.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionEncoder.java @@ -14,14 +14,14 @@ */ package org.fisco.bcos.sdk.transaction.core.impl.executor; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; import org.fisco.bcos.sdk.crypto.signature.SignatureResult; import org.fisco.bcos.sdk.transaction.core.interf.executor.TransactionEncoderInterface; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; public class TransactionEncoder implements TransactionEncoderInterface { @Override - public byte[] encode(BcosTransaction transaction, SignatureResult signature) { + public byte[] encode(RawTransaction transaction, SignatureResult signature) { // TODO Auto-generated method stub return null; } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java index 4c598beb4..7ed7b3b29 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java @@ -16,9 +16,9 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; import org.fisco.bcos.sdk.client.protocol.response.Call; import org.fisco.bcos.sdk.transaction.core.interf.executor.TransactionPusherInterface; +import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; public class TransactionPusher implements TransactionPusherInterface { @@ -29,19 +29,19 @@ public void pushOnly(String signedTransaction) { } @Override - public BcosTransactionReceipt push(String signedTransaction) { + public TransactionReceipt push(String signedTransaction) { // TODO Auto-generated method stub return null; } @Override - public BcosTransactionReceipt push(String signedTransaction, RespCallback callback) { + public TransactionReceipt push(String signedTransaction, RespCallback callback) { // TODO Auto-generated method stub return null; } @Override - public CompletableFuture pushAsync(String signedTransaction) { + public CompletableFuture pushAsync(String signedTransaction) { // TODO Auto-generated method stub return null; } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionSigner.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionSigner.java index ae0d865c1..381f96f8c 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionSigner.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionSigner.java @@ -14,9 +14,9 @@ */ package org.fisco.bcos.sdk.transaction.core.impl.executor; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair; import org.fisco.bcos.sdk.transaction.core.interf.executor.TransactionSignerInterface; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; public class TransactionSigner implements TransactionSignerInterface { @@ -34,7 +34,7 @@ public TransactionSigner(int encryptType, CryptoKeyPair cryptoKeyPair) { } @Override - public byte[] sign(BcosTransaction bcosTransaction) { + public byte[] sign(RawTransaction rawTransaction) { // TODO Auto-generated method stub return null; } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionBuilderInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionBuilderInterface.java index d94afc1a8..aafc61db4 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionBuilderInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionBuilderInterface.java @@ -15,7 +15,7 @@ package org.fisco.bcos.sdk.transaction.core.interf.executor; import java.math.BigInteger; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; /** * TransactionBuilderInterface @Description: TransactionBuilderInterface @@ -25,7 +25,7 @@ */ public interface TransactionBuilderInterface { - public BcosTransaction createTransaction( + public RawTransaction createTransaction( BigInteger gasPrice, BigInteger gasLimit, String to, @@ -41,7 +41,7 @@ public BcosTransaction createTransaction( * @param to, target address * @param data, encoded data * @param groupId - * @return BcosTransaction + * @return RawTransaction */ - public BcosTransaction createTransaction(String to, String data, BigInteger groupId); + public RawTransaction createTransaction(String to, String data, BigInteger groupId); } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java index f2b448c7c..2ee6542ec 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java @@ -16,11 +16,11 @@ import java.util.List; import java.util.Map; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.EventLog; import org.fisco.bcos.sdk.transaction.domain.EventResultEntity; import org.fisco.bcos.sdk.transaction.domain.InputAndOutputResult; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; +import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.TransactionResponse; /** @@ -31,7 +31,7 @@ */ public interface TransactionDecoderInterface { - public BcosTransaction decodeRlp(String hex); + public RawTransaction decodeRlp(String hex); public String decodeCall(String abi, String output); @@ -40,11 +40,10 @@ public interface TransactionDecoderInterface { public InputAndOutputResult decodeOutputReturnObject( String contractName, String input, String output); - public String decodeEventReturnJson( - String contractName, BcosTransactionReceipt transactionReceipt); + public String decodeEventReturnJson(String contractName, TransactionReceipt transactionReceipt); public Map>> decodeEventReturnObject( - String contractName, BcosTransactionReceipt transactionReceipt); + String contractName, TransactionReceipt transactionReceipt); public String decodeEventReturnJson(String contractName, List logList); @@ -60,5 +59,5 @@ public Map>> decodeEventReturnObject( public String decodeReceiptMessage(String input); public TransactionResponse decodeTransactionReceipt( - String contractName, BcosTransactionReceipt transactionReceipt); + String contractName, TransactionReceipt transactionReceipt); } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionEncoderInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionEncoderInterface.java index 28dfeccee..638a79f97 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionEncoderInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionEncoderInterface.java @@ -14,8 +14,8 @@ */ package org.fisco.bcos.sdk.transaction.core.interf.executor; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; import org.fisco.bcos.sdk.crypto.signature.SignatureResult; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; /** * TransactionEncoderInterface @Description: TransactionEncoderInterface @@ -25,5 +25,5 @@ */ public interface TransactionEncoderInterface { - byte[] encode(BcosTransaction transaction, SignatureResult signature); + byte[] encode(RawTransaction transaction, SignatureResult signature); } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java index 8f53d38b0..3a093cd37 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java @@ -16,8 +16,8 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; import org.fisco.bcos.sdk.client.protocol.response.Call; +import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; /** * TransactionPusher @Description: TransactionPusherInterface @@ -29,11 +29,11 @@ public interface TransactionPusherInterface { public void pushOnly(String signedTransaction); - public BcosTransactionReceipt push(String signedTransaction); + public TransactionReceipt push(String signedTransaction); - public BcosTransactionReceipt push(String signedTransaction, RespCallback callback); + public TransactionReceipt push(String signedTransaction, RespCallback callback); - public CompletableFuture pushAsync(String signedTransaction); + public CompletableFuture pushAsync(String signedTransaction); public Call push(String from, String to, String encodedFunction); } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionSignerInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionSignerInterface.java index c9640c109..aedcd32a7 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionSignerInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionSignerInterface.java @@ -14,7 +14,7 @@ */ package org.fisco.bcos.sdk.transaction.core.interf.executor; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; +import org.fisco.bcos.sdk.transaction.domain.RawTransaction; /** * TransactionSignerInterface @Description: TransactionSignerInterface @@ -24,5 +24,5 @@ */ public interface TransactionSignerInterface { - byte[] sign(BcosTransaction bcosTransaction); + byte[] sign(RawTransaction rawTransaction); } diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/Log.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/Log.java new file mode 100644 index 000000000..82e76822e --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/transaction/domain/Log.java @@ -0,0 +1,265 @@ +/* + * 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.transaction.domain; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.math.BigInteger; +import java.util.List; +import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; +import org.fisco.bcos.sdk.utils.Numeric; + +/** + * Log object used by {@link BcosLog} and {@link BcosTransactionReceipt}. + * + *

It's not clear in the docs If only a list of + * hashes are returned for filters created with eth_newBlockFilter or + * eth_newPendingTransactionFilter. + */ +public class Log { + private boolean removed; + private String logIndex; + private String transactionIndex; + private String transactionHash; + private String blockHash; + private String blockNumber; + private String address; + private String data; + private String type; + private List topics; + + public Log() {} + + public Log( + boolean removed, + String logIndex, + String transactionIndex, + String transactionHash, + String blockHash, + String blockNumber, + String address, + String data, + String type, + List topics) { + this.removed = removed; + this.logIndex = logIndex; + this.transactionIndex = transactionIndex; + this.transactionHash = transactionHash; + this.blockHash = blockHash; + this.blockNumber = blockNumber; + this.address = address; + this.data = data; + this.type = type; + this.topics = topics; + } + + @JsonIgnore + public boolean isRemoved() { + return removed; + } + + public void setRemoved(boolean removed) { + this.removed = removed; + } + + public BigInteger getLogIndex() { + return convert(logIndex); + } + + @JsonIgnore + public String getLogIndexRaw() { + return logIndex; + } + + public void setLogIndex(String logIndex) { + this.logIndex = logIndex; + } + + public BigInteger getTransactionIndex() { + return convert(transactionIndex); + } + + @JsonIgnore + public String getTransactionIndexRaw() { + return transactionIndex; + } + + public void setTransactionIndex(String transactionIndex) { + this.transactionIndex = transactionIndex; + } + + public String getTransactionHash() { + return transactionHash; + } + + public void setTransactionHash(String transactionHash) { + this.transactionHash = transactionHash; + } + + public String getBlockHash() { + return blockHash; + } + + public void setBlockHash(String blockHash) { + this.blockHash = blockHash; + } + + public BigInteger getBlockNumber() { + return convert(blockNumber); + } + + @JsonIgnore + public String getBlockNumberRaw() { + return blockNumber; + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + @JsonIgnore + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getTopics() { + return topics; + } + + public void setTopics(List topics) { + this.topics = topics; + } + + private BigInteger convert(String value) { + if (value != null) { + return Numeric.decodeQuantity(value); + } else { + return null; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Log)) { + return false; + } + + Log log = (Log) o; + + if (isRemoved() != log.isRemoved()) { + return false; + } + if (getLogIndexRaw() != null + ? !getLogIndexRaw().equals(log.getLogIndexRaw()) + : log.getLogIndexRaw() != null) { + return false; + } + if (getTransactionIndexRaw() != null + ? !getTransactionIndexRaw().equals(log.getTransactionIndexRaw()) + : log.getTransactionIndexRaw() != null) { + return false; + } + if (getTransactionHash() != null + ? !getTransactionHash().equals(log.getTransactionHash()) + : log.getTransactionHash() != null) { + return false; + } + if (getBlockHash() != null + ? !getBlockHash().equals(log.getBlockHash()) + : log.getBlockHash() != null) { + return false; + } + if (getBlockNumberRaw() != null + ? !getBlockNumberRaw().equals(log.getBlockNumberRaw()) + : log.getBlockNumberRaw() != null) { + return false; + } + if (getAddress() != null + ? !getAddress().equals(log.getAddress()) + : log.getAddress() != null) { + return false; + } + if (getData() != null ? !getData().equals(log.getData()) : log.getData() != null) { + return false; + } + if (getType() != null ? !getType().equals(log.getType()) : log.getType() != null) { + return false; + } + return getTopics() != null ? getTopics().equals(log.getTopics()) : log.getTopics() == null; + } + + @Override + public int hashCode() { + int result = (isRemoved() ? 1 : 0); + result = 31 * result + (getLogIndexRaw() != null ? getLogIndexRaw().hashCode() : 0); + result = + 31 * result + + (getTransactionIndexRaw() != null + ? getTransactionIndexRaw().hashCode() + : 0); + result = 31 * result + (getTransactionHash() != null ? getTransactionHash().hashCode() : 0); + result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0); + result = 31 * result + (getBlockNumberRaw() != null ? getBlockNumberRaw().hashCode() : 0); + result = 31 * result + (getAddress() != null ? getAddress().hashCode() : 0); + result = 31 * result + (getData() != null ? getData().hashCode() : 0); + result = 31 * result + (getType() != null ? getType().hashCode() : 0); + result = 31 * result + (getTopics() != null ? getTopics().hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Log [logIndex=" + + logIndex + + ", transactionIndex=" + + transactionIndex + + ", transactionHash=" + + transactionHash + + ", blockHash=" + + blockHash + + ", blockNumber=" + + blockNumber + + ", address=" + + address + + ", data=" + + data + + ", topics=" + + topics + + "]"; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/MerkleProofUnit.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/MerkleProofUnit.java new file mode 100644 index 000000000..13fdd48dd --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/transaction/domain/MerkleProofUnit.java @@ -0,0 +1,75 @@ +/* + * 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.transaction.domain; + +import java.util.List; +import java.util.Objects; +import org.fisco.bcos.sdk.client.protocol.response.TransactionReceiptWithProof; +import org.fisco.bcos.sdk.client.protocol.response.TransactionWithProof; + +/** + * MerkleProofUnit object used by both {@link TransactionReceiptWithProof} and {@link + * TransactionWithProof}. + */ +public class MerkleProofUnit { + private List left; + private List right; + + public MerkleProofUnit() {} + + public MerkleProofUnit(List left, List right) { + this.left = left; + this.right = 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 instanceof MerkleProofUnit)) { + return false; + } + MerkleProofUnit that = (MerkleProofUnit) o; + return Objects.equals(getLeft(), that.getLeft()) + && Objects.equals(getRight(), that.getRight()); + } + + @Override + public int hashCode() { + return Objects.hash(getLeft(), getRight()); + } + + @Override + public String toString() { + return "MerkleProofUnit{" + "left=" + left + ", right=" + right + '}'; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/RawTransaction.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/RawTransaction.java new file mode 100644 index 000000000..8c9cfccf5 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/transaction/domain/RawTransaction.java @@ -0,0 +1,158 @@ +package org.fisco.bcos.sdk.transaction.domain; + +import java.io.Serializable; +import java.math.BigInteger; +import org.fisco.bcos.sdk.utils.Numeric; + +/** + * Transaction class used for signing transactions locally.
+ * For the specification, refer to p4 of the yellow + * paper. + */ +public class RawTransaction implements Serializable { + + private static final long serialVersionUID = -5580814755985097996L; + private BigInteger randomid; + private BigInteger gasPrice; + private BigInteger gasLimit; + private BigInteger blockLimit; + private String to; + private BigInteger value; + private String data; + private BigInteger fiscoChainId; + private BigInteger groupId; + private String extraData; + // private BigInteger version = TransactionConstant.version; + // TODO + private BigInteger version; + + protected RawTransaction( + BigInteger randomid, + BigInteger gasPrice, + BigInteger gasLimit, + BigInteger blockLimit, + String to, + BigInteger value, + String data, + BigInteger fiscoChainId, + BigInteger groupId, + String extraData) { + this.randomid = randomid; + this.gasPrice = gasPrice; + this.gasLimit = gasLimit; + this.blockLimit = blockLimit; + this.fiscoChainId = fiscoChainId; + this.groupId = groupId; + this.extraData = extraData; + this.to = to; + this.value = value; + if (data != null) { + this.data = Numeric.cleanHexPrefix(data); + } + } + + public static RawTransaction createContractTransaction( + BigInteger randomid, + BigInteger gasPrice, + BigInteger gasLimit, + BigInteger blockLimit, + BigInteger value, + String init, + BigInteger chainId, + BigInteger groupId, + String extraData) { + + return new RawTransaction( + randomid, + gasPrice, + gasLimit, + blockLimit, + "", + value, + init, + chainId, + groupId, + extraData); + } + + public static RawTransaction createTransaction( + BigInteger randomid, + BigInteger gasPrice, + BigInteger gasLimit, + BigInteger blockLimit, + String to, + BigInteger value, + String data, + BigInteger chainId, + BigInteger groupId, + String extraData) { + + return new RawTransaction( + randomid, + gasPrice, + gasLimit, + blockLimit, + to, + value, + data, + chainId, + groupId, + extraData); + } + + public BigInteger getRandomid() { + return randomid; + } + + public BigInteger getGasPrice() { + return gasPrice; + } + + public BigInteger getGasLimit() { + return gasLimit; + } + + public BigInteger getBlockLimit() { + return blockLimit; + } + + public String getTo() { + return to; + } + + public BigInteger getValue() { + return value; + } + + public String getData() { + return data; + } + + public BigInteger getVersion() { + return version; + } + + public BigInteger getGroupId() { + return groupId; + } + + public void setGroupId(BigInteger groupId) { + this.groupId = groupId; + } + + public String getExtraData() { + return extraData; + } + + public void setExtraData(String extraData) { + this.extraData = extraData; + } + + public BigInteger getFiscoChainId() { + return fiscoChainId; + } + + public void setFiscoChainId(BigInteger fiscoChainId) { + this.fiscoChainId = fiscoChainId; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/TransactionReceipt.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/TransactionReceipt.java new file mode 100644 index 000000000..59c8c73c5 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/transaction/domain/TransactionReceipt.java @@ -0,0 +1,386 @@ +/* + * 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.transaction.domain; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.math.BigInteger; +import java.util.List; +import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; +import org.fisco.bcos.sdk.utils.Numeric; + +/** TransactionReceipt object used by {@link BcosTransactionReceipt}. */ +public class TransactionReceipt { + private String transactionHash; + private String transactionIndex; + private String blockHash; + private String blockNumber; + private String gasUsed; + private String contractAddress; + private String root; + // status is only present on Byzantium transactions onwards + // see EIP 658 https://github.com/ethereum/EIPs/pull/658 + private String status; + private String message; + private String from; + private String to; + private String input; + private String output; + private List logs; + private String logsBloom; + private List txProof; + private List receiptProof; + + public TransactionReceipt() {} + + public TransactionReceipt( + String transactionHash, + String transactionIndex, + String blockHash, + String blockNumber, + String gasUsed, + String contractAddress, + String root, + String status, + String message, + String from, + String to, + String input, + String output, + List logs, + String logsBloom) { + this.transactionHash = transactionHash; + this.transactionIndex = transactionIndex; + this.blockHash = blockHash; + this.blockNumber = blockNumber; + this.gasUsed = gasUsed; + this.contractAddress = contractAddress; + this.root = root; + this.status = status; + this.message = message; + this.from = from; + this.to = to; + this.input = input; + this.output = output; + this.logs = logs; + this.logsBloom = logsBloom; + } + + public String getTransactionHash() { + return transactionHash; + } + + public void setTransactionHash(String transactionHash) { + this.transactionHash = transactionHash; + } + + public BigInteger getTransactionIndex() { + return Numeric.decodeQuantity(transactionIndex); + } + + @JsonIgnore + public String getTransactionIndexRaw() { + return transactionIndex; + } + + public void setTransactionIndex(String transactionIndex) { + this.transactionIndex = transactionIndex; + } + + public String getBlockHash() { + return blockHash; + } + + public void setBlockHash(String blockHash) { + this.blockHash = blockHash; + } + + public BigInteger getBlockNumber() { + return Numeric.decodeQuantity(blockNumber); + } + + @JsonIgnore + public String getBlockNumberRaw() { + return blockNumber; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public BigInteger getGasUsed() { + return Numeric.decodeQuantity(gasUsed); + } + + @JsonIgnore + public String getGasUsedRaw() { + return gasUsed; + } + + public void setGasUsed(String gasUsed) { + this.gasUsed = gasUsed; + } + + public String getContractAddress() { + return contractAddress; + } + + public void setContractAddress(String contractAddress) { + this.contractAddress = contractAddress; + } + + public String getRoot() { + return root; + } + + public void setRoot(String root) { + this.root = root; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @JsonIgnore + public boolean isStatusOK() { + if (null == status) { + return true; + } + + try { + BigInteger statusQuantity = Numeric.decodeQuantity(status); + return BigInteger.ZERO.equals(statusQuantity); + } catch (Exception e) { + return false; + } + } + + 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 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 List getTxProof() { + return txProof; + } + + public void setTxProof(List txProof) { + this.txProof = txProof; + } + + 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 instanceof TransactionReceipt)) { + return false; + } + + TransactionReceipt that = (TransactionReceipt) o; + + if (getTransactionHash() != null + ? !getTransactionHash().equals(that.getTransactionHash()) + : that.getTransactionHash() != null) { + return false; + } + if (transactionIndex != null + ? !transactionIndex.equals(that.transactionIndex) + : that.transactionIndex != null) { + return false; + } + if (getBlockHash() != null + ? !getBlockHash().equals(that.getBlockHash()) + : that.getBlockHash() != null) { + return false; + } + if (blockNumber != null + ? !blockNumber.equals(that.blockNumber) + : that.blockNumber != null) { + return false; + } + if (gasUsed != null ? !gasUsed.equals(that.gasUsed) : that.gasUsed != null) { + return false; + } + if (getContractAddress() != null + ? !getContractAddress().equals(that.getContractAddress()) + : that.getContractAddress() != null) { + return false; + } + if (getRoot() != null ? !getRoot().equals(that.getRoot()) : that.getRoot() != null) { + return false; + } + if (getStatus() != null + ? !getStatus().equals(that.getStatus()) + : that.getStatus() != null) { + return false; + } + if (getFrom() != null ? !getFrom().equals(that.getFrom()) : that.getFrom() != null) { + return false; + } + if (getTo() != null ? !getTo().equals(that.getTo()) : that.getTo() != null) { + return false; + } + if (getLogs() != null ? !getLogs().equals(that.getLogs()) : that.getLogs() != null) { + return false; + } + if (getOutput() != null + ? !getOutput().equals(that.getOutput()) + : that.getOutput() != null) { + return false; + } + if (getInput() != null ? !getInput().equals(that.getInput()) : that.getInput() != null) { + return false; + } + return getLogsBloom() != null + ? getLogsBloom().equals(that.getLogsBloom()) + : that.getLogsBloom() == null; + } + + @Override + public int hashCode() { + int result = getTransactionHash() != null ? getTransactionHash().hashCode() : 0; + result = 31 * result + (transactionIndex != null ? transactionIndex.hashCode() : 0); + result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0); + result = 31 * result + (blockNumber != null ? blockNumber.hashCode() : 0); + result = 31 * result + (gasUsed != null ? gasUsed.hashCode() : 0); + result = 31 * result + (getContractAddress() != null ? getContractAddress().hashCode() : 0); + result = 31 * result + (getRoot() != null ? getRoot().hashCode() : 0); + result = 31 * result + (getStatus() != null ? getStatus().hashCode() : 0); + result = 31 * result + (getFrom() != null ? getFrom().hashCode() : 0); + result = 31 * result + (getTo() != null ? getTo().hashCode() : 0); + result = 31 * result + (getOutput() != null ? getOutput().hashCode() : 0); + result = 31 * result + (getInput() != null ? getInput().hashCode() : 0); + result = 31 * result + (getLogs() != null ? getLogs().hashCode() : 0); + result = 31 * result + (getLogsBloom() != null ? getLogsBloom().hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "TransactionReceipt{" + + "transactionHash='" + + transactionHash + + '\'' + + ", transactionIndex='" + + transactionIndex + + '\'' + + ", blockHash='" + + blockHash + + '\'' + + ", blockNumber='" + + blockNumber + + '\'' + + ", gasUsed='" + + gasUsed + + '\'' + + ", contractAddress='" + + contractAddress + + '\'' + + ", root='" + + root + + '\'' + + ", status='" + + status + + '\'' + + ", message='" + + message + + '\'' + + ", from='" + + from + + '\'' + + ", to='" + + to + + '\'' + + ", input='" + + input + + '\'' + + ", output='" + + output + + '\'' + + ", logs=" + + logs + + ", logsBloom='" + + logsBloom + + '\'' + + ", transAndProof=" + + txProof + + ", receiptAndProof=" + + receiptProof + + '}'; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java index a450f46ea..04fd88ef6 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java @@ -14,7 +14,7 @@ */ package org.fisco.bcos.sdk.transaction.domain.dto; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; +import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; /** * TransactionResponse @Description: TransactionResponse @@ -23,18 +23,18 @@ * @data Jul 17, 2020 3:16:51 PM */ public class TransactionResponse extends CommonResponse { - private BcosTransactionReceipt bcosTransactionReceipt; + private TransactionReceipt transactionReceipt; private String contractAddress; private String values; private String events; private String receiptMessages; /** @return the bcosTransactionReceipt */ - public BcosTransactionReceipt getBcosTransactionReceipt() { - return bcosTransactionReceipt; + public TransactionReceipt getTransactionReceipt() { + return transactionReceipt; } - /** @param bcosTransactionReceipt the bcosTransactionReceipt to set */ - public void setBcosTransactionReceipt(BcosTransactionReceipt bcosTransactionReceipt) { - this.bcosTransactionReceipt = bcosTransactionReceipt; + /** @param transactionReceipt the transactionReceipt to set */ + public void setTransactionReceipt(TransactionReceipt transactionReceipt) { + this.transactionReceipt = transactionReceipt; } /** @return the contractAddress */ public String getContractAddress() { diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java index c7113ade0..4c560595a 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java @@ -16,7 +16,7 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; +import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.dto.CallRequest; import org.fisco.bcos.sdk.transaction.domain.dto.CallResponse; import org.fisco.bcos.sdk.transaction.domain.dto.TransactionRequest; @@ -49,14 +49,14 @@ public TransactionResponse sendTransaction(TransactionRequest transactionRequest } @Override - public BcosTransactionReceipt sendTransaction( + public TransactionReceipt sendTransaction( int groupId, String signedTransaction, RespCallback callback) { // TODO Auto-generated method stub return null; } @Override - public CompletableFuture sendTransactionAsync( + public CompletableFuture sendTransactionAsync( TransactionRequest transactionRequest) { // TODO Auto-generated method stub return null; diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java index ba85d26d7..5915e1256 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java @@ -16,7 +16,7 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; +import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.dto.CallRequest; import org.fisco.bcos.sdk.transaction.domain.dto.CallResponse; import org.fisco.bcos.sdk.transaction.domain.dto.TransactionRequest; @@ -36,10 +36,10 @@ public interface TransactionManagerInterface { public TransactionResponse sendTransaction(TransactionRequest transactionRequest); - public BcosTransactionReceipt sendTransaction( + public TransactionReceipt sendTransaction( int groupId, String signedTransaction, RespCallback callback); - public CompletableFuture sendTransactionAsync( + public CompletableFuture sendTransactionAsync( TransactionRequest transactionRequest); public CallResponse sendCall(CallRequest callRequest);