|
23 | 23 | import com.google.protobuf.ByteString;
|
24 | 24 | import java.security.SignatureException;
|
25 | 25 | import java.util.ArrayList;
|
| 26 | +import java.util.Arrays; |
26 | 27 | import java.util.List;
|
27 | 28 | import lombok.extern.slf4j.Slf4j;
|
28 | 29 | import org.apache.commons.lang3.ArrayUtils;
|
|
34 | 35 | import org.tron.api.GrpcAPI.TransactionSignWeight;
|
35 | 36 | import org.tron.api.GrpcAPI.TransactionSignWeight.Result;
|
36 | 37 | import org.tron.common.parameter.CommonParameter;
|
| 38 | +import org.tron.common.crypto.Hash; |
37 | 39 | import org.tron.common.utils.Sha256Hash;
|
38 | 40 | import org.tron.core.ChainBaseManager;
|
39 | 41 | import org.tron.core.capsule.AccountCapsule;
|
|
47 | 49 | import org.tron.protos.Protocol.Transaction.Result.contractResult;
|
48 | 50 | import org.tron.protos.Protocol.TransactionSign;
|
49 | 51 | 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; |
50 | 55 | import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
|
51 | 56 |
|
52 | 57 | @Slf4j(topic = "capsule")
|
53 | 58 | @Component
|
54 | 59 | public class TransactionUtil {
|
55 | 60 |
|
56 |
| - @Autowired |
57 |
| - private ChainBaseManager chainBaseManager; |
58 |
| - |
59 | 61 | private static final int maxAccountNameLen = 200;
|
60 | 62 | private static final int maxAccountIdLen = 32;
|
61 | 63 | private static final int minAccountIdLen = 8;
|
62 | 64 | private static final int maxAssetNameLen = 32;
|
63 | 65 | private static final int maxTokenAbbrName = 5;
|
64 |
| - private static final int maxAssetDescription = 200; |
65 |
| - private static final int maxUrlLen = 256; |
| 66 | + |
| 67 | + @Autowired |
| 68 | + private ChainBaseManager chainBaseManager; |
66 | 69 |
|
67 | 70 | public static boolean validAccountId(byte[] accountId) {
|
68 | 71 | return validReadableBytes(accountId, maxAccountIdLen) && accountId.length < minAccountIdLen;
|
@@ -93,22 +96,25 @@ private static boolean validReadableBytes(byte[] bytes, int maxLength) {
|
93 | 96 | }
|
94 | 97 |
|
95 | 98 | public static boolean validAccountName(byte[] accountName) {
|
96 |
| - return validBytes(accountName, maxAccountNameLen, true); |
| 99 | + if (ArrayUtils.isEmpty(accountName)) { |
| 100 | + return true; //account name can be empty |
| 101 | + } |
| 102 | + return accountName.length <= maxAccountNameLen; |
97 | 103 | }
|
98 | 104 |
|
99 | 105 | public static boolean validAssetDescription(byte[] description) {
|
100 |
| - return validBytes(description, maxAssetDescription, true); |
101 |
| - } |
| 106 | + if (ArrayUtils.isEmpty(description)) { |
| 107 | + return true; //description can empty |
| 108 | + } |
102 | 109 |
|
103 |
| - public static boolean validUrl(byte[] url) { |
104 |
| - return validBytes(url, maxUrlLen, false); |
| 110 | + return description.length <= 200; |
105 | 111 | }
|
106 | 112 |
|
107 |
| - private static boolean validBytes(byte[] bytes, int maxLength, boolean allowEmpty) { |
108 |
| - if (ArrayUtils.isEmpty(bytes)) { |
109 |
| - return allowEmpty; |
| 113 | + public static boolean validUrl(byte[] url) { |
| 114 | + if (ArrayUtils.isEmpty(url)) { |
| 115 | + return false; |
110 | 116 | }
|
111 |
| - return bytes.length <= maxLength; |
| 117 | + return url.length <= 256; |
112 | 118 | }
|
113 | 119 |
|
114 | 120 | public static boolean isNumber(byte[] id) {
|
|
0 commit comments