Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.4.0 #33

Merged
merged 12 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .ci/ci_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,28 @@ LOG_INFO "------ check_basic---------"
check_basic
LOG_INFO "------ check_ecdsa_evm_node---------"
check_ecdsa_evm_node

# if $? error check hs_error log exist
if [ $? -ne 0 ];then
cat hs_err_pid*.log
fi
LOG_INFO "------ check_sm_evm_node---------"
check_sm_evm_node
# if $? error check hs_error log exist
if [ $? -ne 0 ];then
cat hs_err_pid*.log
fi
LOG_INFO "------ check_ecdsa_wasm_node---------"
check_ecdsa_wasm_node
# if $? error check hs_error log exist
if [ $? -ne 0 ];then
cat hs_err_pid*.log
fi
LOG_INFO "------ check_sm_wasm_node---------"
check_sm_wasm_node
# if $? error check hs_error log exist
if [ $? -ne 0 ];then
cat hs_err_pid*.log
fi

bash <(curl -s https://codecov.io/bash)
20 changes: 13 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
apply plugin: 'com.github.johnrengelman.shadow'

group 'com.webank.wecross'
version '1.3.1'
version '1.4.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -74,23 +74,29 @@ List logger = [

dependencies {
compile logger
implementation ('com.webank:wecross-java-stub:1.3.0') {
implementation ('com.webank:wecross-java-stub:1.4.0-SNAPSHOT') {
exclude group: "io.netty"
exclude group: 'org.fisco-bcos', module: 'tcnative'
}

implementation 'com.moandjiezana.toml:toml4j:0.7.2'
implementation 'com.google.guava:guava:30.1-jre'
implementation 'com.google.guava:guava:32.0.1-jre'

implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.4.0')
implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.6.0')
implementation 'commons-io:commons-io:2.8.0'

implementation 'org.fisco-bcos:solcJ:0.5.2.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.3'
implementation ('org.fisco-bcos:solcJ:0.5.2.0'){
exclude group: 'com.fasterxml.jackson.core'
}

// Use JUnit test framework
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.slf4j:slf4j-log4j12:2.0.5'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.5'
testImplementation ('org.springframework.boot:spring-boot-starter-test:2.7.18'){
exclude group: 'org.yaml', module: 'snakeyaml'
}
testImplementation 'net.minidev:json-smart:2.4.9'
testImplementation 'com.jayway.jsonpath:json-path:2.9.0'

integTestImplementation 'junit:junit:4.13.2'
integTestImplementation 'org.slf4j:slf4j-log4j12:2.0.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.webank.wecross.stub.Path;
import com.webank.wecross.stub.ResourceInfo;
import com.webank.wecross.stub.StubConstant;
import com.webank.wecross.stub.Transaction;
import com.webank.wecross.stub.TransactionContext;
import com.webank.wecross.stub.TransactionRequest;
import com.webank.wecross.stub.bcos3.AsyncBfsService;
Expand Down Expand Up @@ -232,9 +233,9 @@ public void getBlockHeaderIntegTest() throws InterruptedException {
driver.asyncGetBlock(blockNumber, false, connection, (e2, block) -> {
assertNull(e2);
BlockHeader blockHeader = block.getBlockHeader();
List<String> transactionsHashes = block.getTransactionsHashes();
assertEquals(1, transactionsHashes.size());
assertTrue(Objects.nonNull(transactionsHashes.get(0)));
List<Transaction> transactionsWithDetail = block.getTransactionsWithDetail();
assertEquals(1, transactionsWithDetail.size());
assertTrue(Objects.nonNull(transactionsWithDetail.get(0)));
assertTrue(block.getRawBytes().length > 1);
assertTrue(Objects.nonNull(blockHeader));
assertTrue(Objects.nonNull(blockHeader.getHash()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ public void handleAsyncGetBlockRequest(Request request, Callback callback) {
Response response = new Response();
try {
BigInteger blockNumber = new BigInteger(request.getData());
BcosBlock.Block block = clientWrapper.getBlockByNumber(blockNumber.longValue());

BcosBlock.Block block = clientWrapper.getBlockByNumber(blockNumber.longValue(), false);
try {
BcosBlockHeader.BlockHeader blockHeader =
clientWrapper.getBlockHeaderByNumber(blockNumber.longValue());
Expand Down
128 changes: 126 additions & 2 deletions src/main/java/com/webank/wecross/stub/bcos3/BCOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
import java.nio.ByteBuffer;
import java.security.InvalidParameterException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionBuilderJniObj;
import org.fisco.bcos.sdk.jni.utilities.tx.TxPair;
import org.fisco.bcos.sdk.v3.client.protocol.model.JsonTransactionResponse;
import org.fisco.bcos.sdk.v3.client.protocol.response.BcosBlock;
import org.fisco.bcos.sdk.v3.client.protocol.response.Call;
import org.fisco.bcos.sdk.v3.codec.ContractCodec;
import org.fisco.bcos.sdk.v3.codec.FunctionEncoderInterface;
Expand Down Expand Up @@ -1133,7 +1136,21 @@ public void asyncGetBlock(
callback.onResponse(new Exception(response.getErrorMessage()), null);
} else {
try {
Block block = BlockUtility.convertToBlock(response.getData(), false);
Block block =
BlockUtility.convertToBlock(response.getData(), onlyHeader);
if (block.getTransactionsHashes().isEmpty()) {
BcosBlock.Block bcosBlock =
ObjectMapperFactory.getObjectMapper()
.readValue(
response.getData(), BcosBlock.Block.class);
for (int i = 0; i < bcosBlock.getTransactionObject().size(); i++) {
BcosBlock.TransactionObject transactionObject =
(BcosBlock.TransactionObject)
bcosBlock.getTransactions().get(i);
assembleJsonTransactionResponse(
blockNumber, transactionObject, connection, block);
}
}
if (blockVerifierString != null && blockNumber != 0) {
BCOSBlockHeader bcosBlockHeader =
(BCOSBlockHeader) block.blockHeader;
Expand Down Expand Up @@ -1211,6 +1228,110 @@ public void asyncGetTransaction(
});
}

private void assembleJsonTransactionResponse(
long blockNumber,
JsonTransactionResponse jsonTransactionResponse,
Connection connection,
Block block)
throws Exception {
byte[] txBytes =
ObjectMapperFactory.getObjectMapper().writeValueAsBytes(jsonTransactionResponse);

String methodId;
String input;
String path;
String resource;
String xaTransactionID = "0";
String transactionHash = jsonTransactionResponse.getHash();
Transaction transaction = new Transaction();
transaction.setTxBytes(txBytes);
transaction.setAccountIdentity(jsonTransactionResponse.getFrom());
transaction.setTransactionByProxy(true);
transaction.getTransactionResponse().setHash(transactionHash);
transaction.getTransactionResponse().setBlockNumber(blockNumber);
transaction.getTransactionResponse().setTimestamp(jsonTransactionResponse.getImportTime());
String proxyInput = jsonTransactionResponse.getInput();
if (proxyInput.startsWith(
Hex.toHexStringWithPrefix(
functionEncoder.buildMethodId(FunctionUtility.ProxySendTXMethod)))) {
Tuple3<String, String, byte[]> proxyResult =
FunctionUtility.getSendTransactionProxyWithoutTxIdFunctionInput(
proxyInput, isWasm);
resource = proxyResult.getValue2();
input = Numeric.toHexString(proxyResult.getValue3());
methodId = input.substring(0, FunctionUtility.MethodIDWithHexPrefixLength);
if (logger.isDebugEnabled()) {
logger.debug(" resource: {}, methodId: {}", resource, methodId);
}
} else if (proxyInput.startsWith(
Hex.toHexStringWithPrefix(
functionEncoder.buildMethodId(
FunctionUtility.ProxySendTransactionTXMethod)))) {
Tuple6<String, String, BigInteger, String, String, byte[]> proxyInputResult =
FunctionUtility.getSendTransactionProxyFunctionInput(proxyInput, isWasm);
xaTransactionID = proxyInputResult.getValue2();
path = proxyInputResult.getValue4();
resource = Path.decode(path).getResource();
String methodSig = proxyInputResult.getValue5();
methodId = Hex.toHexString(functionEncoder.buildMethodId(methodSig));
if (logger.isDebugEnabled()) {
logger.debug("path: {}, methodSig: {}, methodId: {}", path, methodSig, methodId);
}
} else {
// transaction not send by proxy
transaction.setTransactionByProxy(false);
block.getTransactionsWithDetail().add(transaction);
return;
}
transaction
.getTransactionRequest()
.getOptions()
.put(StubConstant.XA_TRANSACTION_ID, xaTransactionID);
transaction.setResource(resource);
// query ABI
String finalMethodId = methodId;
CompletableFuture<String> future = new CompletableFuture<>();
asyncBfsService.queryABI(
resource,
this,
connection,
(queryABIException, abi) -> {
if (Objects.nonNull(queryABIException)) {
logger.error(
"Query abi failed, transactionHash: {}, e: ",
transactionHash,
queryABIException);
future.completeExceptionally(queryABIException);
}
future.complete(abi);
});
try {
String abi = future.get(10, TimeUnit.SECONDS);
ABIDefinition function =
abiDefinitionFactory
.loadABI(abi)
.getMethodIDToFunctions()
.get(ByteBuffer.wrap(Hex.decode(finalMethodId)));
if (Objects.isNull(function)) {
logger.warn(
"Maybe abi is upgraded, Load function failed, methodId: {}", finalMethodId);
} else {
transaction.getTransactionRequest().setMethod(function.getName());
}
} catch (Exception e) {
logger.error(
"Maybe Query abi failed, transactionHash: {},resource:{} MethodId: {},e:",
transactionHash,
resource,
finalMethodId,
e);
}
block.getTransactionsWithDetail().add(transaction);
if (logger.isTraceEnabled()) {
logger.trace("blockNumber: {}, block: {}", blockNumber, block);
}
}

private void assembleTransaction(
String transactionHash,
JsonTransactionResponse jsonTransactionResponse,
Expand Down Expand Up @@ -1241,6 +1362,9 @@ private void assembleTransaction(
transaction
.getTransactionResponse()
.setBlockNumber(receipt.getBlockNumber().longValue());
transaction
.getTransactionResponse()
.setTimestamp(jsonTransactionResponse.getImportTime());

String proxyInput = receipt.getInput();
String proxyOutput = receipt.getOutput();
Expand Down Expand Up @@ -1303,7 +1427,6 @@ private void assembleTransaction(
String finalMethodId = methodId;
String finalInput = input;
byte[] finalOutputBytes = FunctionUtility.decodeProxyBytesOutput(proxyOutput, isWasm);
;
asyncBfsService.queryABI(
resource,
this,
Expand Down Expand Up @@ -1368,6 +1491,7 @@ private void assembleTransaction(
} catch (ClassNotFoundException e) {
logger.error("CodecJsonWrapper e:", e);
callback.onResponse(e, null);
return;
}

transaction.getTransactionResponse().setErrorCode(receipt.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public AbstractClientWrapper(Client client) {
}

@Override
public BcosBlock.Block getBlockByNumber(long blockNumber) throws IOException {
public BcosBlock.Block getBlockByNumber(long blockNumber, boolean onlyTxHash)
throws IOException {
BcosBlock blockByNumber =
getClient().getBlockByNumber(BigInteger.valueOf(blockNumber), false, true);
getClient().getBlockByNumber(BigInteger.valueOf(blockNumber), false, onlyTxHash);
return blockByNumber.getBlock();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public long getBlockNumber() throws IOException {
}

public Block getBlock(long blockNumber) throws IOException {
BcosBlock.Block block = clientWrapper.getBlockByNumber(blockNumber);
BcosBlock.Block block = clientWrapper.getBlockByNumber(blockNumber, true);
return BlockUtility.convertToBlock(block, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/** Wrapper interface for JavaSDK */
public interface ClientWrapper {
BcosBlock.Block getBlockByNumber(long blockNumber) throws IOException;
BcosBlock.Block getBlockByNumber(long blockNumber, boolean onlyTxHash) throws IOException;

BcosBlockHeader.BlockHeader getBlockHeaderByNumber(long blockNumber) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static BlockHeader convertToBlockHeader(BcosBlock.Block block) throws IOE
blockHeader.setReceiptRoot(block.getReceiptsRoot());
blockHeader.setStateRoot(block.getStateRoot());
blockHeader.setTransactionRoot(block.getTransactionsRoot());
blockHeader.setTimestamp(block.getTimestamp());
return blockHeader;
}

Expand Down Expand Up @@ -66,6 +67,7 @@ public static BlockHeader convertToBlockHeaderWithSignature(BcosBlock.Block bloc
stubBlockHeader.setTransactionRoot(bcosHeader.getTransactionsRoot());
stubBlockHeader.setSealerList(bcosHeader.getSealerList());
stubBlockHeader.setSignatureList(bcosHeader.getSignatureList());
stubBlockHeader.setTimestamp(bcosHeader.getTimestamp());
return stubBlockHeader;
}

Expand All @@ -83,7 +85,7 @@ public static Block convertToBlock(BcosBlock.Block block, boolean onlyHeader)

/** tx list */
List<String> txs = new ArrayList<>();
if (!onlyHeader) {
if (!onlyHeader && !block.getTransactionHashes().isEmpty()) {
for (int i = 0; i < block.getTransactions().size(); i++) {
BcosBlock.TransactionHash transactionHash =
(BcosBlock.TransactionHash) block.getTransactions().get(i);
Expand Down
Loading
Loading