Skip to content

Commit 0144bc3

Browse files
authored
Merge pull request tronprotocol#1458 from tronprotocol/add_verificaiton_for_creating_proposal
Add verification for creating proposal
2 parents 44fa282 + a343239 commit 0144bc3

3 files changed

Lines changed: 31 additions & 19 deletions

File tree

‎src/main/java/org/tron/core/actuator/FreezeBalanceActuator.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
9090
dbManager.getDynamicPropertiesStore()
9191
.addTotalEnergyWeight(freezeBalanceContract.getFrozenBalance() / 1000_000L);
9292
break;
93+
default:
94+
//this should never happen
95+
break;
9396
}
9497

9598
dbManager.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);

‎src/main/java/org/tron/core/actuator/ProposalCreateActuator.java‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
3535
try {
3636
final ProposalCreateContract proposalCreateContract = this.contract
3737
.unpack(ProposalCreateContract.class);
38-
long id = (Objects.isNull(getDeposit())) ? dbManager.getDynamicPropertiesStore().getLatestProposalNum() + 1 :
38+
long id = (Objects.isNull(getDeposit())) ?
39+
dbManager.getDynamicPropertiesStore().getLatestProposalNum() + 1 :
3940
getDeposit().getLatestProposalNum() + 1;
4041
ProposalCapsule proposalCapsule =
4142
new ProposalCapsule(proposalCreateContract.getOwnerAddress(), id);
@@ -48,8 +49,10 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
4849
getDeposit().getMaintenanceTimeInterval();
4950
proposalCapsule.setCreateTime(now);
5051

51-
long currentMaintenanceTime = (Objects.isNull(getDeposit())) ? dbManager.getDynamicPropertiesStore().getNextMaintenanceTime():
52-
getDeposit().getNextMaintenanceTime();
52+
long currentMaintenanceTime =
53+
(Objects.isNull(getDeposit())) ? dbManager.getDynamicPropertiesStore()
54+
.getNextMaintenanceTime() :
55+
getDeposit().getNextMaintenanceTime();
5356
long now3 = now + Args.getInstance().getProposalExpireTime();
5457
long round = (now3 - currentMaintenanceTime) / maintenanceTimeInterval;
5558
long expirationTime =
@@ -59,13 +62,11 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
5962
if (Objects.isNull(deposit)) {
6063
dbManager.getProposalStore().put(proposalCapsule.createDbKey(), proposalCapsule);
6164
dbManager.getDynamicPropertiesStore().saveLatestProposalNum(id);
62-
}
63-
else {
64-
deposit.putProposalValue(proposalCapsule.createDbKey(),proposalCapsule);
65+
} else {
66+
deposit.putProposalValue(proposalCapsule.createDbKey(), proposalCapsule);
6567
deposit.putDynamicPropertiesWithLatestProposalNum(id);
6668
}
6769

68-
6970
ret.setStatus(fee, code.SUCESS);
7071
} catch (InvalidProtocolBufferException e) {
7172
logger.debug(e.getMessage(), e);
@@ -102,23 +103,28 @@ public boolean validate() throws ContractValidateException {
102103
throw new ContractValidateException("Invalid address");
103104
}
104105

105-
if(!Objects.isNull(deposit)) {
106+
if (!Objects.isNull(deposit)) {
106107
if (Objects.isNull(deposit.getAccount(ownerAddress))) {
107108
throw new ContractValidateException(
108109
ACCOUNT_EXCEPTION_STR + readableOwnerAddress + NOT_EXIST_STR);
109110
}
110-
}
111-
else if (!dbManager.getAccountStore().has(ownerAddress)) {
112-
throw new ContractValidateException(ACCOUNT_EXCEPTION_STR + readableOwnerAddress + NOT_EXIST_STR);
111+
} else if (!dbManager.getAccountStore().has(ownerAddress)) {
112+
throw new ContractValidateException(
113+
ACCOUNT_EXCEPTION_STR + readableOwnerAddress + NOT_EXIST_STR);
113114
}
114115

115-
if( !Objects.isNull(getDeposit())) {
116+
if (!Objects.isNull(getDeposit())) {
116117
if (Objects.isNull(getDeposit().getWitness(ownerAddress))) {
117118
throw new ContractValidateException(
118119
WITNESS_EXCEPTION_STR + readableOwnerAddress + NOT_EXIST_STR);
119120
}
120-
}else if (!dbManager.getWitnessStore().has(ownerAddress)) {
121-
throw new ContractValidateException(WITNESS_EXCEPTION_STR+ readableOwnerAddress + NOT_EXIST_STR);
121+
} else if (!dbManager.getWitnessStore().has(ownerAddress)) {
122+
throw new ContractValidateException(
123+
WITNESS_EXCEPTION_STR + readableOwnerAddress + NOT_EXIST_STR);
124+
}
125+
126+
if (contract.getParametersMap().size() == 0) {
127+
throw new ContractValidateException("This proposal has no parameter.");
122128
}
123129

124130
for (Map.Entry<Long, Long> entry : contract.getParametersMap().entrySet()) {
@@ -155,20 +161,20 @@ private void validateValue(Map.Entry<Long, Long> entry) throws ContractValidateE
155161
}
156162
break;
157163
}
158-
case (9):{
159-
if(entry.getValue() != 1){
164+
case (9): {
165+
if (entry.getValue() != 1) {
160166
throw new ContractValidateException(
161167
"This value[ALLOW_CREATION_OF_CONTRACTS] is only allowed to be 1");
162168
}
163169
break;
164170
}
165-
case (10):{
166-
if(dbManager.getDynamicPropertiesStore().getRemoveThePowerOfTheGr() == -1){
171+
case (10): {
172+
if (dbManager.getDynamicPropertiesStore().getRemoveThePowerOfTheGr() == -1) {
167173
throw new ContractValidateException(
168174
"This proposal has been executed before and is only allowed to be executed once");
169175
}
170176

171-
if(entry.getValue() != 1){
177+
if (entry.getValue() != 1) {
172178
throw new ContractValidateException(
173179
"This value[REMOVE_THE_POWER_OF_THE_GR] is only allowed to be 1");
174180
}

‎src/main/java/org/tron/core/actuator/UnfreezeBalanceActuator.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
7676

7777
dbManager.getDynamicPropertiesStore().addTotalEnergyWeight(-unfreezeBalance / 1000_000L);
7878
break;
79+
default:
80+
//this should never happen
81+
break;
7982
}
8083

8184
VotesCapsule votesCapsule;

0 commit comments

Comments
 (0)