forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockIndexStore.java
More file actions
45 lines (36 loc) · 1.32 KB
/
BlockIndexStore.java
File metadata and controls
45 lines (36 loc) · 1.32 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
package org.tron.core.db;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.capsule.BlockCapsule.BlockId;
import org.tron.core.capsule.BytesCapsule;
import org.tron.core.exception.ItemNotFoundException;
import java.util.Arrays;
@Component
public class BlockIndexStore extends TronStoreWithRevoking<BytesCapsule> {
@Autowired
public BlockIndexStore(@Value("block-index") String dbName) {
super(dbName);
}
public void put(BlockId id) {
put(ByteArray.fromLong(id.getNum()), new BytesCapsule(id.getBytes()));
}
public BlockId get(Long num)
throws ItemNotFoundException {
return new BlockId(Sha256Hash.wrap(getUnchecked(ByteArray.fromLong(num)).getData()),
num);
}
@Override
public BytesCapsule get(byte[] key)
throws ItemNotFoundException {
byte[] value = revokingDB.getUnchecked(key);
if (ArrayUtils.isEmpty(value)) {
throw new ItemNotFoundException("number: " + Arrays.toString(key) + " is not found!");
}
return new BytesCapsule(value);
}
}