Skip to content

Commit 62522ee

Browse files
authored
add event sub impl (#424)
1 parent f0c28c6 commit 62522ee

File tree

12 files changed

+266
-654
lines changed

12 files changed

+266
-654
lines changed

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/abi/tools/TopicTools.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.fisco.bcos.sdk.codec.abi.tools;
22

33
import java.math.BigInteger;
4+
import java.util.Objects;
5+
46
import org.fisco.bcos.sdk.codec.abi.TypeEncoder;
57
import org.fisco.bcos.sdk.codec.datatypes.Bytes;
68
import org.fisco.bcos.sdk.crypto.CryptoSuite;
@@ -10,7 +12,7 @@
1012
public class TopicTools {
1113

1214
public static final int MAX_NUM_TOPIC_EVENT_LOG = 4;
13-
public static final String LATEST = "latest";
15+
public static final int TOPIC_LENGTH = 64;
1416

1517
private final CryptoSuite cryptoSuite;
1618

@@ -22,6 +24,19 @@ public String integerToTopic(BigInteger i) {
2224
return Numeric.toHexStringWithPrefixZeroPadded(i, 64);
2325
}
2426

27+
public static boolean validTopic(String topic) {
28+
if (Objects.isNull(topic)) {
29+
return false;
30+
}
31+
32+
if (topic.startsWith("0x") || topic.startsWith("0X")) {
33+
return topic.length() == (TOPIC_LENGTH + 2);
34+
}
35+
36+
return topic.length() == TOPIC_LENGTH;
37+
}
38+
39+
2540
public String boolToTopic(boolean b) {
2641
if (b) {
2742
return Numeric.toHexStringWithPrefixZeroPadded(BigInteger.ONE, 64);

sdk-core/src/main/java/org/fisco/bcos/sdk/model/EventLog.java

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,35 @@
1717
import com.fasterxml.jackson.annotation.JsonIgnore;
1818
import java.math.BigInteger;
1919
import java.util.List;
20+
import java.util.Objects;
21+
2022
import org.fisco.bcos.sdk.utils.Numeric;
2123

2224
public class EventLog {
23-
private boolean removed;
2425
private String logIndex;
2526
private String transactionIndex;
2627
private String transactionHash;
27-
private String blockHash;
2828
private String blockNumber;
2929
private String address;
3030
private String data;
31-
private String type;
3231
private List<String> topics;
3332

3433
public EventLog() {}
3534

3635
public EventLog(
37-
boolean removed,
3836
String logIndex,
3937
String transactionIndex,
4038
String transactionHash,
41-
String blockHash,
4239
String blockNumber,
4340
String address,
4441
String data,
45-
String type,
4642
List<String> topics) {
47-
this.removed = removed;
4843
this.logIndex = logIndex;
4944
this.transactionIndex = transactionIndex;
5045
this.transactionHash = transactionHash;
51-
this.blockHash = blockHash;
5246
this.blockNumber = blockNumber;
5347
this.address = address;
5448
this.data = data;
55-
this.type = type;
5649
this.topics = topics;
5750
}
5851

@@ -61,15 +54,6 @@ public EventLog(String data, List<String> topics) {
6154
this.topics = topics;
6255
}
6356

64-
@JsonIgnore
65-
public boolean isRemoved() {
66-
return removed;
67-
}
68-
69-
public void setRemoved(boolean removed) {
70-
this.removed = removed;
71-
}
72-
7357
public BigInteger getLogIndex() {
7458
return convert(logIndex);
7559
}
@@ -104,14 +88,6 @@ public void setTransactionHash(String transactionHash) {
10488
this.transactionHash = transactionHash;
10589
}
10690

107-
public String getBlockHash() {
108-
return blockHash;
109-
}
110-
111-
public void setBlockHash(String blockHash) {
112-
this.blockHash = blockHash;
113-
}
114-
11591
public BigInteger getBlockNumber() {
11692
return convert(blockNumber);
11793
}
@@ -141,15 +117,6 @@ public void setData(String data) {
141117
this.data = data;
142118
}
143119

144-
@JsonIgnore
145-
public String getType() {
146-
return type;
147-
}
148-
149-
public void setType(String type) {
150-
this.type = type;
151-
}
152-
153120
public List<String> getTopics() {
154121
return topics;
155122
}
@@ -177,9 +144,6 @@ public boolean equals(Object o) {
177144

178145
EventLog log = (EventLog) o;
179146

180-
if (isRemoved() != log.isRemoved()) {
181-
return false;
182-
}
183147
if (getLogIndexRaw() != null
184148
? !getLogIndexRaw().equals(log.getLogIndexRaw())
185149
: log.getLogIndexRaw() != null) {
@@ -195,11 +159,6 @@ public boolean equals(Object o) {
195159
: log.getTransactionHash() != null) {
196160
return false;
197161
}
198-
if (getBlockHash() != null
199-
? !getBlockHash().equals(log.getBlockHash())
200-
: log.getBlockHash() != null) {
201-
return false;
202-
}
203162
if (getBlockNumberRaw() != null
204163
? !getBlockNumberRaw().equals(log.getBlockNumberRaw())
205164
: log.getBlockNumberRaw() != null) {
@@ -213,49 +172,24 @@ public boolean equals(Object o) {
213172
if (getData() != null ? !getData().equals(log.getData()) : log.getData() != null) {
214173
return false;
215174
}
216-
if (getType() != null ? !getType().equals(log.getType()) : log.getType() != null) {
217-
return false;
218-
}
219175
return getTopics() != null ? getTopics().equals(log.getTopics()) : log.getTopics() == null;
220176
}
221177

222178
@Override
223179
public int hashCode() {
224-
int result = (isRemoved() ? 1 : 0);
225-
result = 31 * result + (getLogIndexRaw() != null ? getLogIndexRaw().hashCode() : 0);
226-
result =
227-
31 * result
228-
+ (getTransactionIndexRaw() != null
229-
? getTransactionIndexRaw().hashCode()
230-
: 0);
231-
result = 31 * result + (getTransactionHash() != null ? getTransactionHash().hashCode() : 0);
232-
result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0);
233-
result = 31 * result + (getBlockNumberRaw() != null ? getBlockNumberRaw().hashCode() : 0);
234-
result = 31 * result + (getAddress() != null ? getAddress().hashCode() : 0);
235-
result = 31 * result + (getData() != null ? getData().hashCode() : 0);
236-
result = 31 * result + (getType() != null ? getType().hashCode() : 0);
237-
result = 31 * result + (getTopics() != null ? getTopics().hashCode() : 0);
238-
return result;
180+
return Objects.hash(logIndex, transactionIndex, transactionHash, blockNumber, address, data, topics);
239181
}
240182

241183
@Override
242184
public String toString() {
243-
return "Log [logIndex="
244-
+ logIndex
245-
+ ", transactionIndex="
246-
+ transactionIndex
247-
+ ", transactionHash="
248-
+ transactionHash
249-
+ ", blockHash="
250-
+ blockHash
251-
+ ", blockNumber="
252-
+ blockNumber
253-
+ ", address="
254-
+ address
255-
+ ", data="
256-
+ data
257-
+ ", topics="
258-
+ topics
259-
+ "]";
185+
return "EventLog{" +
186+
"logIndex='" + logIndex + '\'' +
187+
", transactionIndex='" + transactionIndex + '\'' +
188+
", transactionHash='" + transactionHash + '\'' +
189+
", blockNumber='" + blockNumber + '\'' +
190+
", address='" + address + '\'' +
191+
", data='" + data + '\'' +
192+
", topics=" + topics +
193+
'}';
260194
}
261195
}

0 commit comments

Comments
 (0)