Skip to content

Commit

Permalink
Merge branch 'web3j:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
1329576606 authored Sep 13, 2023
2 parents 044b8a2 + e4e1dd7 commit 18758b2
Show file tree
Hide file tree
Showing 39 changed files with 3,475 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build
run: ./gradlew check jacocoRootTestReport
run: ./gradlew test
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
57 changes: 57 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "CodeQL"

on:
push:
branches: [ 'master' ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ 'master' ]
schedule:
- cron: '35 2 * * 3'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'java' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Build
run: ./gradlew test

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Java:
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.9.8</version>
<version>4.10.3</version>
</dependency>
```

Expand Down
15 changes: 0 additions & 15 deletions abi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,3 @@ dependencies {

tasks.named("spotlessJava").configure { dependsOn("spotlessGroovyGradle","compileJava","compileTestJava","javadoc","test") }
tasks.named("spotlessKotlin").configure { dependsOn("compileJava","spotlessJava", "spotlessGroovyGradle","compileTestJava","processTestResources","javadoc","test") }
tasks.named("jacocoRootTestReport").configure { dependsOn("compileJava","compileTestJava","javadoc","test", "spotlessGroovyGradle", "spotlessKotlin","spotlessJava") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":besu:compileJava",":besu:compileTestJava",":besu:javadoc",":besu:test", ":besu:spotlessGroovyGradle", ":besu:spotlessJava",":besu:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":test",":spotlessGroovyGradle",":spotlessJava",":spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":codegen:compileJava",":codegen:compileTestJava",":codegen:javadoc",":codegen:test",":codegen:processTestResources",":codegen:spotlessGroovyGradle", ":codegen:spotlessJava",":codegen:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":contracts:compileJava",":contracts:javadoc",":contracts:test",":contracts:processResources",":contracts:spotlessGroovyGradle", ":contracts:spotlessJava",":contracts:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":core:javadoc",":core:test",":core:spotlessGroovyGradle", ":core:spotlessJava",":core:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":crypto:javadoc",":crypto:test",":crypto:spotlessGroovyGradle", ":crypto:spotlessJava",":crypto:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":eea:compileTestJava",":eea:javadoc",":eea:test",":eea:spotlessGroovyGradle", ":eea:spotlessJava",":eea:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":geth:compileJava",":geth:compileTestJava",":geth:javadoc",":geth:test",":geth:spotlessGroovyGradle", ":geth:spotlessJava",":geth:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":hosted-providers:compileJava",":hosted-providers:compileTestJava",":hosted-providers:javadoc",":hosted-providers:test",":hosted-providers:spotlessGroovyGradle", ":hosted-providers:spotlessJava",":hosted-providers:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":integration-tests:compileTestJava",":integration-tests:processTestResources",":integration-tests:spotlessGroovyGradle", ":integration-tests:spotlessJava",":integration-tests:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":parity:compileJava",":parity:compileTestJava",":parity:javadoc",":parity:test",":parity:spotlessGroovyGradle", ":parity:spotlessJava",":parity:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":rlp:compileTestJava",":rlp:javadoc",":rlp:test",":rlp:spotlessGroovyGradle", ":rlp:spotlessJava",":rlp:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":tuples:javadoc",":tuples:test",":tuples:spotlessGroovyGradle", ":tuples:spotlessJava",":tuples:spotlessKotlin") }
tasks.named("jacocoRootTestReport").configure { dependsOn(":utils:javadoc",":utils:test",":utils:spotlessGroovyGradle", ":utils:spotlessJava",":utils:spotlessKotlin") }
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java'
id 'idea'
id 'org.sonarqube' version '3.4.0.2513'
id 'jacoco'
id 'com.diffplug.gradle.spotless' version '4.5.1'
id 'io.codearte.nexus-staging' version '0.22.0'
Expand All @@ -23,10 +24,11 @@ ext {
slf4jVersion = '1.7.30'
javaWebSocketVersion = '1.5.3'
picocliVersion = '3.0.0'
ensAdraffyVersion = '0.1.2'
// test dependencies
equalsverifierVersion = '3.14.1'
junitVersion = '5.5.2'
web3jUnitVersion = '4.10.0'
web3jUnitVersion = '4.10.2'
junitBenchmarkVersion = '0.7.2'
logbackVersion = '1.2.3'
mockitoJunitVersion = '3.1.0'
Expand Down Expand Up @@ -97,5 +99,6 @@ configure(subprojects.findAll { it.name != 'integration-tests' }) {
apply from: "$rootDir/gradle/jacoco/build.gradle"
}


tasks.named("spotlessJava").configure { dependsOn("spotlessGroovyGradle") }
tasks.named("spotlessKotlin").configure { dependsOn("spotlessJava", "spotlessGroovyGradle") }
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -47,13 +48,25 @@ public CompilerClassLoader(final File outputDir, final URL... urls) {

@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
return compileClass(name)
.flatMap(this::readBytes)
.map(bytes -> defineClass(name, bytes, 0, bytes.length))
List<Class<?>> loadedClasses =
compileClass(name).stream()
.map(
classFile -> {
Optional<byte[]> bytes = readBytes(classFile);
return defineClass(
extractClassName(classFile.toString()),
bytes.get(),
0,
bytes.get().length);
})
.collect(Collectors.toList());
return loadedClasses.stream()
.filter(c -> c.getName().equals(name))
.findFirst()
.orElseThrow(() -> new ClassNotFoundException(name));
}

private Optional<File> compileClass(final String name) {
private List<File> compileClass(final String name) {

final String path = name.replace(".", File.separator);
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
Expand All @@ -79,7 +92,7 @@ private Optional<File> compileClass(final String name) {
}

if (!sourceFile.exists()) {
return Optional.empty();
return List.of();
}

final Iterable<? extends JavaFileObject> javaFileObjects =
Expand All @@ -93,8 +106,27 @@ private Optional<File> compileClass(final String name) {
final CompilationTask task =
compiler.getTask(null, null, System.err::println, options, null, javaFileObjects);

final File classFile = new File(outputDir, path + ".class");
return task.call() ? Optional.of(classFile) : Optional.empty();
if (task.call()) {
try {
return Files.walk(Paths.get(outputDir.getAbsoluteFile().toURI()))
.filter(Files::isRegularFile)
.filter(
filePath -> {
String fileName = extractClassName(filePath.toString());
return fileName.startsWith(name);
})
.map(Path::toFile)
.toList();
} catch (IOException e) {
throw new IllegalStateException("Unable to process compiled classes: ", e);
}
}
return List.of();
}

private String extractClassName(final String pathName) {
return pathName.substring(outputDir.toString().length() + 1, pathName.lastIndexOf("."))
.replaceAll("/", ".");
}

private String buildClassPath() {
Expand Down
3 changes: 2 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ dependencies {
"io.reactivex.rxjava2:rxjava:$rxjavaVersion",
"org.java-websocket:Java-WebSocket:$javaWebSocketVersion",
"com.fasterxml.jackson.core:jackson-databind:$jacksonVersion",
"org.slf4j:slf4j-api:$slf4jVersion"
"org.slf4j:slf4j-api:$slf4jVersion",
"io.github.adraffy:ens-normalize:$ensAdraffyVersion"
testImplementation project(path: ':crypto', configuration: 'testArtifacts'),
"nl.jqno.equalsverifier:equalsverifier:$equalsverifierVersion",
"ch.qos.logback:logback-classic:$logbackVersion"
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/web3j/crypto/Bip44WalletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.File;
import java.io.IOException;

import org.web3j.crypto.exception.CipherException;

import static org.web3j.crypto.Bip32ECKeyPair.HARDENED_BIT;

public class Bip44WalletUtils extends WalletUtils {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/web3j/crypto/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bouncycastle.crypto.generators.SCrypt;
import org.bouncycastle.crypto.params.KeyParameter;

import org.web3j.crypto.exception.CipherException;
import org.web3j.utils.Numeric;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/web3j/crypto/WalletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.web3j.crypto.exception.CipherException;
import org.web3j.utils.Numeric;

import static org.web3j.crypto.Hash.sha256;
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/org/web3j/ens/NameHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.IDN;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import io.github.adraffy.ens.ENSNormalize;
import io.github.adraffy.ens.InvalidLabelException;

import org.web3j.crypto.Hash;
import org.web3j.utils.Numeric;

Expand Down Expand Up @@ -58,16 +60,16 @@ private static byte[] nameHash(String[] labels) {

/**
* Normalise ENS name as per the <a
* href="http://docs.ens.domains/en/latest/implementers.html#normalising-and-validating-names">specification</a>.
* href="https://docs.ens.domains/ens-improvement-proposals/ensip-15-normalization-standard">specification</a>.
*
* @param ensName our user input ENS name
* @return normalised ens name
* @throws EnsResolutionException if the name cannot be normalised
*/
public static String normalise(String ensName) {
try {
return IDN.toASCII(ensName, IDN.USE_STD3_ASCII_RULES).toLowerCase();
} catch (IllegalArgumentException e) {
return ENSNormalize.ENSIP15.normalize(ensName);
} catch (InvalidLabelException e) {
throw new EnsResolutionException("Invalid ENS name provided: " + ensName);
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/web3j/protocol/core/Ethereum.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.web3j.protocol.core.methods.response.DbPutHex;
import org.web3j.protocol.core.methods.response.DbPutString;
import org.web3j.protocol.core.methods.response.EthAccounts;
import org.web3j.protocol.core.methods.response.EthBaseFee;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.core.methods.response.EthChainId;
Expand All @@ -39,6 +40,7 @@
import org.web3j.protocol.core.methods.response.EthGetBlockTransactionCountByNumber;
import org.web3j.protocol.core.methods.response.EthGetCode;
import org.web3j.protocol.core.methods.response.EthGetCompilers;
import org.web3j.protocol.core.methods.response.EthGetProof;
import org.web3j.protocol.core.methods.response.EthGetStorageAt;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
import org.web3j.protocol.core.methods.response.EthGetTransactionReceipt;
Expand Down Expand Up @@ -112,6 +114,8 @@ public interface Ethereum {

Request<?, EthMaxPriorityFeePerGas> ethMaxPriorityFeePerGas();

Request<?, EthBaseFee> ethBaseFee();

Request<?, EthFeeHistory> ethFeeHistory(
int blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles);

Expand Down Expand Up @@ -202,6 +206,8 @@ Request<?, EthBlock> ethGetUncleByBlockNumberAndIndex(

Request<?, EthLog> ethGetLogs(org.web3j.protocol.core.methods.request.EthFilter ethFilter);

Request<?, EthGetProof> ethGetProof(String address, List<String> storageKeys, String quantity);

Request<?, EthGetWork> ethGetWork();

Request<?, EthSubmitWork> ethSubmitWork(String nonce, String headerPowHash, String mixDigest);
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/java/org/web3j/protocol/core/JsonRpc2_0Web3j.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.web3j.protocol.core.methods.response.DbPutHex;
import org.web3j.protocol.core.methods.response.DbPutString;
import org.web3j.protocol.core.methods.response.EthAccounts;
import org.web3j.protocol.core.methods.response.EthBaseFee;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.core.methods.response.EthChainId;
Expand All @@ -51,6 +52,7 @@
import org.web3j.protocol.core.methods.response.EthGetBlockTransactionCountByNumber;
import org.web3j.protocol.core.methods.response.EthGetCode;
import org.web3j.protocol.core.methods.response.EthGetCompilers;
import org.web3j.protocol.core.methods.response.EthGetProof;
import org.web3j.protocol.core.methods.response.EthGetStorageAt;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
import org.web3j.protocol.core.methods.response.EthGetTransactionReceipt;
Expand Down Expand Up @@ -233,6 +235,12 @@ public Request<?, EthMaxPriorityFeePerGas> ethMaxPriorityFeePerGas() {
EthMaxPriorityFeePerGas.class);
}

@Override
public Request<?, EthBaseFee> ethBaseFee() {
return new Request<>(
"eth_baseFee", Collections.<String>emptyList(), web3jService, EthBaseFee.class);
}

@Override
public Request<?, EthFeeHistory> ethFeeHistory(
int blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles) {
Expand Down Expand Up @@ -568,6 +576,16 @@ public Request<?, EthLog> ethGetLogs(
return new Request<>("eth_getLogs", Arrays.asList(ethFilter), web3jService, EthLog.class);
}

@Override
public Request<?, EthGetProof> ethGetProof(
String address, List<String> storageKeys, String quantity) {
return new Request<>(
"eth_getProof",
Arrays.asList(address, storageKeys, quantity),
web3jService,
EthGetProof.class);
}

@Override
public Request<?, EthGetWork> ethGetWork() {
return new Request<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ private void pollFilter(EthFilter ethFilter) {
protected abstract void process(List<EthLog.LogResult> logResults);

private void reinstallFilter() {
log.warn("The filter has not been found. Filter id: " + filterId);
log.warn(
"Previously installed filter has not been found, trying to re-install. Filter id: {}",
filterId);
schedule.cancel(false);
this.run(scheduledExecutorService, blockTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;

import org.web3j.protocol.core.DefaultBlockParameter;

/**
Expand Down Expand Up @@ -71,6 +73,7 @@ public List<String> getAddress() {
}

@Override
@JsonIgnore
EthFilter getThis() {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.web3j.protocol.core.methods.request;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* Filter implementation as per <a
* href="https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter">docs</a>
Expand All @@ -29,6 +31,7 @@ public String getTo() {
}

@Override
@JsonIgnore
ShhFilter getThis() {
return this;
}
Expand Down
Loading

0 comments on commit 18758b2

Please sign in to comment.