forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetIssueStore.java
More file actions
69 lines (57 loc) · 2.07 KB
/
AssetIssueStore.java
File metadata and controls
69 lines (57 loc) · 2.07 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
package org.tron.core.db;
import static org.tron.core.config.Parameter.DatabaseConstants.ASSET_ISSUE_COUNT_LIMIT_MAX;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import com.google.common.collect.Streams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.capsule.AssetIssueCapsule;
@Slf4j
@Component
public class AssetIssueStore extends TronStoreWithRevoking<AssetIssueCapsule> {
@Autowired
private AssetIssueStore(@Value("asset-issue") String dbName) {
super(dbName);
}
@Override
public AssetIssueCapsule get(byte[] key) {
return super.getUnchecked(key);
}
/**
* get all asset issues.
*/
public List<AssetIssueCapsule> getAllAssetIssues() {
return Streams.stream(iterator())
.map(Entry::getValue)
.collect(Collectors.toList());
}
public List<AssetIssueCapsule> getAssetIssuesPaginated(long offset, long limit) {
if (limit < 0 || offset < 0) {
return null;
}
// return Streams.stream(iterator())
// .map(Entry::getValue)
// .sorted(Comparator.comparing(a -> a.getName().toStringUtf8(), String::compareTo))
// .skip(offset)
// .limit(Math.min(limit, ASSET_ISSUE_COUNT_LIMIT_MAX))
// .collect(Collectors.toList());
List<AssetIssueCapsule> assetIssueList = getAllAssetIssues();
if (assetIssueList.size() <= offset) {
return null;
}
assetIssueList.sort((o1, o2) -> {
if (o1.getName() != o2.getName()) {
return o1.getName().toStringUtf8().compareTo(o2.getName().toStringUtf8());
}
return Long.compare(o1.getOrder(), o2.getOrder());
});
limit = limit > ASSET_ISSUE_COUNT_LIMIT_MAX ? ASSET_ISSUE_COUNT_LIMIT_MAX : limit;
long end = offset + limit;
end = end > assetIssueList.size() ? assetIssueList.size() : end ;
return assetIssueList.subList((int)offset,(int)end);
}
}