forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContractStore.java
More file actions
executable file
·70 lines (57 loc) · 1.57 KB
/
ContractStore.java
File metadata and controls
executable file
·70 lines (57 loc) · 1.57 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
package org.tron.core.db;
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.ContractCapsule;
import org.tron.protos.Protocol.SmartContract;
@Slf4j
@Component
public class ContractStore extends TronStoreWithRevoking<ContractCapsule> {
@Autowired
private ContractStore(@Value("contract") String dbName) {
super(dbName);
}
@Override
public ContractCapsule get(byte[] key) {
return getUnchecked(key);
}
/**
* get total transaction.
*/
public long getTotalContracts() {
return Streams.stream(revokingDB.iterator()).count();
}
private static ContractStore instance;
public static void destory() {
instance = null;
}
void destroy() {
instance = null;
}
/**
* find a transaction by it's id.
*/
public byte[] findContractByHash(byte[] trxHash) {
return revokingDB.getUnchecked(trxHash);
}
/**
*
* @param contractAddress
* @return
*/
public SmartContract.ABI getABI(byte[] contractAddress) {
byte[] value = revokingDB.getUnchecked(contractAddress);
if (ArrayUtils.isEmpty(value)) {
return null;
}
ContractCapsule contractCapsule = new ContractCapsule(value);
SmartContract smartContract = contractCapsule.getInstance();
if (smartContract == null) {
return null;
}
return smartContract.getAbi();
}
}