|
26 | 26 | import org.apache.commons.lang3.StringUtils; |
27 | 27 | import org.springframework.beans.factory.annotation.Autowired; |
28 | 28 | import org.springframework.stereotype.Component; |
| 29 | +import org.tron.api.GrpcAPI; |
29 | 30 | import org.tron.api.GrpcAPI.AccountList; |
30 | 31 | import org.tron.api.GrpcAPI.AssetIssueList; |
31 | 32 | import org.tron.api.GrpcAPI.BlockList; |
32 | 33 | import org.tron.api.GrpcAPI.NumberMessage; |
| 34 | +import org.tron.api.GrpcAPI.Return.response_code; |
33 | 35 | import org.tron.api.GrpcAPI.WitnessList; |
34 | 36 | import org.tron.common.crypto.ECKey; |
35 | 37 | import org.tron.common.crypto.Hash; |
36 | 38 | import org.tron.common.overlay.message.Message; |
37 | 39 | import org.tron.common.utils.Base58; |
38 | 40 | import org.tron.common.utils.ByteArray; |
| 41 | +import org.tron.common.utils.ByteUtil; |
39 | 42 | import org.tron.common.utils.Utils; |
40 | 43 | import org.tron.core.capsule.AccountCapsule; |
41 | 44 | import org.tron.core.capsule.AssetIssueCapsule; |
|
53 | 56 | import org.tron.core.exception.ValidateSignatureException; |
54 | 57 | import org.tron.core.net.message.TransactionMessage; |
55 | 58 | import org.tron.core.net.node.NodeImpl; |
56 | | -import org.tron.protos.Contract.AccountCreateContract; |
57 | 59 | import org.tron.protos.Contract.AssetIssueContract; |
58 | | -import org.tron.protos.Contract.ParticipateAssetIssueContract; |
59 | | -import org.tron.protos.Contract.TransferAssetContract; |
60 | 60 | import org.tron.protos.Contract.TransferContract; |
61 | | -import org.tron.protos.Contract.VoteWitnessContract; |
62 | | -import org.tron.protos.Contract.WitnessCreateContract; |
63 | | -import org.tron.protos.Contract.WitnessUpdateContract; |
64 | 61 | import org.tron.protos.Protocol.Account; |
65 | 62 | import org.tron.protos.Protocol.Block; |
66 | 63 | import org.tron.protos.Protocol.Transaction; |
@@ -115,7 +112,7 @@ public static void setAddressPreFixByte(byte addressPreFixByte) { |
115 | 112 | } |
116 | 113 |
|
117 | 114 | public static boolean addressValid(byte[] address) { |
118 | | - if (address == null || address.length == 0) { |
| 115 | + if (ByteUtil.isNullOrZeroArray(address)) { |
119 | 116 | logger.warn("Warning: Address is empty !!"); |
120 | 117 | return false; |
121 | 118 | } |
@@ -207,60 +204,61 @@ public Transaction createTransaction(TransferContract contract) { |
207 | 204 | /** |
208 | 205 | * Broadcast a transaction. |
209 | 206 | */ |
210 | | - public boolean broadcastTransaction(Transaction signaturedTransaction) { |
| 207 | + public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) { |
| 208 | + GrpcAPI.Return.Builder builder = GrpcAPI.Return.newBuilder(); |
211 | 209 | TransactionCapsule trx = new TransactionCapsule(signaturedTransaction); |
212 | 210 | try { |
213 | 211 | Message message = new TransactionMessage(signaturedTransaction); |
214 | 212 | if (message.getData().length > Constant.TRANSACTION_MAX_BYTE_SIZE) { |
215 | | - throw new TooBigTransactionException("too big transaction, the size is " + message.getData().length + " bytes"); |
| 213 | + throw new TooBigTransactionException( |
| 214 | + "too big transaction, the size is " + message.getData().length + " bytes"); |
216 | 215 | } |
217 | 216 | dbManager.pushTransactions(trx); |
218 | 217 | p2pNode.broadcast(message); |
219 | | - return true; |
| 218 | + return builder.setResult(true).setCode(response_code.SUCCESS).build(); |
220 | 219 | } catch (ValidateSignatureException e) { |
221 | 220 | logger.error(e.getMessage(), e); |
| 221 | + return builder.setResult(false).setCode(response_code.SIGERROR) |
| 222 | + .setMessage(ByteString.copyFromUtf8("validate signature error")) |
| 223 | + .build(); |
222 | 224 | } catch (ContractValidateException e) { |
223 | 225 | logger.error(e.getMessage(), e); |
| 226 | + return builder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR) |
| 227 | + .setMessage(ByteString.copyFromUtf8("contract validate error")) |
| 228 | + .build(); |
224 | 229 | } catch (ContractExeException e) { |
225 | 230 | logger.error(e.getMessage(), e); |
| 231 | + return builder.setResult(false).setCode(response_code.CONTRACT_EXE_ERROR) |
| 232 | + .setMessage(ByteString.copyFromUtf8("contract execute error")) |
| 233 | + .build(); |
226 | 234 | } catch (ValidateBandwidthException e) { |
227 | 235 | logger.error("high freq", e); |
| 236 | + return builder.setResult(false).setCode(response_code.BANDWITH_ERROR) |
| 237 | + .setMessage(ByteString.copyFromUtf8("high freq error")) |
| 238 | + .build(); |
228 | 239 | } catch (DupTransactionException e) { |
229 | 240 | logger.error("dup trans", e); |
| 241 | + return builder.setResult(false).setCode(response_code.DUP_TRANSACTION_ERROR) |
| 242 | + .setMessage(ByteString.copyFromUtf8("dup transaction")) |
| 243 | + .build(); |
230 | 244 | } catch (TaposException e) { |
231 | 245 | logger.debug("tapos error", e); |
| 246 | + return builder.setResult(false).setCode(response_code.TAPOS_ERROR) |
| 247 | + .setMessage(ByteString.copyFromUtf8("Tapos check error")) |
| 248 | + .build(); |
232 | 249 | } catch (TooBigTransactionException e) { |
233 | 250 | logger.debug("transaction error", e); |
234 | | - } catch (Exception e){ |
| 251 | + return builder.setResult(false).setCode(response_code.TOO_BIG_TRANSACTION_ERROR) |
| 252 | + .setMessage(ByteString.copyFromUtf8("TooBigTransactionException")) |
| 253 | + .build(); |
| 254 | + } catch (Exception e) { |
235 | 255 | logger.error("exception caught", e); |
| 256 | + return builder.setResult(false).setCode(response_code.OTHER_ERROR) |
| 257 | + .setMessage(ByteString.copyFromUtf8("other error")) |
| 258 | + .build(); |
236 | 259 | } |
237 | | - return false; |
238 | 260 | } |
239 | 261 |
|
240 | | - @Deprecated |
241 | | - public Transaction createAccount(AccountCreateContract contract) { |
242 | | - AccountStore accountStore = dbManager.getAccountStore(); |
243 | | - return new TransactionCapsule(contract, accountStore).getInstance(); |
244 | | - } |
245 | | - |
246 | | - @Deprecated |
247 | | - public Transaction createTransaction(VoteWitnessContract voteWitnessContract) { |
248 | | - return new TransactionCapsule(voteWitnessContract).getInstance(); |
249 | | - } |
250 | | - |
251 | | - @Deprecated |
252 | | - public Transaction createTransaction(AssetIssueContract assetIssueContract) { |
253 | | - return new TransactionCapsule(assetIssueContract).getInstance(); |
254 | | - } |
255 | | - @Deprecated |
256 | | - public Transaction createTransaction(WitnessCreateContract witnessCreateContract) { |
257 | | - return new TransactionCapsule(witnessCreateContract).getInstance(); |
258 | | - } |
259 | | - |
260 | | - @Deprecated |
261 | | - public Transaction createTransaction(WitnessUpdateContract witnessUpdateContract) { |
262 | | - return new TransactionCapsule(witnessUpdateContract).getInstance(); |
263 | | - } |
264 | 262 |
|
265 | 263 | public Block getNowBlock() { |
266 | 264 | try { |
@@ -295,15 +293,6 @@ public WitnessList getWitnessList() { |
295 | 293 | .forEach(witnessCapsule -> builder.addWitnesses(witnessCapsule.getInstance())); |
296 | 294 | return builder.build(); |
297 | 295 | } |
298 | | - @Deprecated |
299 | | - public Transaction createTransaction(TransferAssetContract transferAssetContract) { |
300 | | - return new TransactionCapsule(transferAssetContract).getInstance(); |
301 | | - } |
302 | | - @Deprecated |
303 | | - public Transaction createTransaction( |
304 | | - ParticipateAssetIssueContract participateAssetIssueContract) { |
305 | | - return new TransactionCapsule(participateAssetIssueContract).getInstance(); |
306 | | - } |
307 | 296 |
|
308 | 297 | public AssetIssueList getAssetIssueList() { |
309 | 298 | AssetIssueList.Builder builder = AssetIssueList.newBuilder(); |
|
0 commit comments