Skip to content

Commit 30b563c

Browse files
authored
Merge pull request #889 from lxcmyf/feature/dev_4.9.2
fix(msg): optimize prompt information
2 parents 0bf4a9b + 908880a commit 30b563c

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

src/main/java/org/tron/core/manager/UpdateAccountPermissionInteractive.java

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ private void editPermission(Permission permission, String name) {
200200
editKeys(permission);
201201
}
202202

203-
/**
204-
* editKeys: 支持 add/modify/delete,包含 addressValid 与 weight 校验,
205-
* 修改和添加时都可用 'q' 退出回上一层。
206-
*/
207203
private void editKeys(Permission permission) {
208204
if (permission == null) return;
209205
while (true) {
@@ -261,16 +257,7 @@ private void editKeys(Permission permission) {
261257
continue;
262258
}
263259

264-
long totalWeight = permission.getKeys().stream()
265-
.mapToLong(Key::getWeight)
266-
.sum();
267-
if (totalWeight + weight < permission.getThreshold()) {
268-
System.out.println(redBoldHighlight("The sum of address weights must be greater than or equal to the threshold"));
269-
continue;
270-
}
271-
272260
permission.getKeys().add(new Key(addr, weight));
273-
274261
System.out.println("Added key: " + addr + " (weight=" + weight + ")");
275262

276263
break;
@@ -310,15 +297,6 @@ private void editKeys(Permission permission) {
310297
try {
311298
long w = Long.parseLong(newWeight);
312299
long threshold = permission.getThreshold();
313-
List<Key> keys = permission.getKeys();
314-
long remainWeight = IntStream.range(0, keys.size())
315-
.filter(i -> i != midx)
316-
.mapToLong(i -> keys.get(i).getWeight())
317-
.sum();
318-
if (remainWeight + w < permission.getThreshold()) {
319-
System.out.println(redBoldHighlight("The sum of address weights must be greater than or equal to the threshold"));
320-
continue;
321-
}
322300
if (w <= 0 || w > threshold) {
323301
System.out.println("Weight must be > 0 and <= threshold(" + threshold + "). Skip changing weight.");
324302
} else {
@@ -721,6 +699,9 @@ private String showFinalSummary() {
721699

722700
switch (input) {
723701
case "y":
702+
if (!validateAllPermissionWeights(data)) {
703+
return EMPTY;
704+
}
724705
System.out.println("Confirmed. Preparing final JSON...");
725706
return JSON.toJSONString(data.toTronJson());
726707
case "n":
@@ -732,6 +713,35 @@ private String showFinalSummary() {
732713
}
733714
}
734715

716+
private boolean validateAllPermissionWeights(PermissionData data) {
717+
// valid owner permission
718+
if (!validateSinglePermission(data.getOwnerPermission())) {
719+
System.out.println(redBoldHighlight("Owner permission key weight sum must >= threshold!"));
720+
return false;
721+
}
722+
723+
// valid active permissions
724+
for (Permission p : data.getActivePermissions()) {
725+
if (!validateSinglePermission(p)) {
726+
System.out.println(redBoldHighlight("Active permission '" + p.getPermissionName()
727+
+ "' key weight sum must >= threshold!"));
728+
return false;
729+
}
730+
}
731+
732+
return true;
733+
}
734+
735+
private boolean validateSinglePermission(Permission p) {
736+
if (p == null) return false;
737+
int totalWeight = 0;
738+
for (Key k : p.getKeys()) {
739+
totalWeight += k.getWeight();
740+
}
741+
return totalWeight >= p.getThreshold();
742+
}
743+
744+
735745
private void printPermissionData(PermissionData data) {
736746
System.out.println("\n=============== Preview of Updated Account Permissions ===============\n");
737747

src/main/java/org/tron/walletcli/Client.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import org.jline.reader.impl.DefaultParser;
7676
import org.jline.reader.impl.completer.ArgumentCompleter;
7777
import org.jline.reader.impl.completer.NullCompleter;
78-
import org.jline.reader.impl.completer.StringsCompleter;
7978
import org.jline.terminal.Terminal;
8079
import org.jline.terminal.TerminalBuilder;
8180
import org.tron.api.GrpcAPI.AddressPrKeyPairMessage;

src/main/java/org/tron/walletserver/WalletApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ public Triple<Boolean, Long, Long> triggerContract(
24642464
long calculateBandwidth = calculateBandwidth(transaction);
24652465
String s = new String(builder.build().getResult().getMessage().toByteArray(), StandardCharsets.UTF_8);
24662466
if ("REVERT opcode executed".equals(s)) {
2467-
System.out.println(redBoldHighlight("The transaction may be reversed."));
2467+
System.out.println(redBoldHighlight("The transaction may be reverted."));
24682468
}
24692469
System.out.println("It is estimated that " + greenBoldHighlight(calculateBandwidth) + " bandwidth and " + greenBoldHighlight(energyUsed) + " energy will be consumed.");
24702470
} else {

0 commit comments

Comments
 (0)