forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexHelper.java
More file actions
138 lines (111 loc) · 3.11 KB
/
IndexHelper.java
File metadata and controls
138 lines (111 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package org.tron.core.db.api;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.capsule.AssetIssueCapsule;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.capsule.WitnessCapsule;
import org.tron.core.db.api.index.Index;
import org.tron.protos.Contract.AssetIssueContract;
import org.tron.protos.Protocol.Account;
import org.tron.protos.Protocol.Block;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Witness;
@Slf4j
public class IndexHelper {
@Getter
@Resource
private Index.Iface<Transaction> transactionIndex;
@Getter
@Resource
private Index.Iface<Block> blockIndex;
@Getter
@Resource
private Index.Iface<Witness> witnessIndex;
@Getter
@Resource
private Index.Iface<Account> accountIndex;
@Getter
@Resource
private Index.Iface<AssetIssueContract> assetIssueIndex;
@PostConstruct
public void init() {
transactionIndex.fill();
//blockIndex.fill();
//witnessIndex.fill();
//accountIndex.fill();
//assetIssueIndex.fill();
}
private <T> void add(Index.Iface<T> index, byte[] bytes) {
index.add(bytes);
}
public void add(Transaction t) {
add(transactionIndex, getKey(t));
}
public void add(Block b) {
//add(blockIndex, getKey(b));
}
public void add(Witness w) {
//add(witnessIndex, getKey(w));
}
public void add(Account a) {
//add(accountIndex, getKey(a));
}
public void add(AssetIssueContract a) {
//add(assetIssueIndex, getKey(a));
}
private <T> void update(Index.Iface<T> index, byte[] bytes) {
index.update(bytes);
}
public void update(Transaction t) {
update(transactionIndex, getKey(t));
}
public void update(Block b) {
// update(blockIndex, getKey(b));
}
public void update(Witness w) {
//update(witnessIndex, getKey(w));
}
public void update(Account a) {
//update(accountIndex, getKey(a));
}
public void update(AssetIssueContract a) {
//update(assetIssueIndex, getKey(a));
}
private <T> void remove(Index.Iface<T> index, byte[] bytes) {
index.remove(bytes);
}
public void remove(Transaction t) {
remove(transactionIndex, getKey(t));
}
public void remove(Block b) {
//remove(blockIndex, getKey(b));
}
public void remove(Witness w) {
//remove(witnessIndex, getKey(w));
}
public void remove(Account a) {
//remove(accountIndex, getKey(a));
}
public void remove(AssetIssueContract a) {
//remove(assetIssueIndex, getKey(a));
}
private byte[] getKey(Transaction t) {
return new TransactionCapsule(t).getTransactionId().getBytes();
}
private byte[] getKey(Block b) {
return new BlockCapsule(b).getBlockId().getBytes();
}
private byte[] getKey(Witness w) {
return new WitnessCapsule(w).createDbKey();
}
private byte[] getKey(Account a) {
return new AccountCapsule(a).createDbKey();
}
private byte[] getKey(AssetIssueContract a) {
return new AssetIssueCapsule(a).createDbKey();
}
}