Skip to content

Commit d0da5ea

Browse files
committed
mdf conflict“
2 parents d4a9896 + 4d45605 commit d0da5ea

57 files changed

Lines changed: 557 additions & 1154 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cache:
1414
script:
1515
- sh tron.sh
1616
- "./gradlew build"
17-
- sonar-scanner
17+
1818
skip_build:
1919
- README.md:
2020
- LICENSE

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ task lint(type: Checkstyle) {
153153
source 'src'
154154
include '**/*.java'
155155
exclude 'main/gen/**'
156+
exclude 'test/**'
156157
// empty classpath
157158
classpath = files()
158159
//Failing the build
@@ -271,4 +272,4 @@ def binaryRelease(taskName, jarName, mainClass) {
271272
artifacts {
272273
archives(binaryRelease('buildSolidityNodeJar', 'SolidityNode', 'org.tron.program.SolidityNode'),
273274
binaryRelease('buildFullNodeJar', 'FullNode', 'org.tron.program.FullNode'))
274-
}
275+
}

src/main/java/org/tron/common/application/ApplicationImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void closeConnection() {
117117
try {
118118
p2pNode.close();
119119
} catch (Exception e) {
120-
System.err.println("faild to close p2pNode. " + e);
120+
System.err.println("failed to close p2pNode. " + e);
121121
} finally {
122122
System.err.println("******** end to shutdown connection ********");
123123
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class SyncPool {
5151

5252
public static final Logger logger = LoggerFactory.getLogger("SyncPool");
5353

54-
private static final double fator = 0.4;
54+
private static final double factor = 0.4;
5555

5656
private final List<PeerConnection> activePeers = Collections.synchronizedList(new ArrayList<PeerConnection>());
5757
private final AtomicInteger passivePeersCount = new AtomicInteger(0);
@@ -103,10 +103,8 @@ public void init(PeerConnectionDelegate peerDel) {
103103
}
104104

105105
private void fillUp() {
106-
int lackSize = (int) (maxActiveNodes * fator) - activePeers.size();
107-
if (lackSize <= 0) {
108-
return;
109-
}
106+
int lackSize = (int) (maxActiveNodes * factor) - activePeers.size();
107+
if(lackSize <= 0) return;
110108

111109
final Set<String> nodesInUse = new HashSet<>();
112110
channelManager.getActivePeers().forEach(channel -> nodesInUse.add(channel.getPeerId()));

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.tron.core.db.BandwidthProcessor;
5353
import org.tron.core.db.Manager;
5454
import org.tron.core.db.PendingManager;
55+
import org.tron.core.exception.AccountResourceInsufficientException;
5556
import org.tron.core.exception.BadItemException;
5657
import org.tron.core.exception.ContractExeException;
5758
import org.tron.core.exception.ContractValidateException;
@@ -60,7 +61,6 @@
6061
import org.tron.core.exception.TaposException;
6162
import org.tron.core.exception.TooBigTransactionException;
6263
import org.tron.core.exception.TransactionExpirationException;
63-
import org.tron.core.exception.ValidateBandwidthException;
6464
import org.tron.core.exception.ValidateSignatureException;
6565
import org.tron.core.net.message.TransactionMessage;
6666
import org.tron.core.net.node.NodeImpl;
@@ -260,10 +260,10 @@ public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
260260
return builder.setResult(false).setCode(response_code.CONTRACT_EXE_ERROR)
261261
.setMessage(ByteString.copyFromUtf8("contract execute error"))
262262
.build();
263-
} catch (ValidateBandwidthException e) {
264-
logger.info("high freq" + e.getMessage());
263+
} catch (AccountResourceInsufficientException e) {
264+
logger.info(e.getMessage());
265265
return builder.setResult(false).setCode(response_code.BANDWITH_ERROR)
266-
.setMessage(ByteString.copyFromUtf8("high freq error"))
266+
.setMessage(ByteString.copyFromUtf8("AccountResourceInsufficient error"))
267267
.build();
268268
} catch (DupTransactionException e) {
269269
logger.info("dup trans" + e.getMessage());
@@ -356,6 +356,8 @@ public AccountNetMessage getAccountNet(ByteString accountAddress) {
356356

357357
long netLimit = processor.calculateGlobalNetLimit(accountCapsule.getFrozenBalance());
358358
long freeNetLimit = dbManager.getDynamicPropertiesStore().getFreeNetLimit();
359+
long totalNetLimit = dbManager.getDynamicPropertiesStore().getTotalNetLimit();
360+
long totalNetWeight = dbManager.getDynamicPropertiesStore().getTotalNetWeight();
359361

360362
Map<String, Long> assetNetLimitMap = new HashMap<>();
361363
accountCapsule.getAllFreeAssetNetUsage().keySet().forEach(asset -> {
@@ -367,6 +369,8 @@ public AccountNetMessage getAccountNet(ByteString accountAddress) {
367369
.setFreeNetLimit(freeNetLimit)
368370
.setNetUsed(accountCapsule.getNetUsage())
369371
.setNetLimit(netLimit)
372+
.setTotalNetLimit(totalNetLimit)
373+
.setTotalNetWeight(totalNetWeight)
370374
.putAllAssetNetUsed(accountCapsule.getAllFreeAssetNetUsage())
371375
.putAllAssetNetLimit(assetNetLimitMap);
372376
return builder.build();

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

Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
import lombok.extern.slf4j.Slf4j;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.stereotype.Component;
8-
import org.springframework.util.CollectionUtils;
98
import org.tron.api.GrpcAPI.AssetIssueList;
10-
import org.tron.api.GrpcAPI.NumberMessage;
119
import org.tron.api.GrpcAPI.TransactionList;
1210
import org.tron.api.GrpcAPI.WitnessList;
1311
import org.tron.common.utils.ByteArray;
1412
import org.tron.core.db.api.StoreAPI;
15-
import org.tron.core.exception.NonUniqueObjectException;
1613
import org.tron.protos.Contract.AssetIssueContract;
17-
import org.tron.protos.Protocol.Account;
18-
import org.tron.protos.Protocol.Block;
1914
import org.tron.protos.Protocol.Transaction;
2015
import org.tron.protos.Protocol.Witness;
2116

@@ -26,17 +21,6 @@ public class WalletSolidity {
2621
@Autowired
2722
private StoreAPI storeAPI;
2823

29-
public Account getAccount(ByteString addressBs) {
30-
Account accountByAddress = null;
31-
try {
32-
accountByAddress = storeAPI
33-
.getAccountByAddress(ByteArray.toHexString(addressBs.toByteArray()));
34-
} catch (NonUniqueObjectException e) {
35-
e.printStackTrace();
36-
}
37-
return accountByAddress;
38-
}
39-
4024
public WitnessList getWitnessList() {
4125
List<Witness> witnessAll = storeAPI.getWitnessAll();
4226
WitnessList witnessList = WitnessList.newBuilder().addAllWitnesses(witnessAll).build();
@@ -50,81 +34,9 @@ public AssetIssueList getAssetIssueList() {
5034
return assetIssueList;
5135
}
5236

53-
public AssetIssueList getAssetIssueListByTimestamp(long timestamp) {
54-
List<AssetIssueContract> assetIssueAll = storeAPI.getAssetIssueByTime(timestamp);
55-
AssetIssueList assetIssueList =
56-
AssetIssueList.newBuilder().addAllAssetIssue(assetIssueAll).build();
57-
return assetIssueList;
58-
}
59-
60-
public AssetIssueList getAssetIssueByAccount(ByteString address) {
61-
List<AssetIssueContract> assetIssueByOwnerAddress = storeAPI
62-
.getAssetIssueByOwnerAddress(ByteArray.toHexString(address.toByteArray()));
63-
AssetIssueList assetIssueList =
64-
AssetIssueList.newBuilder().addAllAssetIssue(assetIssueByOwnerAddress).build();
65-
return assetIssueList;
66-
}
67-
68-
public AssetIssueContract getAssetIssueByName(ByteString name) {
69-
AssetIssueContract assetIssueByName = null;
70-
try {
71-
assetIssueByName = storeAPI.getAssetIssueByName(name.toStringUtf8());
72-
} catch (NonUniqueObjectException e) {
73-
e.printStackTrace();
74-
}
75-
return assetIssueByName;
76-
}
77-
78-
public Block getNowBlock() {
79-
List<Block> latestBlocks = storeAPI.getLatestBlocks(1);
80-
if (CollectionUtils.isEmpty(latestBlocks)) {
81-
return null;
82-
}
83-
return latestBlocks.get(0);
84-
}
85-
86-
public Block getBlockByNum(long num) {
87-
Block blockByNumber = null;
88-
try {
89-
blockByNumber = storeAPI.getBlockByNumber(num);
90-
} catch (NonUniqueObjectException e) {
91-
e.printStackTrace();
92-
}
93-
return blockByNumber;
94-
}
95-
96-
public NumberMessage totalTransaction() {
97-
long transactionCount = storeAPI.getTransactionCount();
98-
return NumberMessage.newBuilder().setNum(transactionCount).build();
99-
}
100-
101-
public Transaction getTransactionById(ByteString id) {
102-
try {
103-
Transaction transactionById = storeAPI
104-
.getTransactionById(ByteArray.toHexString(id.toByteArray()));
105-
return transactionById;
106-
} catch (NonUniqueObjectException e) {
107-
e.printStackTrace();
108-
}
109-
return null;
110-
}
111-
112-
public TransactionList getTransactionsByTimestamp(long beginTime, long endTime, long offset, long limit) {
113-
List<Transaction> transactionsByTimestamp = storeAPI
114-
.getTransactionsByTimestamp(beginTime, endTime, offset, limit);
115-
TransactionList transactionList = TransactionList.newBuilder()
116-
.addAllTransaction(transactionsByTimestamp).build();
117-
return transactionList;
118-
}
119-
120-
public NumberMessage getTransactionsByTimestampCount(long beginTime, long endTime) {
121-
return NumberMessage.newBuilder().setNum(storeAPI
122-
.getTransactionsByTimestampCount(beginTime, endTime)).build();
123-
}
124-
125-
public TransactionList getTransactionsFromThis(ByteString thisAddress, long offset , long limit) {
37+
public TransactionList getTransactionsFromThis(ByteString thisAddress, long offset, long limit) {
12638
List<Transaction> transactionsFromThis = storeAPI
127-
.getTransactionsFromThis(ByteArray.toHexString(thisAddress.toByteArray()),offset , limit);
39+
.getTransactionsFromThis(ByteArray.toHexString(thisAddress.toByteArray()), offset, limit);
12840
TransactionList transactionList = TransactionList.newBuilder()
12941
.addAllTransaction(transactionsFromThis).build();
13042
return transactionList;
@@ -137,11 +49,4 @@ public TransactionList getTransactionsToThis(ByteString toAddress, long offset,
13749
.addAllTransaction(transactionsToThis).build();
13850
return transactionList;
13951
}
140-
public NumberMessage getTransactionFromThisCount(ByteString toAddress) {
141-
return NumberMessage.newBuilder().setNum(storeAPI.getTransactionsFromThisCount(ByteArray.toHexString(toAddress.toByteArray()))).build();
142-
}
143-
144-
public NumberMessage getTransactionToThisCount(ByteString toAddress) {
145-
return NumberMessage.newBuilder().setNum(storeAPI.getTransactionsToThisCount(ByteArray.toHexString(toAddress.toByteArray()))).build();
146-
}
14752
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ private static Actuator getActuatorByContract(Contract contract, Manager manager
5353
return new VoteWitnessActuator(contract.getParameter(), manager);
5454
case WitnessCreateContract:
5555
return new WitnessCreateActuator(contract.getParameter(), manager);
56+
case AccountCreateContract:
57+
return new CreateAccountActuator(contract.getParameter(), manager);
5658
case AssetIssueContract:
5759
return new AssetIssueActuator(contract.getParameter(), manager);
5860
case UnfreezeAssetContract:

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.protobuf.ByteString;
55
import com.google.protobuf.InvalidProtocolBufferException;
66
import lombok.extern.slf4j.Slf4j;
7+
import org.tron.common.utils.StringUtil;
78
import org.tron.core.Wallet;
89
import org.tron.core.capsule.AccountCapsule;
910
import org.tron.core.capsule.TransactionResultCapsule;
@@ -16,15 +17,11 @@
1617
@Slf4j
1718
public class CreateAccountActuator extends AbstractActuator {
1819

19-
@Deprecated
20-
//Can not create account by api. Need send more than 1 trx , will create account if not exit.
2120
CreateAccountActuator(Any contract, Manager dbManager) {
2221
super(contract, dbManager);
2322
}
2423

2524
@Override
26-
@Deprecated
27-
//Can not create account by api. Need send more than 1 trx , will create account if not exit.
2825
public boolean execute(TransactionResultCapsule ret)
2926
throws ContractExeException {
3027
long fee = calcFee();
@@ -33,7 +30,7 @@ public boolean execute(TransactionResultCapsule ret)
3330
AccountCapsule accountCapsule = new AccountCapsule(accountCreateContract,
3431
dbManager.getHeadBlockTimeStamp());
3532
dbManager.getAccountStore()
36-
.put(accountCreateContract.getOwnerAddress().toByteArray(), accountCapsule);
33+
.put(accountCreateContract.getAccountAddress().toByteArray(), accountCapsule);
3734
ret.setStatus(fee, code.SUCESS);
3835
} catch (InvalidProtocolBufferException e) {
3936
logger.debug(e.getMessage(), e);
@@ -45,8 +42,6 @@ public boolean execute(TransactionResultCapsule ret)
4542
}
4643

4744
@Override
48-
@Deprecated
49-
//Can not create account by api. Need send more than 1 trx , will create account if not exit.
5045
public boolean validate() throws ContractValidateException {
5146
if (this.contract == null) {
5247
throw new ContractValidateException("No contract!");
@@ -66,34 +61,43 @@ public boolean validate() throws ContractValidateException {
6661
logger.debug(e.getMessage(), e);
6762
throw new ContractValidateException(e.getMessage());
6863
}
69-
if (contract.getAccountName().isEmpty()) {
70-
throw new ContractValidateException("AccountName is null");
71-
}
72-
if (!Wallet.addressValid(contract.getOwnerAddress().toByteArray())) {
64+
// if (contract.getAccountName().isEmpty()) {
65+
// throw new ContractValidateException("AccountName is null");
66+
// }
67+
byte[] ownerAddress = contract.getOwnerAddress().toByteArray();
68+
if (!Wallet.addressValid(ownerAddress)) {
7369
throw new ContractValidateException("Invalid ownerAddress");
7470
}
7571

76-
if (contract.getType() == null) {
77-
throw new ContractValidateException("Type is null");
72+
AccountCapsule accountCapsule = dbManager.getAccountStore().get(ownerAddress);
73+
if (accountCapsule == null) {
74+
String readableOwnerAddress = StringUtil.createReadableString(ownerAddress);
75+
throw new ContractValidateException(
76+
"Account[" + readableOwnerAddress + "] not exists");
7877
}
7978

80-
if (dbManager.getAccountStore().has(contract.getOwnerAddress().toByteArray())) {
79+
byte[] accountAddress = contract.getAccountAddress().toByteArray();
80+
if (!Wallet.addressValid(accountAddress)) {
81+
throw new ContractValidateException("Invalid account address");
82+
}
83+
84+
// if (contract.getType() == null) {
85+
// throw new ContractValidateException("Type is null");
86+
// }
87+
88+
if (dbManager.getAccountStore().has(accountAddress)) {
8189
throw new ContractValidateException("Account has existed");
8290
}
8391

8492
return true;
8593
}
8694

8795
@Override
88-
@Deprecated
89-
//Can not create account by api. Need send more than 1 trx , will create account if not exit.
9096
public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
9197
return contract.unpack(AccountCreateContract.class).getOwnerAddress();
9298
}
9399

94100
@Override
95-
@Deprecated
96-
//Can not create account by api. Need send more than 1 trx , will create account if not exit.
97101
public long calcFee() {
98102
return 0;
99103
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
5050
assetIssueStore.put(assetIssueCapsule.createDbKey(), assetIssueCapsule);
5151

5252
ret.setStatus(fee, code.SUCESS);
53-
} catch (Exception e) {
53+
} catch (InvalidProtocolBufferException e) {
5454
logger.debug(e.getMessage(), e);
5555
ret.setStatus(fee, code.FAILED);
5656
throw new ContractExeException(e.getMessage());

src/main/java/org/tron/core/capsule/AccountCapsule.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,19 @@ public AccountCapsule(ByteString accountName, ByteString address, AccountType ac
7070
*/
7171
public AccountCapsule(final AccountCreateContract contract) {
7272
this.account = Account.newBuilder()
73-
.setAccountName(contract.getAccountName())
7473
.setType(contract.getType())
75-
.setAddress(contract.getOwnerAddress())
74+
.setAddress(contract.getAccountAddress())
7675
.setTypeValue(contract.getTypeValue())
7776
.build();
7877
}
7978

8079
/**
81-
* construct account from AccountCreateContract and creatTime.
80+
* construct account from AccountCreateContract and createTime.
8281
*/
8382
public AccountCapsule(final AccountCreateContract contract, long createTime) {
8483
this.account = Account.newBuilder()
85-
.setAccountName(contract.getAccountName())
8684
.setType(contract.getType())
87-
.setAddress(contract.getOwnerAddress())
85+
.setAddress(contract.getAccountAddress())
8886
.setTypeValue(contract.getTypeValue())
8987
.setCreateTime(createTime)
9088
.build();

0 commit comments

Comments
 (0)