Repository navigation
Expand file tree
/
Copy pathProposalStore.java
More file actions
57 lines (49 loc) · 1.51 KB
/
Copy pathProposalStore.java
File metadata and controls
57 lines (49 loc) · 1.51 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
package org.tron.core.db;
import java.util.List;
import java.util.stream.Collectors;
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.ProposalCapsule;
import org.tron.core.exception.ItemNotFoundException;
@Component
public class ProposalStore extends TronStoreWithRevoking<ProposalCapsule> {
@Autowired
public ProposalStore(@Value("proposal") String dbName) {
super(dbName);
}
@Override
public ProposalCapsule get(byte[] key) throws ItemNotFoundException {
byte[] value = dbSource.getData(key);
if (ArrayUtils.isEmpty(value)) {
throw new ItemNotFoundException();
}
return new ProposalCapsule(value);
}
@Override
public boolean has(byte[] key) {
byte[] account = dbSource.getData(key);
return null != account;
}
@Override
public void put(byte[] key, ProposalCapsule item) {
super.put(key, item);
}
/**
* get all witnesses.
*/
public List<ProposalCapsule> getAllProposals() {
return dbSource
.allValues()
.stream()
.map(bytes -> new ProposalCapsule(bytes))
.sorted(
(ProposalCapsule a, ProposalCapsule b) -> a.getCreateTime() <= b.getCreateTime() ?
1 : -1)
.collect(Collectors.toList());
}
public org.tron.core.db.common.iterator.DBIterator getIterator() {
return dbSource.iterator();
}
}