Skip to content

Commit 831461f

Browse files
Merge branch 'develop' into feature/wallet
2 parents 77b8b43 + a41dd00 commit 831461f

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

src/main/java/org/tron/command/Cli.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ public void run(Peer peer) {
2727
Scanner in = new Scanner(System.in);
2828

2929
while (true) {
30-
String cmd = in.nextLine();
31-
cmd = cmd.trim();
30+
String cmd = in.nextLine().trim();
3231

3332
String[] cmdArray = cmd.split("\\s+");
34-
35-
if (cmdArray.length == 0 || cmdArray[0].equals("")) {
33+
// split on trim() string will always return at the minimum: [""]
34+
if ("".equals(cmdArray[0])) {
3635
continue;
3736
}
3837

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

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,54 +134,51 @@ public static String toPrintString(Transaction transaction) {
134134
return "";
135135
}
136136

137-
String str =
138-
"\nTransaction {\n" +
139-
"\tid=" + ByteArray.toHexString(transaction.getId()
140-
.toByteArray()) + "\n" +
141-
"\tvin=[\n";
142-
int i = 0;
143-
for (TXInput vin : transaction.getVinList()) {
144-
str += "\t\t{\n" +
137+
StringBuilder sb = new StringBuilder("\nTransaction {\n" +
138+
"\tid=" + ByteArray.toHexString(transaction.getId()
139+
.toByteArray()) + "\n" +
140+
"\tvin=[\n");
141+
142+
143+
for (int i = 0, vinCount = transaction.getVinCount(); i < vinCount; i++) {
144+
TXInput vin = transaction.getVin(i);
145+
146+
sb.append("\t\t{\n" +
145147
"\t\t\ttxID=" + ByteArray.toHexString(vin.getTxID()
146148
.toByteArray()) + "\n" +
147149
"\t\t\tvout=" + vin.getVout() + "\n" +
148150
"\t\t\tsignature=" + ByteArray.toHexString(vin
149151
.getSignature().toByteArray()) + "\n" +
150152
"\t\t\tpubKey=" + ByteArray.toHexString(vin.getPubKey()
151153
.toByteArray()) + "\n" +
152-
"\t\t}";
154+
"\t\t}");
153155

154-
if (i != transaction.getVinList().size() - 1) {
155-
str += ",";
156+
if (i != vinCount - 1) {
157+
sb.append(",");
156158
}
157-
158-
i++;
159-
160-
str += "\n";
159+
sb.append("\n");
161160
}
162161

163-
str += "\t],\n\tvout=[\n";
162+
sb.append("\t],\n\tvout=[\n");
163+
164164

165-
i = 0;
166-
for (TXOutput vout : transaction.getVoutList()) {
167-
str += "\t\t{\n" +
165+
for (int i = 0, voutCount = transaction.getVoutCount(); i < voutCount; i++) {
166+
TXOutput vout = transaction.getVout(i);
167+
sb.append("\t\t{\n" +
168168
"\t\t\tvalue=" + vout.getValue() + "\n" +
169169
"\t\t\tpubKeyHash=" + ByteArray.toHexString(vout
170170
.getPubKeyHash().toByteArray()) + "\n" +
171-
"\t\t}";
171+
"\t\t}");
172172

173-
if (i != transaction.getVoutList().size() - 1) {
174-
str += ",";
173+
if (i != voutCount - 1) {
174+
sb.append(",");
175175
}
176-
177-
i++;
178-
179-
str += "\n";
176+
sb.append("\n");
180177
}
181178

182-
str += "\t]\n}";
179+
sb.append("\t]\n}");
183180

184-
return str;
181+
return sb.toString();
185182
}
186183

187184
/**

0 commit comments

Comments
 (0)