1
1
package org .tron .core .services ;
2
2
3
+ import com .google .common .collect .Maps ;
3
4
import java .util .HashMap ;
4
5
import java .util .Map ;
6
+ import java .util .Map .Entry ;
5
7
import java .util .Objects ;
8
+ import java .util .stream .Collectors ;
6
9
import javax .annotation .PostConstruct ;
10
+ import lombok .Getter ;
7
11
import lombok .extern .slf4j .Slf4j ;
8
- import org .apache .commons .collections4 .CollectionUtils ;
9
12
import org .apache .commons .collections4 .MapUtils ;
13
+ import org .springframework .beans .factory .annotation .Autowired ;
10
14
import org .springframework .stereotype .Component ;
11
15
import org .tron .common .utils .ByteArray ;
12
- import org .tron .common .utils .ForkController ;
13
16
import org .tron .core .Wallet ;
14
17
import org .tron .core .capsule .TransactionCapsule ;
15
18
import org .tron .core .config .Parameter .ForkBlockVersionEnum ;
16
- import org .tron .core .config . args . Args ;
19
+ import org .tron .core .db . Manager ;
17
20
import org .tron .core .db .common .WrappedByteArray ;
18
21
import org .tron .core .exception .WhitelistException ;
19
22
import org .tron .protos .Protocol .Transaction .Contract ;
23
26
@ Component
24
27
@ Slf4j
25
28
public class WhitelistService {
26
- private final static String TEST_FROM = "41ceee995c01c9bb7d720f9013336363cdc7c8c4d8" ;
27
- private final static String TEST_TO = "41216352a10649ffc3e37ba492feb0c35b3b6258e0" ;
28
29
private static Map <WrappedByteArray , WrappedByteArray > whitelist = new HashMap <>();
29
30
30
31
public WhitelistService () {
31
- // test
32
- whitelist .put (WrappedByteArray .of (ByteArray .fromHexString (TEST_FROM )),
33
- WrappedByteArray .of (ByteArray .fromHexString (TEST_TO )));
32
+ WhitelistTestCase .testMap .forEach ((k , v ) -> {
33
+ WrappedByteArray key = WrappedByteArray .of (ByteArray .fromHexString (k ));
34
+ WrappedByteArray value = WrappedByteArray .of (ByteArray .fromHexString (v ));
35
+ whitelist .put (key , value );
36
+ });
34
37
}
35
38
36
39
// TODO
@@ -44,7 +47,7 @@ public void loadFromConfig() {
44
47
}
45
48
46
49
public static void check (TransactionCapsule transactionCapsule ) throws WhitelistException {
47
- if (!ForkController .instance (). pass (ForkBlockVersionEnum .VERSION_3_5 )) {
50
+ if (!ForkController .pass (ForkBlockVersionEnum .VERSION_3_5 )) {
48
51
return ;
49
52
}
50
53
@@ -70,4 +73,47 @@ public static void check(TransactionCapsule transactionCapsule) throws Whitelist
70
73
+ ", to:" + (toAddress == null ? null : Wallet .encode58Check (toAddress )));
71
74
}
72
75
}
76
+
77
+ @ Component
78
+ public static class ForkController {
79
+
80
+ private static final byte VERSION_UPGRADE = (byte ) 1 ;
81
+
82
+ @ Getter
83
+ private static Manager manager ;
84
+
85
+ @ Autowired
86
+ public void setManager (Manager manager ) {
87
+ ForkController .manager = manager ;
88
+ }
89
+
90
+ public static boolean pass (ForkBlockVersionEnum forkBlockVersionEnum ) {
91
+ return pass (forkBlockVersionEnum .getValue ());
92
+ }
93
+
94
+ private static synchronized boolean pass (int version ) {
95
+ byte [] stats = manager .getDynamicPropertiesStore ().statsByVersion (version );
96
+ return check (stats );
97
+ }
98
+
99
+ private static boolean check (byte [] stats ) {
100
+ if (stats == null || stats .length == 0 ) {
101
+ return false ;
102
+ }
103
+
104
+ int count = 0 ;
105
+ for (int i = 0 ; i < stats .length ; i ++) {
106
+ if (VERSION_UPGRADE == stats [i ]) {
107
+ ++count ;
108
+ }
109
+ }
110
+
111
+ if (count >= 24 ) {
112
+ return true ;
113
+ }
114
+
115
+ return false ;
116
+ }
117
+ }
118
+
73
119
}
0 commit comments