Skip to content

Commit 05119cc

Browse files
committed
resolve conflict
2 parents 4073fdd + e5bc074 commit 05119cc

27 files changed

+1014
-163
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ TRON Protocol and the TVM allow anyone to develop DAPPs for themselves or their
7171
In the shell command, type:
7272
```bash
7373
git clone https://github.com/tronprotocol/java-tron.git
74+
git checkout -t origin/master
7475
```
7576

7677
* For Mac, you can also install **[GitHub for Mac](https://mac.github.com/)** then **[fork and clone our repository](https://guides.github.com/activities/forking/)**.

src/main/java/org/tron/common/overlay/discover/message/Message.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.commons.lang3.ArrayUtils;
44
import org.tron.common.utils.Sha256Hash;
5+
import org.tron.core.exception.P2pException;
56

67
public abstract class Message {
78

@@ -46,7 +47,7 @@ public int hashCode() {
4647
return getMessageId().hashCode();
4748
}
4849

49-
public static Message parse(byte[] encode) {
50+
public static Message parse(byte[] encode) throws Exception{
5051
byte type = encode[0];
5152
byte[] data = ArrayUtils.subarray(encode, 1, encode.length);
5253
switch (type) {
@@ -59,7 +60,7 @@ public static Message parse(byte[] encode) {
5960
case 4:
6061
return new NeighborsMessage(data);
6162
default:
62-
throw new IllegalArgumentException("No such message");
63+
throw new P2pException(P2pException.TypeEnum.NO_SUCH_MESSAGE, "type=" + encode[0]);
6364
}
6465
}
6566
}

src/main/java/org/tron/common/overlay/message/MessageCodec.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/*
2-
* Copyright (c) [2016] [ <ether.camp> ]
3-
* This file is part of the ethereumJ library.
4-
*
5-
* The ethereumJ library is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Lesser General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* The ethereumJ library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public License
16-
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
17-
*/
181
package org.tron.common.overlay.message;
192

203
import io.netty.buffer.ByteBuf;
@@ -31,13 +14,10 @@
3114
import org.springframework.context.annotation.Scope;
3215
import org.springframework.stereotype.Component;
3316
import org.tron.common.overlay.server.Channel;
17+
import org.tron.core.exception.P2pException;
3418
import org.tron.core.net.message.MessageTypes;
3519
import org.tron.core.net.message.TronMessageFactory;
3620

37-
38-
/**
39-
* The Netty codec which encodes/decodes RPLx frames to subprotocol Messages
40-
*/
4121
@Component
4222
@Scope("prototype")
4323
public class MessageCodec extends ByteToMessageDecoder {
@@ -63,15 +43,15 @@ public void setChannel(Channel channel) {
6343
this.channel = channel;
6444
}
6545

66-
private Message createMessage(byte[] encoded) {
46+
private Message createMessage(byte[] encoded) throws Exception{
6747
byte type = encoded[0];
6848
if (MessageTypes.inP2pRange(type)) {
6949
return p2pMessageFactory.create(encoded);
7050
}
7151
if (MessageTypes.inTronRange(type)) {
7252
return tronMessageFactory.create(encoded);
7353
}
74-
throw new Error(MessageFactory.ERR_NO_SUCH_MSG + ", type=" + type + ", len=" + encoded.length);
54+
throw new P2pException(P2pException.TypeEnum.NO_SUCH_MESSAGE, "type=" + encoded[0]);
7555
}
7656

7757
}

src/main/java/org/tron/common/overlay/message/MessageFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public abstract class MessageFactory {
1919
public static String ERR_NO_SUCH_MSG = "No such message";
2020
public static String ERR_PARSE_FAILED = "parse message failed";
2121

22-
protected abstract Message create(byte[] data);
22+
protected abstract Message create(byte[] data) throws Exception;
2323

2424
}

src/main/java/org/tron/common/overlay/message/P2pMessageFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@
1919
package org.tron.common.overlay.message;
2020

2121
import org.apache.commons.lang3.ArrayUtils;
22+
import org.tron.core.exception.P2pException;
2223
import org.tron.core.net.message.MessageTypes;
2324

2425
public class P2pMessageFactory extends MessageFactory {
2526

2627
@Override
27-
public P2pMessage create(byte[] data) {
28+
public P2pMessage create(byte[] data) throws Exception{
2829
try {
2930
byte type = data[0];
3031
byte[] rawData = ArrayUtils.subarray(data, 1, data.length);
3132
return create(type, rawData);
3233
} catch (Exception e) {
33-
if (e.getMessage() != null && e.getMessage().contains(MessageFactory.ERR_NO_SUCH_MSG)){
34+
if (e instanceof P2pException){
3435
throw e;
3536
}else {
36-
throw new Error(MessageFactory.ERR_PARSE_FAILED + ", type=" + data[0] + ", len=" + data.length);
37+
throw new P2pException(P2pException.TypeEnum.PARSE_MESSAGE_FAILED, "type=" + data[0] + ", len=" + data.length);
3738
}
3839
}
3940
}
4041

41-
private P2pMessage create(byte type, byte[] rawData) {
42+
private P2pMessage create(byte type, byte[] rawData) throws Exception{
4243
MessageTypes messageType = MessageTypes.fromByte(type);
4344
if (messageType == null){
44-
throw new RuntimeException(MessageFactory.ERR_NO_SUCH_MSG + ", type=" + type);
45+
throw new P2pException(P2pException.TypeEnum.NO_SUCH_MESSAGE, "type=" + type);
4546
}
4647
switch (messageType) {
4748
case P2P_HELLO:
@@ -53,7 +54,7 @@ private P2pMessage create(byte type, byte[] rawData) {
5354
case P2P_PONG:
5455
return new PongMessage(type, rawData);
5556
default:
56-
throw new Error(MessageFactory.ERR_NO_SUCH_MSG + ", " + messageType);
57+
throw new P2pException(P2pException.TypeEnum.NO_SUCH_MESSAGE, messageType.toString());
5758
}
5859
}
5960
}

src/main/java/org/tron/common/overlay/server/Channel.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.netty.handler.timeout.ReadTimeoutHandler;
2626
import java.io.IOException;
2727
import java.net.InetSocketAddress;
28+
import java.net.SocketAddress;
2829
import java.util.concurrent.TimeUnit;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
@@ -36,6 +37,7 @@
3637
import org.tron.common.overlay.discover.NodeStatistics;
3738
import org.tron.common.overlay.message.*;
3839
import org.tron.core.db.ByteArrayWrapper;
40+
import org.tron.core.exception.P2pException;
3941
import org.tron.core.net.peer.PeerConnectionDelegate;
4042
import org.tron.core.net.peer.TronHandler;
4143

@@ -152,14 +154,15 @@ public void disconnect(ReasonCode reason) {
152154

153155
public void processException(Throwable throwable){
154156
String errMsg = throwable.getMessage();
157+
SocketAddress address = ctx.channel().remoteAddress();
155158
if (throwable instanceof ReadTimeoutException){
156-
logger.error("Read timeout, {}", ctx.channel().remoteAddress());
157-
}else if (errMsg != null && (errMsg.contains(MessageFactory.ERR_NO_SUCH_MSG) ||
158-
errMsg.contains(MessageFactory.ERR_PARSE_FAILED) ||
159-
errMsg.contains("Connection reset by peer"))){
160-
logger.error("{}, {}", errMsg, ctx.channel().remoteAddress());
159+
logger.error("Read timeout, {}", address);
160+
}else if (errMsg != null && errMsg.contains("Connection reset by peer")){
161+
logger.error("{}, {}", errMsg, address);
162+
}else if(throwable instanceof P2pException){
163+
logger.error("type: {}, info: {}, {}", ((P2pException) throwable).getType(), errMsg, address);
161164
}else {
162-
logger.error("exception caught, {}", ctx.channel().remoteAddress(), throwable);
165+
logger.error("exception caught, {}", address, throwable);
163166
}
164167
close();
165168
}

src/main/java/org/tron/core/Wallet.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@
4343
import org.tron.core.capsule.WitnessCapsule;
4444
import org.tron.core.db.AccountStore;
4545
import org.tron.core.db.Manager;
46-
import org.tron.core.exception.*;
46+
import org.tron.core.exception.ContractExeException;
47+
import org.tron.core.exception.ContractValidateException;
48+
import org.tron.core.exception.DupTransactionException;
49+
import org.tron.core.exception.StoreException;
50+
import org.tron.core.exception.TaposException;
51+
import org.tron.core.exception.TooBigTransactionException;
52+
import org.tron.core.exception.ValidateBandwidthException;
53+
import org.tron.core.exception.ValidateSignatureException;
4754
import org.tron.core.net.message.TransactionMessage;
4855
import org.tron.core.net.node.NodeImpl;
4956
import org.tron.protos.Contract.AccountCreateContract;
@@ -191,6 +198,7 @@ public Account getBalance(Account account) {
191198
/**
192199
* Create a transaction by contract.
193200
*/
201+
@Deprecated
194202
public Transaction createTransaction(TransferContract contract) {
195203
AccountStore accountStore = dbManager.getAccountStore();
196204
return new TransactionCapsule(contract, accountStore).getInstance();
@@ -244,7 +252,7 @@ public Transaction createTransaction(VoteWitnessContract voteWitnessContract) {
244252
public Transaction createTransaction(AssetIssueContract assetIssueContract) {
245253
return new TransactionCapsule(assetIssueContract).getInstance();
246254
}
247-
255+
@Deprecated
248256
public Transaction createTransaction(WitnessCreateContract witnessCreateContract) {
249257
return new TransactionCapsule(witnessCreateContract).getInstance();
250258
}
@@ -287,11 +295,11 @@ public WitnessList getWitnessList() {
287295
.forEach(witnessCapsule -> builder.addWitnesses(witnessCapsule.getInstance()));
288296
return builder.build();
289297
}
290-
298+
@Deprecated
291299
public Transaction createTransaction(TransferAssetContract transferAssetContract) {
292300
return new TransactionCapsule(transferAssetContract).getInstance();
293301
}
294-
302+
@Deprecated
295303
public Transaction createTransaction(
296304
ParticipateAssetIssueContract participateAssetIssueContract) {
297305
return new TransactionCapsule(participateAssetIssueContract).getInstance();

src/main/java/org/tron/core/actuator/CreateAccountActuator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ public class CreateAccountActuator extends AbstractActuator {
2323
}
2424

2525
@Override
26+
@Deprecated //Can not create account by api. Need send more than 1 trx , will create account if not exit.
2627
public boolean execute(TransactionResultCapsule ret)
2728
throws ContractExeException {
2829
long fee = calcFee();
2930
try {
3031

3132
AccountCreateContract accountCreateContract = contract.unpack(AccountCreateContract.class);
32-
AccountCapsule accountCapsule = new AccountCapsule(accountCreateContract);
33+
AccountCapsule accountCapsule = new AccountCapsule(accountCreateContract,
34+
System.currentTimeMillis());
3335
dbManager.getAccountStore()
3436
.put(accountCreateContract.getOwnerAddress().toByteArray(), accountCapsule);
3537
ret.setStatus(fee, code.SUCESS);
@@ -42,6 +44,7 @@ public boolean execute(TransactionResultCapsule ret)
4244
}
4345

4446
@Override
47+
@Deprecated //Can not create account by api. Need send more than 1 trx , will create account if not exit.
4548
public boolean validate() throws ContractValidateException {
4649
try {
4750
if (!contract.is(AccountCreateContract.class)) {
@@ -69,11 +72,13 @@ public boolean validate() throws ContractValidateException {
6972
}
7073

7174
@Override
75+
@Deprecated //Can not create account by api. Need send more than 1 trx , will create account if not exit.
7276
public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
7377
return contract.unpack(AccountCreateContract.class).getOwnerAddress();
7478
}
7579

7680
@Override
81+
@Deprecated //Can not create account by api. Need send more than 1 trx , will create account if not exit.
7782
public long calcFee() {
7883
return 0;
7984
}

src/main/java/org/tron/core/actuator/TransferActuator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public boolean validate() throws ContractValidateException {
106106
throw new ContractValidateException(
107107
"For a non-existent account transfer, the minimum amount is 1 TRX");
108108
}
109-
toAccount = new AccountCapsule(transferContract.getToAddress(), AccountType.Normal);
109+
toAccount = new AccountCapsule(transferContract.getToAddress(), AccountType.Normal, System.currentTimeMillis());
110110
dbManager.getAccountStore().put(transferContract.getToAddress().toByteArray(), toAccount);
111111
} else {
112112
//check to account balance if overflow

src/main/java/org/tron/core/actuator/TransferAssetActuator.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.tron.core.exception.ContractExeException;
3030
import org.tron.core.exception.ContractValidateException;
3131
import org.tron.protos.Contract.TransferAssetContract;
32-
import org.tron.protos.Protocol.AccountType;
3332
import org.tron.protos.Protocol.Transaction.Result.code;
3433

3534
public class TransferAssetActuator extends AbstractActuator {
@@ -131,14 +130,12 @@ public boolean validate() throws ContractValidateException {
131130
AccountCapsule toAccount = this.dbManager.getAccountStore()
132131
.get(transferAssetContract.getToAddress().toByteArray());
133132
if (toAccount == null) {
134-
toAccount = new AccountCapsule(transferAssetContract.getToAddress(), AccountType.Normal);
135-
dbManager.getAccountStore()
136-
.put(transferAssetContract.getToAddress().toByteArray(), toAccount);
137-
} else {
138-
assetBalance = toAccount.getAssetMap().get(ByteArray.toStr(nameKey));
139-
if (assetBalance != null) {
140-
assetBalance = Math.addExact(assetBalance, amount); //check if overflow
141-
}
133+
throw new ContractValidateException("To account is not exit!");
134+
}
135+
136+
assetBalance = toAccount.getAssetMap().get(ByteArray.toStr(nameKey));
137+
if (assetBalance != null) {
138+
assetBalance = Math.addExact(assetBalance, amount); //check if overflow
142139
}
143140
} catch (InvalidProtocolBufferException e) {
144141
throw new ContractValidateException(e.getMessage());

0 commit comments

Comments
 (0)