Skip to content

Commit

Permalink
Merge pull request #757 from FISCO-BCOS/release-2.6.5
Browse files Browse the repository at this point in the history
sync code from 2.6.5
  • Loading branch information
ywy2090 authored Jul 13, 2023
2 parents 2788e9f + 42b1ed0 commit 2189feb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 301 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ dependencies {
// compile 'io.netty:netty-tcnative:2.0.25.Final'
// compile 'io.netty:netty-tcnative-boringssl-static:2.0.27.Final'
// compile 'org.fisco-bcos:netty-sm-ssl-context:1.0.0-SNAPSHOT'
compile ('org.fisco-bcos:netty-sm-ssl-context:1.2.0') {
compile ('org.fisco-bcos:netty-sm-ssl-context:1.5.2') {
exclude module:"log4j"
}

// compile 'org.ethereum:solcJ-all:0.4.25'
compile 'io.netty:netty-all:4.1.53.Final'
compile 'com.google.guava:guava:29.0-jre'
compile 'commons-configuration:commons-configuration:1.10'
compile 'org.apache.httpcomponents:httpclient:4.5.5'
Expand Down
6 changes: 3 additions & 3 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ dependencies {

// compile 'io.netty:netty-tcnative:2.0.25.Final'
// compile 'io.netty:netty-tcnative-boringssl-static:2.0.27.Final'
compile ('org.fisco-bcos:netty-sm-ssl-context:1.2.0') {
compile ('org.fisco-bcos:netty-sm-ssl-context:1.5.2') {
exclude module:"log4j"
}

// compile 'org.ethereum:solcJ-all:0.4.25'
compile 'io.netty:netty-all:4.1.53.Final'
// compile 'io.netty:netty-all:4.1.53.Final'
compile 'com.google.guava:guava:29.0-jre'
compile 'commons-configuration:commons-configuration:1.10'
compile 'org.apache.httpcomponents:httpclient:4.5.5'
Expand All @@ -90,7 +90,7 @@ dependencies {

archivesBaseName = 'web3sdk'
group = 'org.fisco-bcos'
version = '2.6.4'
version = '2.6.6'

// Additional attribute definition

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/fisco/bcos/channel/client/ReceiptEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import org.fisco.bcos.fisco.EnumNodeVersion;
import org.fisco.bcos.web3j.protocol.core.methods.response.Log;
import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt;
import org.fisco.bcos.web3j.rlp.RlpEncoder;
Expand All @@ -12,14 +13,16 @@

// encode transaction receipt by Rlp into hex string
public class ReceiptEncoder {
public static String encode(TransactionReceipt transactionReceipt) {
List<RlpType> values = asRlpValues(transactionReceipt);
public static String encode(
TransactionReceipt transactionReceipt, EnumNodeVersion.Version version) {
List<RlpType> values = asRlpValues(transactionReceipt, version);
RlpList rlpList = new RlpList(values);
byte[] rlpBytes = RlpEncoder.encode(rlpList);
return Numeric.toHexString(rlpBytes);
}

private static List<RlpType> asRlpValues(TransactionReceipt transactionReceipt) {
private static List<RlpType> asRlpValues(
TransactionReceipt transactionReceipt, EnumNodeVersion.Version version) {
List<RlpType> result = new ArrayList<>();
// bytes
result.add(RlpString.create(Numeric.hexStringToByteArray(transactionReceipt.getRoot())));
Expand All @@ -38,6 +41,11 @@ private static List<RlpType> asRlpValues(TransactionReceipt transactionReceipt)

result.add(RlpString.create(Numeric.hexStringToByteArray(transactionReceipt.getOutput())));

// gas used
if (version != null && version.getMinor() >= 9) {
result.add(RlpString.create(Numeric.toBigInt(transactionReceipt.getRemainGasRaw())));
}

// List
List<Log> logs = transactionReceipt.getLogs();
List<RlpType> logList = new ArrayList<>();
Expand Down
140 changes: 0 additions & 140 deletions src/main/java/org/fisco/bcos/channel/client/TransactionResource.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class TransactionReceipt {
private String blockHash;
private String blockNumber;
private String gasUsed;
private String remainGas;
private String contractAddress;
private String root;
// status is only present on Byzantium transactions onwards
Expand All @@ -34,6 +35,7 @@ public TransactionReceipt(
String transactionIndex,
String blockHash,
String blockNumber,
String remainGas,
String gasUsed,
String contractAddress,
String root,
Expand All @@ -49,6 +51,7 @@ public TransactionReceipt(
this.transactionIndex = transactionIndex;
this.blockHash = blockHash;
this.blockNumber = blockNumber;
this.remainGas = remainGas;
this.gasUsed = gasUsed;
this.contractAddress = contractAddress;
this.root = root;
Expand Down Expand Up @@ -120,6 +123,19 @@ public void setBlockNumber(String blockNumber) {
this.blockNumber = blockNumber;
}

@JsonIgnore
public String getRemainGasRaw() {
return remainGas;
}

public BigInteger getRemainGas() {
return Numeric.decodeQuantity(remainGas);
}

public void setRemainGas(String remainGas) {
this.remainGas = remainGas;
}

public BigInteger getGasUsed() {
return Numeric.decodeQuantity(gasUsed);
}
Expand Down Expand Up @@ -261,6 +277,11 @@ public boolean equals(Object o) {
if (gasUsed != null ? !gasUsed.equals(that.gasUsed) : that.gasUsed != null) {
return false;
}

if (remainGas != null ? !remainGas.equals(that.remainGas) : that.remainGas != null) {
return false;
}

if (getContractAddress() != null
? !getContractAddress().equals(that.getContractAddress())
: that.getContractAddress() != null) {
Expand Down Expand Up @@ -303,6 +324,7 @@ public int hashCode() {
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 + (remainGas != null ? remainGas.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);
Expand Down Expand Up @@ -333,6 +355,9 @@ public String toString() {
+ ", gasUsed='"
+ gasUsed
+ '\''
+ ", remainGas='"
+ remainGas
+ '\''
+ ", contractAddress='"
+ contractAddress
+ '\''
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/org/fisco/bcos/web3j/tx/MerkleProofUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;
import org.fisco.bcos.channel.client.Merkle;
import org.fisco.bcos.channel.client.ReceiptEncoder;
import org.fisco.bcos.channel.protocol.ChannelPrococolExceiption;
import org.fisco.bcos.fisco.EnumNodeVersion;
import org.fisco.bcos.web3j.crypto.Hash;
import org.fisco.bcos.web3j.protocol.core.methods.response.MerkleProofUnit;
import org.fisco.bcos.web3j.protocol.core.methods.response.Transaction;
Expand Down Expand Up @@ -55,7 +57,15 @@ public static boolean verifyTransaction(
* @return
*/
public static boolean verifyTransactionReceipt(
String receiptRoot, TransactionReceiptWithProof.ReceiptAndProof receiptAndProof) {
String receiptRoot,
TransactionReceiptWithProof.ReceiptAndProof receiptAndProof,
String supportedVersion) {

EnumNodeVersion.Version classVersion = null;
try {
classVersion = EnumNodeVersion.getClassVersion(supportedVersion);
} catch (ChannelPrococolExceiption e) {
}

TransactionReceipt transactionReceipt = receiptAndProof.getTransactionReceipt();

Expand All @@ -67,7 +77,14 @@ public static boolean verifyTransactionReceipt(
transactionReceipt.setGasUsed("0x" + transactionReceipt.getGasUsed().toString(16));
}

String receiptRlp = ReceiptEncoder.encode(transactionReceipt);
if (classVersion != null && classVersion.getMinor() >= 9) {
if (!transactionReceipt.getRemainGasRaw().startsWith("0x")) {
transactionReceipt.setRemainGas(
"0x" + transactionReceipt.getRemainGas().toString(16));
}
}

String receiptRlp = ReceiptEncoder.encode(transactionReceipt, classVersion);
String rlpHash = Hash.sha3(receiptRlp);
String input = Numeric.toHexString(byteIndex) + rlpHash.substring(2);

Expand Down Expand Up @@ -125,17 +142,31 @@ public static boolean verifyTransaction(
public static boolean verifyTransactionReceipt(
String receiptRoot,
TransactionReceipt transactionReceipt,
List<MerkleProofUnit> receiptProof) {
List<MerkleProofUnit> receiptProof,
String supportedVersion) {

if (!transactionReceipt.getGasUsedRaw().startsWith("0x")) {
transactionReceipt.setGasUsed("0x" + transactionReceipt.getGasUsed().toString(16));
}

EnumNodeVersion.Version classVersion = null;
try {
classVersion = EnumNodeVersion.getClassVersion(supportedVersion);
} catch (ChannelPrococolExceiption e) {
}

if (classVersion != null && classVersion.getMinor() >= 9) {
if (!transactionReceipt.getRemainGasRaw().startsWith("0x")) {
transactionReceipt.setRemainGas(
"0x" + transactionReceipt.getRemainGas().toString(16));
}
}

// transaction index
byte[] byteIndex =
RlpEncoder.encode(RlpString.create(transactionReceipt.getTransactionIndex()));

String receiptRlp = ReceiptEncoder.encode(transactionReceipt);
String receiptRlp = ReceiptEncoder.encode(transactionReceipt, classVersion);
String rlpHash = Hash.sha3(receiptRlp);
String input = Numeric.toHexString(byteIndex) + rlpHash.substring(2);

Expand Down
Loading

0 comments on commit 2189feb

Please sign in to comment.