Skip to content

Commit

Permalink
Merge pull request #149 from kyonRay/master
Browse files Browse the repository at this point in the history
Release v1.4.0
  • Loading branch information
kyonRay authored Mar 2, 2024
2 parents e9e9caf + d6589f3 commit f35ea14
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WeCross Java SDK提供操作跨链资源的Java API,开发者通过SDK可以
gradle

```
compile ('com.webank:wecross-java-sdk:1.3.1')
compile ('com.webank:wecross-java-sdk:1.4.0')
```

maven
Expand Down
30 changes: 18 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'jacoco'

group = 'com.webank'
sourceCompatibility = '1.8'
version = '1.3.1'
version = '1.4.0-SNAPSHOT'
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
classifier = 'sources'
Expand Down Expand Up @@ -87,18 +87,24 @@ dependencies {
compile 'com.moandjiezana.toml:toml4j:0.7.2'
compile 'com.google.code.gson:gson:2.8.9'
compile 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
compile 'org.springframework.boot:spring-boot-starter-web:2.7.13'
compile 'org.springframework.boot:spring-boot-starter-aop:2.7.13'
compile 'org.springframework.boot:spring-boot-starter-security:2.7.13'
compile 'org.springframework:spring-aspects:5.3.13'
compile 'org.springframework:spring-aop:5.3.13'
compile 'org.asynchttpclient:async-http-client:2.12.3'
compile 'io.netty:netty-codec-http:4.1.89.Final'
compile 'io.netty:netty-buffer:4.1.89.Final'
compile 'io.netty:netty-handler:4.1.89.Final'
compile 'com.google.guava:guava:30.1-jre'
compile ('org.springframework.boot:spring-boot-starter-web:2.7.18'){
exclude group: 'org.springframework', module: 'spring-core'
exclude group: 'org.springframework', module: 'spring-web'
exclude group: 'org.springframework', module: 'spring-webmvc'
exclude group: 'org.yaml', module: 'snakeyaml'
}
compile 'org.springframework.boot:spring-boot-starter-aop:2.7.18'
compile 'org.springframework.boot:spring-boot-starter-security:2.7.18'
compile 'org.springframework:spring-aspects:5.3.32'
compile 'org.springframework:spring-core:5.3.32'
compile 'org.springframework:spring-aop:5.3.32'
implementation ('org.asynchttpclient:async-http-client:2.12.3'){
exclude group : 'io.netty'
}
compile 'io.netty:netty-all:4.1.101.Final'
compile 'com.google.guava:guava:32.0.1-jre'
compile 'commons-codec:commons-codec:1.14'
compile 'org.bouncycastle:bcprov-jdk15on:1.69'
compile 'org.bouncycastle:bcprov-jdk18on:1.77'
compile 'junit:junit:4.13.1'
compile 'org.aspectj:aspectjrt:1.9.7'
compile 'org.aspectj:aspectjweaver:1.9.7'
Expand Down
2 changes: 1 addition & 1 deletion release_note.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.3.1
v1.4.0
1 change: 0 additions & 1 deletion src/main/java/com/webank/wecrosssdk/common/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public class Constant {
public static final String APPLICATION_CONFIG_FILE = "classpath:application.toml";
public static final String TEMPLATE_URL = "http://127.0.0.1:8250/";
public static final String XA_TRANSACTION_ID_KEY = "XA_TRANSACTION_ID";
public static final String XA_TRANSACTION_SEQ_KEY = "XA_TRANSACTION_SEQ";
/** alphabet(upper or lower case) + digit + character("_-") ,length in (4,16) */
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/webank/wecrosssdk/rpc/WeCrossRPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.webank.wecrosssdk.rpc.common.account.ChainAccount;
import com.webank.wecrosssdk.rpc.methods.Response;
import com.webank.wecrosssdk.rpc.methods.response.*;
import java.math.BigInteger;

public interface WeCrossRPC {

Expand Down Expand Up @@ -47,6 +48,8 @@ RemoteCall<XAResponse> autoCommitXATransaction(

RemoteCall<XATransactionListResponse> listXATransactions(int size);

RemoteCall<XATransactionListResponse> listXATransactions(int size, String chainPath);

RemoteCall<UAResponse> register(String name, String password) throws Exception;

RemoteCall<UAResponse> login(String name, String password) throws Exception;
Expand All @@ -63,5 +66,7 @@ RemoteCall<XAResponse> autoCommitXATransaction(

RemoteCall<UAResponse> setDefaultChainAccount(String chainName, Integer keyID);

RemoteCall<CommandResponse> getBlock(String path, BigInteger blockNumber);

String getCurrentTransactionID();
}
17 changes: 16 additions & 1 deletion src/main/java/com/webank/wecrosssdk/rpc/WeCrossRPCRest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.webank.wecrosssdk.rpc.methods.request.UARequest;
import com.webank.wecrosssdk.rpc.methods.response.*;
import com.webank.wecrosssdk.rpc.service.WeCrossService;
import java.math.BigInteger;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -246,7 +247,13 @@ public RemoteCall<CommandResponse> customCommand(String command, String path, Ob

@Override
public RemoteCall<XATransactionListResponse> listXATransactions(int size) {
ListXATransactionsRequest listXATransactionsRequest = new ListXATransactionsRequest(size);
return listXATransactions(size, null);
}

@Override
public RemoteCall<XATransactionListResponse> listXATransactions(int size, String chainPath) {
ListXATransactionsRequest listXATransactionsRequest =
new ListXATransactionsRequest(size, chainPath);
Request<ListXATransactionsRequest> request = new Request<>(listXATransactionsRequest);
return new RemoteCall<>(
weCrossService,
Expand Down Expand Up @@ -335,6 +342,14 @@ public String getCurrentTransactionID() {
return txID;
}

@Override
public RemoteCall<CommandResponse> getBlock(String path, BigInteger blockNumber) {
String uri = "/trans/getBlock";
BlockRequest blockRequest = new BlockRequest(blockNumber, path);
Request<BlockRequest> request = new Request<>(blockRequest);
return new RemoteCall<>(weCrossService, "GET", uri, CommandResponse.class, request);
}

private RemoteCall<TransactionResponse> buildSendTransactionRequest(
String path, TransactionRequest transactionRequest) {
String uri = "/resource/" + path.replace('.', '/') + "/sendTransaction";
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/webank/wecrosssdk/rpc/common/Block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.webank.wecrosssdk.rpc.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Block {
@JsonIgnore public byte[] rawBytes;
public BlockHeader blockHeader;
public List<String> transactionsHashes = new LinkedList<>();

public BlockHeader getBlockHeader() {
return blockHeader;
}

public void setBlockHeader(BlockHeader blockHeader) {
this.blockHeader = blockHeader;
}

public List<String> getTransactionsHashes() {
return transactionsHashes;
}

public void setTransactionsHashes(List<String> transactionsHashes) {
this.transactionsHashes = transactionsHashes;
}

public byte[] getRawBytes() {
return rawBytes;
}

public void setRawBytes(byte[] rawBytes) {
this.rawBytes = rawBytes;
}

@Override
public String toString() {
return "Block{"
+ "rawBytes="
+ Arrays.toString(rawBytes)
+ ", blockHeader="
+ blockHeader
+ ", transactionsHashes="
+ Arrays.toString(transactionsHashes.toArray())
+ '}';
}
}
81 changes: 81 additions & 0 deletions src/main/java/com/webank/wecrosssdk/rpc/common/BlockHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.webank.wecrosssdk.rpc.common;

public class BlockHeader {
private long number;
private String prevHash;
private String hash;
private String stateRoot;
private String transactionRoot;
private String receiptRoot;

public long getNumber() {
return number;
}

public void setNumber(long number) {
this.number = number;
}

public String getPrevHash() {
return prevHash;
}

public void setPrevHash(String prevHash) {
this.prevHash = prevHash;
}

public String getHash() {
return hash;
}

public void setHash(String hash) {
this.hash = hash;
}

public String getStateRoot() {
return stateRoot;
}

public void setStateRoot(String stateRoot) {
this.stateRoot = stateRoot;
}

public String getTransactionRoot() {
return transactionRoot;
}

public void setTransactionRoot(String transactionRoot) {
this.transactionRoot = transactionRoot;
}

public String getReceiptRoot() {
return receiptRoot;
}

public void setReceiptRoot(String receiptRoot) {
this.receiptRoot = receiptRoot;
}

@Override
public String toString() {
return "BlockHeader{"
+ "number="
+ number
+ ", prevHash='"
+ prevHash
+ '\''
+ ", hash='"
+ hash
+ '\''
+ ", stateRoot='"
+ stateRoot
+ '\''
+ ", transactionRoot='"
+ transactionRoot
+ '\''
+ ", receiptRoot='"
+ receiptRoot
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class CommandList {
"supportedStubs",
"listResources",
"status",
"detail");
"detail",
"getBlock");

public static final List<String> normalCommands = Arrays.asList("register", "login");
}
16 changes: 6 additions & 10 deletions src/main/java/com/webank/wecrosssdk/rpc/common/RequestUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public static String buildLoginParams(WeCrossRPC weCrossRPC, String username, St
String confusedPassword = DigestUtils.sha256Hex(LoginSalt.LoginSalt + password);

if (logger.isDebugEnabled()) {
logger.debug(
"login username: {}, pub: {}, randomToken: {}",
username,
pub,
authCode.getRandomToken());
username = username.replace("\n", "");
username = username.replace("\r", "");
logger.debug("login username: {}", username);
}

LoginRequest loginRequest = new LoginRequest();
Expand All @@ -56,11 +54,9 @@ public static String buildRegisterParams(
String confusedPassword = DigestUtils.sha256Hex(LoginSalt.LoginSalt + password);

if (logger.isDebugEnabled()) {
logger.debug(
"register username: {}, pub: {}, randomToken: {}",
username,
pub,
authCode.getRandomToken());
username = username.replace("\n", "");
username = username.replace("\r", "");
logger.debug("login username: {}", username);
}

RegisterRequest registerRequest = new RegisterRequest();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.webank.wecrosssdk.rpc.methods.request;

import java.math.BigInteger;

public class BlockRequest {
private BigInteger blockNumber;
private String path;

public BlockRequest() {}

public BlockRequest(BigInteger blockNumber, String path) {
this.blockNumber = blockNumber;
this.path = path;
}

public BigInteger getBlockNumber() {
return blockNumber;
}

public void setBlockNumber(BigInteger blockNumber) {
this.blockNumber = blockNumber;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ public class ListXATransactionsRequest {

private Map<String, Integer> offsets = new HashMap<>();

private String chainPath;

public ListXATransactionsRequest(int size) {
this.size = size;
}

public ListXATransactionsRequest(int size, String chainPath) {
this.size = size;
this.chainPath = chainPath;
}

public int getSize() {
return size;
}
Expand All @@ -28,4 +35,12 @@ public Map<String, Integer> getOffsets() {
public void setOffsets(Map<String, Integer> offsets) {
this.offsets = offsets;
}

public String getChainPath() {
return chainPath;
}

public void setChainPath(String chainPath) {
this.chainPath = chainPath;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.webank.wecrosssdk.rpc.methods.response;

import com.webank.wecrosssdk.rpc.common.Block;
import com.webank.wecrosssdk.rpc.methods.Response;

public class BlockResponse extends Response<Block> {

public BlockResponse() {
super();
}

public Block getBlock() {
return getData();
}

public void setBlock(Block block) {
setData(block);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public <T extends Response> void asyncSend(
} else {
url = server + uri;
}
if (logger.isDebugEnabled()) {
logger.debug("request: {}; url: {}", objectMapper.writeValueAsString(request), url);
if (logger.isTraceEnabled()) {
logger.trace("request: {}; url: {}", objectMapper.writeValueAsString(request), url);
}

checkRequest(request);
Expand Down
Loading

0 comments on commit f35ea14

Please sign in to comment.