Movatterモバイル変換


[0]ホーム

URL:


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

Commit2df9d68

Browse files
committed
Make LogApi usage bug-free
1 parent0480bf3 commit2df9d68

File tree

40 files changed

+1395
-257
lines changed

40 files changed

+1395
-257
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
packageio.api.etherscan.model;
2+
3+
importio.api.etherscan.util.BasicUtils;
4+
5+
importjava.util.Objects;
6+
7+
publicclassAddress {
8+
9+
privatefinalStringaddress;
10+
11+
privateAddress(Stringaddress) {
12+
this.address =address;
13+
}
14+
15+
publicstaticAddressof(Stringaddress) {
16+
BasicUtils.validateAddress(address);
17+
returnnewAddress(address);
18+
}
19+
20+
publicStringgetAddress() {
21+
returnaddress;
22+
}
23+
24+
publicStringto64Hex() {
25+
StringaddressWithoutOx =address.substring(2);
26+
return"0x" +padLeftZeros(addressWithoutOx);
27+
}
28+
29+
@Override
30+
publicbooleanequals(Objecto) {
31+
if (this ==o)returntrue;
32+
if (o ==null ||getClass() !=o.getClass())returnfalse;
33+
Addressother = (Address)o;
34+
returnaddress.equals(other.address);
35+
}
36+
37+
@Override
38+
publicinthashCode() {
39+
returnObjects.hash(address);
40+
}
41+
42+
privateStringpadLeftZeros(StringinputString) {
43+
if (inputString.length() >=64) {
44+
returninputString;
45+
}
46+
StringBuildersb =newStringBuilder();
47+
while (sb.length() <64 -inputString.length()) {
48+
sb.append('0');
49+
}
50+
sb.append(inputString);
51+
52+
returnsb.toString();
53+
}
54+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
packageio.api.etherscan.model.query;
2+
3+
importio.api.etherscan.model.Address;
4+
importio.api.etherscan.util.BasicUtils;
5+
6+
importjava.util.Objects;
7+
8+
publicclassLogTopic {
9+
10+
privatefinalStringhex;
11+
12+
privateLogTopic(Stringhex) {
13+
this.hex =hex;
14+
}
15+
16+
publicstaticLogTopicof(Addressaddress) {
17+
returnof(address.to64Hex());
18+
}
19+
20+
publicstaticLogTopicof(Stringhex) {
21+
BasicUtils.validateTxHash(hex);
22+
returnnewLogTopic(hex);
23+
}
24+
25+
publicStringgetHex() {
26+
returnhex;
27+
}
28+
29+
@Override
30+
publicbooleanequals(Objecto) {
31+
if (this ==o)returntrue;
32+
if (o ==null ||getClass() !=o.getClass())returnfalse;
33+
LogTopicother = (LogTopic)o;
34+
returnhex.equals(other.hex);
35+
}
36+
37+
@Override
38+
publicinthashCode() {
39+
returnObjects.hash(hex);
40+
}
41+
42+
}

‎src/main/java/io/api/etherscan/model/query/impl/LogQuery.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
packageio.api.etherscan.model.query.impl;
22

33
importio.api.etherscan.core.ILogsApi;
4+
importio.api.etherscan.model.query.impl.topic.TopicParams;
5+
importorg.jetbrains.annotations.NotNull;
46

57
/**
68
* Final builded container for The Event Log API
@@ -24,6 +26,10 @@ public class LogQuery {
2426
this.params =params;
2527
}
2628

29+
publicLogQuery(@NotNullStandardLogQueryParamsstandardLogQueryParams,@NotNullTopicParamstopicParams) {
30+
this.params =standardLogQueryParams.getApiParams() +topicParams.getApiParams();
31+
}
32+
2733
publicStringgetParams() {
2834
returnparams;
2935
}

‎src/main/java/io/api/etherscan/model/query/impl/LogQueryBuilder.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
importio.api.etherscan.core.ILogsApi;
44
importio.api.etherscan.error.LogQueryException;
55
importio.api.etherscan.model.query.IQueryBuilder;
6+
importio.api.etherscan.model.query.impl.topic.TopicParams;
67
importio.api.etherscan.util.BasicUtils;
8+
importorg.jetbrains.annotations.NotNull;
79

810
/**
911
* Builder for The Event Log API
@@ -40,12 +42,20 @@ public static LogQueryBuilder with(String address, long startBlock, long endBloc
4042
returnnewLogQueryBuilder(address,startBlock,endBlock);
4143
}
4244

45+
/**
46+
* @deprecated use {@link LogQueryBuilder#topic(TopicParams)}
47+
*/
48+
@Deprecated
4349
publicLogTopicSingletopic(Stringtopic0) {
4450
if (BasicUtils.isNotHex(topic0))
4551
thrownewLogQueryException("topic0 can not be empty or non hex.");
4652
returnnewLogTopicSingle(address,startBlock,endBlock,topic0);
4753
}
4854

55+
/**
56+
* @deprecated use {@link LogQueryBuilder#topic(TopicParams)}
57+
*/
58+
@Deprecated
4959
publicLogTopicTupletopic(Stringtopic0,Stringtopic1) {
5060
if (BasicUtils.isNotHex(topic0))
5161
thrownewLogQueryException("topic0 can not be empty or non hex.");
@@ -54,6 +64,10 @@ public LogTopicTuple topic(String topic0, String topic1) {
5464
returnnewLogTopicTuple(address,startBlock,endBlock,topic0,topic1);
5565
}
5666

67+
/**
68+
* @deprecated use {@link LogQueryBuilder#topic(TopicParams)}
69+
*/
70+
@Deprecated
5771
publicLogTopicTripletopic(Stringtopic0,Stringtopic1,Stringtopic2) {
5872
if (BasicUtils.isNotHex(topic0))
5973
thrownewLogQueryException("topic0 can not be empty or non hex.");
@@ -64,6 +78,10 @@ public LogTopicTriple topic(String topic0, String topic1, String topic2) {
6478
returnnewLogTopicTriple(address,startBlock,endBlock,topic0,topic1,topic2);
6579
}
6680

81+
/**
82+
* @deprecated use {@link LogQueryBuilder#topic(TopicParams)}
83+
*/
84+
@Deprecated
6785
publicLogTopicQuadrotopic(Stringtopic0,Stringtopic1,Stringtopic2,Stringtopic3) {
6886
if (BasicUtils.isNotHex(topic0))
6987
thrownewLogQueryException("topic0 can not be empty or non hex.");
@@ -77,6 +95,10 @@ public LogTopicQuadro topic(String topic0, String topic1, String topic2, String
7795
returnnewLogTopicQuadro(address,startBlock,endBlock,topic0,topic1,topic2,topic3);
7896
}
7997

98+
publicLogQueryWithTopicsBuildertopic(@NotNullTopicParamstopicParams) {
99+
returnnewLogQueryWithTopicsBuilder(newStandardLogQueryParams(address,startBlock,endBlock),topicParams);
100+
}
101+
80102
@Override
81103
publicLogQuerybuild()throwsLogQueryException {
82104
returnnewLogQuery("&address=" +this.address +"&fromBlock=" +this.startBlock +"&toBlock=" +this.endBlock);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packageio.api.etherscan.model.query.impl;
2+
3+
importio.api.etherscan.error.LogQueryException;
4+
importio.api.etherscan.model.query.IQueryBuilder;
5+
importio.api.etherscan.model.query.impl.topic.TopicParams;
6+
7+
publicclassLogQueryWithTopicsBuilderimplementsIQueryBuilder {
8+
9+
privatefinalStandardLogQueryParamsstandardLogQueryParams;
10+
privatefinalTopicParamstopicParams;
11+
12+
publicLogQueryWithTopicsBuilder(StandardLogQueryParamsstandardLogQueryParams,TopicParamstopicParams) {
13+
this.standardLogQueryParams =standardLogQueryParams;
14+
this.topicParams =topicParams;
15+
}
16+
17+
@Override
18+
publicLogQuerybuild()throwsLogQueryException {
19+
returnnewLogQuery(standardLogQueryParams,topicParams);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packageio.api.etherscan.model.query.impl;
2+
3+
publicclassStandardLogQueryParams {
4+
5+
privatefinalStringaddress;
6+
privatefinallongstartBlock;
7+
privatefinallongendBlock;
8+
9+
publicStandardLogQueryParams(Stringaddress,longstartBlock,longendBlock) {
10+
this.address =address;
11+
this.startBlock =startBlock;
12+
this.endBlock =endBlock;
13+
}
14+
15+
publicStringgetApiParams() {
16+
return"&address=" +address
17+
+"&fromBlock=" +startBlock
18+
+"&toBlock=" +endBlock;
19+
}
20+
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packageio.api.etherscan.model.query.impl.topic;
2+
3+
importio.api.etherscan.model.query.LogTopic;
4+
5+
publicabstractclassBaseTopic {
6+
7+
privatefinalTopicNrtopicNr;
8+
privatefinalLogTopiclogTopic;
9+
10+
publicBaseTopic(TopicNrtopicNr,LogTopiclogTopic) {
11+
this.topicNr =topicNr;
12+
this.logTopic =logTopic;
13+
}
14+
15+
publicStringgetApiParams() {
16+
returntopicNr.getTopicParam() +logTopic.getHex();
17+
}
18+
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packageio.api.etherscan.model.query.impl.topic;
2+
3+
enumTopicNr {
4+
TOPIC_0("&topic0="),
5+
TOPIC_1("&topic1="),
6+
TOPIC_2("&topic2="),
7+
TOPIC_3("&topic3=");
8+
9+
privatefinalStringtopicParam;
10+
11+
TopicNr(StringtopicParam) {
12+
this.topicParam =topicParam;
13+
}
14+
15+
publicStringgetTopicParam() {
16+
returntopicParam;
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
packageio.api.etherscan.model.query.impl.topic;
2+
3+
importio.api.etherscan.model.query.LogTopic;
4+
5+
publicclassTopicOneextendsBaseTopic{
6+
7+
publicTopicOne(LogTopiclogTopic) {
8+
super(TopicNr.TOPIC_1,logTopic);
9+
}
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
packageio.api.etherscan.model.query.impl.topic;
2+
3+
publicinterfaceTopicParams {
4+
5+
StringgetApiParams();
6+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp