Repository navigation
Expand file tree
/
Copy pathTransactionStore.java
More file actions
64 lines (55 loc) · 1.6 KB
/
Copy pathTransactionStore.java
File metadata and controls
64 lines (55 loc) · 1.6 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
package org.tron.core.db;
import java.util.Objects;
import com.google.common.collect.Streams;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.exception.BadItemException;
import org.tron.core.exception.StoreException;
@Slf4j
@Component
public class TransactionStore extends TronStoreWithRevoking<TransactionCapsule> {
@Autowired
private TransactionStore(@Value("trans") String dbName) {
super(dbName);
}
@Override
public void put(byte[] key, TransactionCapsule item) {
super.put(key, item);
if (Objects.nonNull(indexHelper)) {
indexHelper.update(item.getInstance());
}
}
@Override
public TransactionCapsule get(byte[] key) throws BadItemException {
byte[] value = revokingDB.getUnchecked(key);
return ArrayUtils.isEmpty(value) ? null : new TransactionCapsule(value);
}
/**
* get total transaction.
*/
public long getTotalTransactions() {
return Streams.stream(iterator()).count();
}
@Override
public void delete(byte[] key) {
deleteIndex(key);
super.delete(key);
}
private void deleteIndex(byte[] key) {
if (Objects.nonNull(indexHelper)) {
TransactionCapsule item;
try {
item = get(key);
if (Objects.nonNull(item)) {
indexHelper.remove(item.getInstance());
}
} catch (StoreException e) {
return;
}
}
}
}