23
23
import com .google .protobuf .ByteString ;
24
24
import java .security .SignatureException ;
25
25
import java .util .ArrayList ;
26
- import java .util .Arrays ;
27
26
import java .util .List ;
28
27
import lombok .extern .slf4j .Slf4j ;
29
28
import org .apache .commons .lang3 .ArrayUtils ;
35
34
import org .tron .api .GrpcAPI .TransactionSignWeight ;
36
35
import org .tron .api .GrpcAPI .TransactionSignWeight .Result ;
37
36
import org .tron .common .parameter .CommonParameter ;
38
- import org .tron .common .crypto .Hash ;
39
37
import org .tron .common .utils .Sha256Hash ;
40
38
import org .tron .core .ChainBaseManager ;
41
39
import org .tron .core .capsule .AccountCapsule ;
49
47
import org .tron .protos .Protocol .Transaction .Result .contractResult ;
50
48
import org .tron .protos .Protocol .TransactionSign ;
51
49
import org .tron .protos .contract .SmartContractOuterClass .CreateSmartContract ;
52
- import org .tron .protos .contract .SmartContractOuterClass .SmartContract ;
53
- import org .tron .protos .contract .SmartContractOuterClass .SmartContract .ABI ;
54
- import org .tron .protos .contract .SmartContractOuterClass .SmartContract .ABI .Entry .StateMutabilityType ;
55
50
import org .tron .protos .contract .SmartContractOuterClass .TriggerSmartContract ;
56
51
57
52
@ Slf4j (topic = "capsule" )
58
53
@ Component
59
54
public class TransactionUtil {
60
55
56
+ private static final int maxAccountNameLen = 200 ;
57
+ private static final int maxAccountIdLen = 32 ;
58
+ private static final int minAccountIdLen = 8 ;
59
+ private static final int maxAssetNameLen = 32 ;
60
+ private static final int maxTokenAbbrNameLen = 5 ;
61
+
61
62
@ Autowired
62
63
private ChainBaseManager chainBaseManager ;
63
64
@@ -66,51 +67,25 @@ public static boolean validAccountName(byte[] accountName) {
66
67
return true ; //account name can be empty
67
68
}
68
69
69
- return accountName .length <= 200 ;
70
+ return accountName .length <= maxAccountNameLen ;
70
71
}
71
72
72
73
public static boolean validAccountId (byte [] accountId ) {
73
- if (ArrayUtils .isEmpty (accountId )) {
74
- return false ;
75
- }
76
-
77
- if (accountId .length < 8 ) {
78
- return false ;
79
- }
80
-
81
- if (accountId .length > 32 ) {
82
- return false ;
83
- }
84
-
85
- return validBytes (accountId );
86
-
74
+ return validReadableBytes (accountId , maxAccountIdLen ) && accountId .length >= minAccountIdLen ;
87
75
}
88
76
89
77
public static boolean validAssetName (byte [] assetName ) {
90
- if (ArrayUtils .isEmpty (assetName )) {
91
- return false ;
92
- }
93
- if (assetName .length > 32 ) {
94
- return false ;
95
- }
96
-
97
- return validBytes (assetName );
98
-
78
+ return validReadableBytes (assetName , maxAssetNameLen );
99
79
}
100
80
101
81
public static boolean validTokenAbbrName (byte [] abbrName ) {
102
- if (ArrayUtils .isEmpty (abbrName )) {
103
- return false ;
104
- }
105
- if (abbrName .length > 5 ) {
106
- return false ;
107
- }
108
-
109
- return validBytes (abbrName );
110
-
82
+ return validReadableBytes (abbrName , maxTokenAbbrNameLen );
111
83
}
112
84
113
- private static boolean validBytes (byte [] bytes ) {
85
+ private static boolean validReadableBytes (byte [] bytes , int maxLength ) {
86
+ if (ArrayUtils .isEmpty (bytes ) || bytes .length > maxLength ) {
87
+ return false ;
88
+ }
114
89
// b must be readable
115
90
for (byte b : bytes ) {
116
91
if (b < 0x21 ) {
@@ -123,7 +98,6 @@ private static boolean validBytes(byte[] bytes) {
123
98
return true ;
124
99
}
125
100
126
-
127
101
public static boolean validAssetDescription (byte [] description ) {
128
102
if (ArrayUtils .isEmpty (description )) {
129
103
return true ; //description can empty
0 commit comments