Skip to content
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
8 changes: 8 additions & 0 deletions sdk-core/src/main/java/org/fisco/bcos/sdk/utils/Hex.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;
import org.fisco.bcos.sdk.utils.exceptions.DecoderException;
import org.fisco.bcos.sdk.utils.exceptions.EncoderException;

/** Utility class for converting hex data to bytes and back again. */
public class Hex {
private static final HexEncoder encoder = new HexEncoder();

public static String trimPrefix(String data) {
if (Objects.nonNull(data) && data.startsWith("0x")) {
return data.substring(2);
}
return data;
}

public static String toHexString(byte[] data) {
return toHexString(data, 0, data.length);
}
Expand Down
14 changes: 7 additions & 7 deletions sdk-service/src/main/java/org/fisco/bcos/sdk/BcosSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public ConfigOption getConfig() {
return config;
}

// public org.fisco.bcos.sdk.jni.BcosSDK getJniBcosSdk() {
// return jniBcosSdk;
// }
//
// public void setJniBcosSdk(org.fisco.bcos.sdk.jni.BcosSDK jniBcosSdk) {
// this.jniBcosSdk = jniBcosSdk;
// }
// public org.fisco.bcos.sdk.jni.BcosSDK getJniBcosSdk() {
// return jniBcosSdk;
// }
//
// public void setJniBcosSdk(org.fisco.bcos.sdk.jni.BcosSDK jniBcosSdk) {
// this.jniBcosSdk = jniBcosSdk;
// }

/**
* Build BcosSDK instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.fisco.bcos.sdk.model.JsonRpcResponse;
import org.fisco.bcos.sdk.model.Response;
import org.fisco.bcos.sdk.model.callback.TransactionCallback;
import org.fisco.bcos.sdk.utils.Hex;
import org.fisco.bcos.sdk.utils.ObjectMapperFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -71,7 +72,7 @@ protected void initGroupInfo() {
if (nodeList == null || nodeList.isEmpty()) {
logger.error("There has no nodes in the group, groupID: {}, groupInfo: {}", groupInfo);
throw new ClientException(
"There has no nodes in the group, please check the group, groupID: "
"There has no nodes in the group, maybe the group has been removed, groupID: "
+ this.groupID);
}

Expand Down Expand Up @@ -246,7 +247,10 @@ public Call call(String node, Transaction transaction) {
new JsonRpcRequest(
JsonRpcMethods.CALL,
Arrays.asList(
this.groupID, node, transaction.getTo(), transaction.getData())),
this.groupID,
node,
Hex.trimPrefix(transaction.getTo()),
transaction.getData())),
Call.class);
}

Expand All @@ -262,7 +266,12 @@ public void callAsync(String node, Transaction transaction, RespCallback<Call> c
this.groupID,
node,
new JsonRpcRequest(
JsonRpcMethods.CALL, Arrays.asList(this.groupID, node, transaction)),
JsonRpcMethods.CALL,
Arrays.asList(
this.groupID,
node,
Hex.trimPrefix(transaction.getTo()),
transaction.getData())),
Call.class,
callback);
}
Expand Down Expand Up @@ -307,10 +316,12 @@ public Code getCode(String address) {
@Override
public Code getCode(String node, String address) {
node = Objects.isNull(node) ? "" : node;

// create request
JsonRpcRequest request =
new JsonRpcRequest(
JsonRpcMethods.GET_CODE, Arrays.asList(this.groupID, node, address));
JsonRpcMethods.GET_CODE,
Arrays.asList(this.groupID, node, Hex.trimPrefix(address)));
return this.callRemoteMethod(this.groupID, node, request, Code.class);
}

Expand All @@ -326,7 +337,8 @@ public void getCodeAsync(String node, String address, RespCallback<Code> callbac
this.groupID,
node,
new JsonRpcRequest(
JsonRpcMethods.GET_CODE, Arrays.asList(this.groupID, node, address)),
JsonRpcMethods.GET_CODE,
Arrays.asList(this.groupID, node, Hex.trimPrefix(address))),
Code.class,
callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.fisco.bcos.sdk.codec.ABICodecException;
import org.fisco.bcos.sdk.crypto.CryptoSuite;
import org.fisco.bcos.sdk.transaction.codec.encode.TransactionEncoderService;
import org.fisco.bcos.sdk.utils.Hex;

public class TransactionBuilderService implements TransactionBuilderInterface {
private Client client;
Expand Down Expand Up @@ -88,7 +89,13 @@ public TransactionData createTransaction(
Random r = ThreadLocalRandom.current();
BigInteger randomId = new BigInteger(250, r);
return new TransactionData(
0, chainId, groupId, blockLimit.intValue(), randomId.toString(), to, data);
0,
chainId,
groupId,
blockLimit.intValue(),
randomId.toString(),
Hex.trimPrefix(to),
data);
}

/** @return the client */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public TransactionData getRawTransaction(
String to, String abi, String functionName, List<Object> params)
throws ABICodecException {
return this.transactionBuilder.createTransaction(
to,
Hex.trimPrefix(to),
this.abiCodec.encodeMethod(abi, functionName, params),
this.chainId,
this.groupId);
Expand All @@ -376,7 +376,7 @@ public TransactionData getRawTransaction(
throws ABICodecException {
return this.transactionBuilder.createTransaction(
blockLimit,
to,
Hex.trimPrefix(to),
this.abiCodec.encodeMethod(abi, functionName, params),
this.chainId,
this.groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void testGetGroupList() throws ConfigException, JniException {
System.out.println("getGroupList: " + groupList);

BcosSDK bcosSDK = new BcosSDK(configOption);
for(String groupId: groupList) {
for (String groupId : groupList) {
Client client = bcosSDK.getClient(groupId);
System.out.println("build client, groupId: " + groupId);
System.out.println("getBlockNumber, blk: " + client.getBlockNumber().getBlockNumber());
Expand Down