Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7ea0526

Browse files
[3.0.0-SNAPSHOT]
Added JdkEthHttpClient gzip/deflate protocol support Added EthScanAPIBuilder key required Fixed JdkEthHttpClient fallback to UrlEthHttpClient cause content-length works incorrectly Updated test and fixed
1 parent 260899b commit 7ea0526

File tree

10 files changed

+62
-66
lines changed

10 files changed

+62
-66
lines changed

‎.github/workflows/master.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI Master
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
schedule:
8+
- cron: 0 0 * * 0
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
java: [ '11', '17' ]
16+
name: Master Java ${{ matrix.java }} action
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up JDK
21+
uses: actions/setup-java@v3
22+
with:
23+
java-version: ${{ matrix.java }}
24+
distribution: 'adopt'
25+
26+
- name: Build
27+
run: './gradlew classes'
28+
29+
- name: Test
30+
run: './gradlew test jacocoTestReport'
31+
32+
- name: SonarQube
33+
if: matrix.java == '17'
34+
run: './gradlew sonar --info'
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

‎.github/workflows/publish-release.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Master
1+
name: Release
22

33
on:
44
release:
@@ -22,8 +22,6 @@ jobs:
2222

2323
- name: Test
2424
run: './gradlew test jacocoTestReport'
25-
env:
26-
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY_2 }}
2725

2826
- name: SonarQube
2927
run: './gradlew sonar --info'

‎.github/workflows/publish-snapshot.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Dev
1+
name: Snapshot
22

33
on:
44
push:
@@ -32,8 +32,6 @@ jobs:
3232

3333
- name: Test
3434
run: './gradlew test jacocoTestReport'
35-
env:
36-
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY_2 }}
3735

3836
- name: Publish Snapshot
3937
run: './gradlew publish'

‎.github/workflows/pull-request.yml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
java: [ '11', '17' ]
15-
name: Java ${{ matrix.java }} Pull Request setup
15+
name: Pull Request Java ${{ matrix.java }} action
1616

1717
steps:
1818
- uses: actions/checkout@v3
@@ -29,23 +29,7 @@ jobs:
2929
run: './gradlew classes'
3030

3131
- name: Test
32-
if: matrix.java == '11'
3332
run: './gradlew test jacocoTestReport'
34-
env:
35-
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY_1 }}
36-
37-
- name: Test
38-
if: matrix.java == '17'
39-
run: './gradlew test jacocoTestReport'
40-
env:
41-
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY_2 }}
42-
43-
- name: Test Report
44-
if: matrix.java == '17'
45-
uses: EnricoMi/publish-unit-test-result-action@v2
46-
with:
47-
files: |
48-
**/test-results/**/*.xml
4933

5034
- name: SonarQube
5135
if: matrix.java == '17'

‎build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test {
3535
testLogging {
3636
events("passed", "skipped", "failed")
3737
exceptionFormat("full")
38-
showStandardStreams(false)
38+
showStandardStreams(true)
3939
}
4040

4141
reports {
@@ -71,8 +71,8 @@ nexusPublishing {
7171
sonatype {
7272
username = System.getenv("OSS_USERNAME")
7373
password = System.getenv("OSS_PASSWORD")
74-
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
75-
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
74+
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
75+
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
7676
}
7777
}
7878
}
@@ -110,8 +110,8 @@ publishing {
110110
}
111111
repositories {
112112
maven {
113-
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
114-
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
113+
def releasesRepoUrl = "https://ossrh-staging-api.central.sonatype.com/service/local/"
114+
def snapshotsRepoUrl = "https://central.sonatype.com/repository/maven-snapshots/"
115115
url = version.endsWith("SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl
116116
credentials {
117117
username System.getenv("OSS_USERNAME")

‎src/main/java/io/goodforgod/api/etherscan/http/impl/JdkEthHttpClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class JdkEthHttpClient implements EthHttpClient {
4242
private final HttpClient httpClient;
4343
private final Duration requestTimeout;
4444
private final Map<String, String> headers;
45+
private final UrlEthHttpClient urlEthHttpClient;
4546

4647
public JdkEthHttpClient() {
4748
this(HttpClient.newBuilder()
@@ -65,6 +66,7 @@ public JdkEthHttpClient(HttpClient httpClient, Duration requestTimeout, Map<Stri
6566
this.httpClient = httpClient;
6667
this.requestTimeout = requestTimeout;
6768
this.headers = headers;
69+
this.urlEthHttpClient = new UrlEthHttpClient(DEFAULT_CONNECT_TIMEOUT, requestTimeout, headers);
6870
}
6971

7072
@Override
@@ -111,12 +113,19 @@ public byte[] body() {
111113

112114
@Override
113115
public EthResponse post(@NotNull URI uri, byte[] body) {
116+
return urlEthHttpClient.post(uri, body);
117+
}
118+
119+
// content-length somehow is not working properly and can't force user to override
120+
// "jdk.httpclient.allowRestrictedHeaders" prop, so will force use UrlEthHttpClient
121+
private EthResponse postJdk(@NotNull URI uri, byte[] body) {
114122
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
115123
.POST(HttpRequest.BodyPublishers.ofByteArray(body))
116124
.uri(uri)
117125
.timeout(requestTimeout);
118126

119127
headers.forEach(requestBuilder::header);
128+
requestBuilder.header("Content-Type", "application/json; charset=UTF-8");
120129

121130
try {
122131
HttpResponse<InputStream> response = httpClient.send(requestBuilder.build(),

‎src/main/java/io/goodforgod/api/etherscan/model/GasOracle.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.goodforgod.api.etherscan.model;
22

33
import java.math.BigDecimal;
4-
import java.math.BigInteger;
54
import java.util.Arrays;
65
import java.util.List;
76
import java.util.Objects;
@@ -14,9 +13,9 @@
1413
public class GasOracle {
1514

1615
private Long LastBlock;
17-
private BigInteger SafeGasPrice;
18-
private BigInteger ProposeGasPrice;
19-
private BigInteger FastGasPrice;
16+
private BigDecimal SafeGasPrice;
17+
private BigDecimal ProposeGasPrice;
18+
private BigDecimal FastGasPrice;
2019
private BigDecimal suggestBaseFee;
2120
private String gasUsedRatio;
2221

@@ -129,13 +128,13 @@ public GasOracle build() {
129128
gasOracle.LastBlock = this.lastBlock;
130129
gasOracle.suggestBaseFee = this.suggestBaseFee;
131130
if (this.proposeGasPrice != null) {
132-
gasOracle.ProposeGasPrice = this.proposeGasPrice.asGwei().toBigInteger();
131+
gasOracle.ProposeGasPrice = this.proposeGasPrice.asGwei();
133132
}
134133
if (this.safeGasPrice != null) {
135-
gasOracle.SafeGasPrice = this.safeGasPrice.asGwei().toBigInteger();
134+
gasOracle.SafeGasPrice = this.safeGasPrice.asGwei();
136135
}
137136
if (this.fastGasPrice != null) {
138-
gasOracle.FastGasPrice = this.fastGasPrice.asGwei().toBigInteger();
137+
gasOracle.FastGasPrice = this.fastGasPrice.asGwei();
139138
}
140139
if (this.gasUsedRatio != null) {
141140
gasOracle.gasUsedRatio = this.gasUsedRatio.stream()

‎src/test/java/io/goodforgod/api/etherscan/EtherScanAPITests.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.goodforgod.api.etherscan.error.EtherScanKeyException;
55
import io.goodforgod.api.etherscan.http.EthHttpClient;
66
import io.goodforgod.api.etherscan.http.impl.UrlEthHttpClient;
7-
import io.goodforgod.api.etherscan.model.Balance;
87
import java.net.URI;
98
import java.time.Duration;
109
import java.util.concurrent.TimeUnit;
@@ -37,33 +36,6 @@ void blankKey() {
3736
() -> EtherScanAPI.builder("someKey").withApiKey(" ").withNetwork(network).build());
3837
}
3938

40-
@Test
41-
void noTimeoutOnRead() {
42-
Supplier<EthHttpClient> supplier = () -> new UrlEthHttpClient(Duration.ofMillis(300));
43-
EtherScanAPI api = EtherScanAPI.builder(ApiRunner.getKey()).withNetwork(EthNetworks.MAINNET).withHttpClient(supplier)
44-
.build();
45-
Balance balance = api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
46-
assertNotNull(balance);
47-
}
48-
49-
@Test
50-
void noTimeoutOnReadGroli() {
51-
Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
52-
assertNotNull(balance);
53-
}
54-
55-
@Test
56-
void noTimeoutOnReadTobalala() {
57-
Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
58-
assertNotNull(balance);
59-
}
60-
61-
@Test
62-
void noTimeoutUnlimitedAwait() {
63-
Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
64-
assertNotNull(balance);
65-
}
66-
6739
@Test
6840
void timeout() throws InterruptedException {
6941
TimeUnit.SECONDS.sleep(5);

‎src/test/java/io/goodforgod/api/etherscan/account/AccountTxsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AccountTxsTests extends ApiRunner {
1616
void correct() {
1717
List<Tx> txs = getApi().account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9");
1818
assertNotNull(txs);
19-
assertEquals(5, txs.size());
19+
assertEquals(6, txs.size());
2020
assertTxs(txs);
2121
assertNotNull(txs.get(0).getTimeStamp());
2222
assertNotNull(txs.get(0).getHash());
@@ -39,7 +39,7 @@ void correct() {
3939
void correctStartBlock() {
4040
List<Tx> txs = getApi().account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9", 3892842);
4141
assertNotNull(txs);
42-
assertEquals(4, txs.size());
42+
assertEquals(5, txs.size());
4343
assertTxs(txs);
4444
}
4545

‎src/test/java/io/goodforgod/api/etherscan/proxy/ProxyBlockApiTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void correct() {
2222
assertNotNull(proxy.getStateRoot());
2323
assertNotNull(proxy.getSize());
2424
assertNotNull(proxy.getDifficulty());
25-
assertNotNull(proxy.getTotalDifficulty());
2625
assertNotNull(proxy.getTimeStamp());
2726
assertNotNull(proxy.getMiner());
2827
assertNotNull(proxy.getNonce());

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /