Repository navigation
Expand file tree
/
Copy pathContractStore.java
More file actions
executable file
·79 lines (64 loc) · 1.78 KB
/
Copy pathContractStore.java
File metadata and controls
executable file
·79 lines (64 loc) · 1.78 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
71
72
73
74
75
76
77
78
79
package org.tron.core.db;
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.Contract.CreateSmartContract;
import org.tron.protos.Protocol;
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) {
byte[] value = dbSource.getData(key);
return ArrayUtils.isEmpty(value) ? null : new ContractCapsule(value);
}
@Override
public boolean has(byte[] key) {
byte[] contract = dbSource.getData(key);
return null != contract;
}
/**
* get total transaction.
*/
public long getTotalContracts() {
return dbSource.getTotal();
}
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 dbSource.getData(trxHash);
}
/**
*
* @param contractAddress
* @return
*/
public SmartContract.ABI getABI(byte[] contractAddress) {
byte[] value = dbSource.getData(contractAddress);
if (ArrayUtils.isEmpty(value)) {
return null;
}
ContractCapsule contractCapsule = new ContractCapsule(value);
SmartContract smartContract = contractCapsule.getInstance();
if (smartContract == null) {
return null;
}
return smartContract.getAbi();
}
}