Skip to content

Commit

Permalink
<fix>(project): fix codeQL code scan warning. (#693)
Browse files Browse the repository at this point in the history
* <fix>(precompiled): fix isolated node add sealer error code bug.

* <fix>(project): fix codeQL code scan warning.
  • Loading branch information
kyonRay authored Nov 18, 2022
1 parent 5d1e255 commit dab6d3f
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public Boolean isAuthCheck() {
return this.authCheck;
}

@Override
public Boolean isSerialExecute() {
return this.serialExecute;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public void setExecutor(Executor executor) {
this.executor = executor;
}

@Override
public String toString() {
return "GroupNodeIniConfig{" + "chain=" + chain + ", executor=" + executor + '}';
}

public static class Executor {
private boolean isWasm;
private boolean isAuthCheck;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public TransactionHash(String value) {
this.value = value;
}

@Override
public String get() {
return value;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ public List<Object> decodeMethodInputById(String abi, byte[] methodId, byte[] in
ContractABIDefinition contractABIDefinition = this.abiDefinitionFactory.loadABI(abi);
ABIDefinition abiDefinition = contractABIDefinition.getABIDefinitionByMethodId(methodId);
if (abiDefinition == null) {
String errorMsg = " methodId " + methodId + " is invalid";
String errorMsg = " methodId " + Hex.toHexString(methodId) + " is invalid";
logger.error(errorMsg);
throw new ContractCodecException(errorMsg);
}
Expand Down Expand Up @@ -736,7 +736,7 @@ public List<String> decodeMethodInputByIdToString(String abi, byte[] methodId, b
ContractABIDefinition contractABIDefinition = this.abiDefinitionFactory.loadABI(abi);
ABIDefinition abiDefinition = contractABIDefinition.getABIDefinitionByMethodId(methodId);
if (abiDefinition == null) {
String errorMsg = " methodId " + methodId + " is invalid";
String errorMsg = " methodId " + Hex.toHexString(methodId) + " is invalid";
logger.error(errorMsg);
throw new ContractCodecException(errorMsg);
}
Expand Down Expand Up @@ -820,7 +820,7 @@ public List<Object> decodeMethodById(String abi, byte[] methodId, byte[] output)
ContractABIDefinition contractABIDefinition = this.abiDefinitionFactory.loadABI(abi);
ABIDefinition abiDefinition = contractABIDefinition.getABIDefinitionByMethodId(methodId);
if (abiDefinition == null) {
String errorMsg = " methodId " + methodId + " is invalid";
String errorMsg = " methodId " + Hex.toHexString(methodId) + " is invalid";
logger.error(errorMsg);
throw new ContractCodecException(errorMsg);
}
Expand Down Expand Up @@ -873,7 +873,7 @@ public List<String> decodeMethodByIdToString(String abi, byte[] methodId, byte[]
ContractABIDefinition contractABIDefinition = this.abiDefinitionFactory.loadABI(abi);
ABIDefinition abiDefinition = contractABIDefinition.getABIDefinitionByMethodId(methodId);
if (abiDefinition == null) {
String errorMsg = " methodId " + methodId + " is invalid";
String errorMsg = " methodId " + Hex.toHexString(methodId) + " is invalid";
logger.error(errorMsg);
throw new ContractCodecException(errorMsg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public List<Type> decode(String rawInput, List<TypeReference<Type>> outputParame
* @param <T> type of TypeReference
* @return the decode value
*/
@Override
public <T extends Type> Type decodeIndexedValue(
String rawInput, TypeReference<T> typeReference) {
String input = Numeric.cleanHexPrefix(rawInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static <T extends Type> byte[] encodeArrayValuesOffsets(DynamicArray<T> value) {
long offset = 0;
for (int i = 0; i < value.getValue().size(); i++) {
if (i == 0) {
offset = value.getValue().size() * MAX_BYTE_LENGTH;
offset = (long) value.getValue().size() * MAX_BYTE_LENGTH;
} else {
int bytesLength =
arrayOfBytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected TypeReference(Type type) {
this.indexed = false;
}

@Override
public int compareTo(TypeReference<T> o) {
// taken from the blog post comments - this results in an errror if the
// type parameter is left out.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,35 @@ public int hashCode() {
return result;
}

@Override
public String toString() {
return "ABIDefinition{"
+ "name='"
+ name
+ '\''
+ ", type='"
+ type
+ '\''
+ ", constant="
+ constant
+ ", payable="
+ payable
+ ", anonymous="
+ anonymous
+ ", stateMutability='"
+ stateMutability
+ '\''
+ ", conflictFields="
+ conflictFields
+ ", inputs="
+ inputs
+ ", outputs="
+ outputs
+ ", selector="
+ selector
+ '}';
}

public List<ConflictField> getConflictFields() {
return conflictFields;
}
Expand Down Expand Up @@ -418,6 +447,19 @@ public String getSlot() {
public void setSlot(String slot) {
this.slot = slot;
}

@Override
public String toString() {
return "ConflictField{"
+ "kind="
+ kind
+ ", slot='"
+ slot
+ '\''
+ ", value="
+ value
+ '}';
}
}

public static class NamedType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,20 @@ public ABIDefinition getABIDefinitionByEventTopic(String topic) {
// FIXME: check topic string is hex
return this.eventTopicToEvents.get(ByteBuffer.wrap(Hex.decode(topic)));
}

@Override
public String toString() {
return "ContractABIDefinition{"
+ "constructor="
+ constructor
+ ", functions="
+ functions
+ ", events="
+ events
+ ", methodIDToFunctions="
+ methodIDToFunctions
+ ", eventTopicToEvents="
+ eventTopicToEvents
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ private ABIObject encodeNode(String path, ABIObject template, JsonNode node) {
abiObject.setStringValue(new Utf8String(node.asText()));
break;
}
case FIXED:
case UFIXED:
{
throw new UnsupportedOperationException(
" Unsupported fixed/unfixed type. ");
}
}
break;
}
Expand Down Expand Up @@ -445,6 +451,12 @@ public JsonNode decode(ABIObject abiObject) {
return jsonNodeFactory.textNode(
abiObject.getStringValue().getValue());
}
case FIXED:
case UFIXED:
{
throw new UnsupportedOperationException(
" Unsupported fixed/unfixed type. ");
}
}
break;
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/fisco/bcos/sdk/v3/config/ConfigOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,22 @@ public ConfigProperty getConfigProperty() {
public void setConfigProperty(ConfigProperty configProperty) {
this.configProperty = configProperty;
}

@Override
public String toString() {
return "ConfigOption{"
+ ", accountConfig="
+ accountConfig
+ ", amopConfig="
+ amopConfig
+ ", networkConfig="
+ networkConfig
+ ", threadPoolConfig="
+ threadPoolConfig
+ ", configProperty="
+ configProperty
+ ", jniConfig="
+ jniConfig
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ public List<AmopTopic> getAmopTopicConfig() {
public void setAmopTopicConfig(List<AmopTopic> amopTopicConfig) {
this.amopTopicConfig = amopTopicConfig;
}

@Override
public String toString() {
return "AmopConfig{" + "amopTopicConfig=" + amopTopicConfig + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,18 @@ public static String getConfigFileContent(String configFilePath) throws ConfigEx
throw new ConfigException("File not found, path: " + configFilePath);
}
}

@Override
public String toString() {
return "ConfigProperty{"
+ ", network="
+ network
+ ", amop="
+ amop
+ ", account="
+ account
+ ", threadPool="
+ threadPool
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,17 @@ public int getTimeout() {
public void setTimeout(int timeout) {
this.timeout = timeout;
}

@Override
public String toString() {
return "NetworkConfig{"
+ "peers="
+ peers
+ ", defaultGroup='"
+ defaultGroup
+ '\''
+ ", timeout="
+ timeout
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public ThreadPoolConfig(ConfigProperty configProperty) {
this.threadPoolSize = Integer.parseInt(value);
logger.debug("Init ThreadPoolConfig, threadPoolSize: {}", this.threadPoolSize);
}

@Override
public String toString() {
return "ThreadPoolConfig{" + "threadPoolSize=" + threadPoolSize + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ private void checkSetConsensusWeightParams(String node, BigInteger weight, boole
List<String> observerList = client.getObserverList().getObserverList();
if (observerList != null && !observerList.contains(node)) {
throw new ContractException(
PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getMessage());
PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getMessage(),
PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getCode());
}
SyncStatus syncStatus = client.getSyncStatus();
BigInteger blockNumber = client.getBlockNumber().getBlockNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public RetCode addSealer(String nodeId, BigInteger weight) throws ContractExcept
List<String> observerList = client.getObserverList().getObserverList();
if (observerList != null && !observerList.contains(nodeId)) {
throw new ContractException(
PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getMessage());
PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getMessage(),
PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getCode());
}
SyncStatus syncStatus = client.getSyncStatus();
BigInteger blockNumber = client.getBlockNumber().getBlockNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ public Entry(String key, List<String> fields) {
}

public static class Condition extends DynamicStruct {
public BigInteger op;
private BigInteger op;

public String value;
private String condValue;

public Condition() {
super(new Uint8(0), new Utf8String(""));
Expand All @@ -443,18 +443,18 @@ public Condition() {
public Condition(Uint8 op, Utf8String value) {
super(op, value);
this.op = op.getValue();
this.value = value.getValue();
this.condValue = value.getValue();
}

public Condition(BigInteger op, String value) {
super(new Uint8(op), new Utf8String(value));
this.op = op;
this.value = value;
this.condValue = value;
}

@Override
public String toString() {
return "Condition{" + "op=" + op + ", value='" + value + '\'' + '}';
return "Condition{" + "op=" + op + ", condValue='" + condValue + '\'' + '}';
}
}

Expand Down Expand Up @@ -504,9 +504,9 @@ public String toString() {
}

public static class UpdateField extends DynamicStruct {
public String columnName;
private String columnName;

public String value;
private String columnValue;

public UpdateField() {
super(new Utf8String(""), new Utf8String(""));
Expand All @@ -515,20 +515,26 @@ public UpdateField() {
public UpdateField(Utf8String columnName, Utf8String value) {
super(columnName, value);
this.columnName = columnName.getValue();
this.value = value.getValue();
this.columnValue = value.getValue();
}

public UpdateField(String columnName, String value) {
super(
new org.fisco.bcos.sdk.v3.codec.datatypes.Utf8String(columnName),
new org.fisco.bcos.sdk.v3.codec.datatypes.Utf8String(value));
this.columnName = columnName;
this.value = value;
this.columnValue = value;
}

@Override
public String toString() {
return "UpdateField{" + "columnName=" + columnName + ", value='" + value + '\'' + '}';
return "UpdateField{"
+ "columnName="
+ columnName
+ ", columnValue='"
+ columnValue
+ '\''
+ '}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public PublicKey getPublicKey() {
*
* @param in the input stream that should used to load keyPair
*/
@Override
protected void load(InputStream in) {
try {
keyStore = KeyStore.getInstance("PKCS12", "BC");
Expand Down Expand Up @@ -107,6 +108,7 @@ protected void load(InputStream in) {
*
* @return the private key
*/
@Override
protected PrivateKey getPrivateKey() {
try {
Enumeration<String> aliases = keyStore.aliases();
Expand Down Expand Up @@ -150,9 +152,11 @@ public static void storeKeyPairWithP12Format(
Certificate[] certChain = new Certificate[1];
certChain[0] = generateSelfSignedCertificate(keyPair, signatureAlgorithm);
keyStore.setKeyEntry(NAME, privateKey, password.toCharArray(), certChain);
keyStore.store(new FileOutputStream(privateKeyFilePath), password.toCharArray());
FileOutputStream fileOutputStream = new FileOutputStream(privateKeyFilePath);
keyStore.store(fileOutputStream, password.toCharArray());
// store the public key
storePublicKeyWithPem(privateKey, privateKeyFilePath);
fileOutputStream.close();
} catch (IOException
| KeyStoreException
| NoSuchProviderException
Expand Down
Loading

0 comments on commit dab6d3f

Please sign in to comment.