Skip to content

Commit fc5fc3e

Browse files
committed
feat(backup): optimize backup records
1 parent 141ec79 commit fc5fc3e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/main/java/org/tron/core/viewer/BackupRecordsViewer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void viewBackupRecords() {
8181

8282
private void printRecords(List<BackupRecord> records) {
8383
System.out.printf("%-33s %-52s %-47s %-25s%n",
84-
greenBoldHighlight("COMMAND"), greenBoldHighlight("FILE NAME"), greenBoldHighlight("LOGIN ADDRESS"), greenBoldHighlight("TIMESTAMP"));
84+
greenBoldHighlight("COMMAND"), greenBoldHighlight("FILE NAME"), greenBoldHighlight("ADDRESS"), greenBoldHighlight("TIMESTAMP"));
8585
System.out.println("-------------------------------------------------------------------------------------------------------------------");
8686

8787
for (BackupRecord br : records) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,15 @@ public byte[] backupWallet(String cmdName) throws IOException, CipherException {
649649
char[] password = Utils.inputPassword(false);
650650
byte[] passwd = char2Byte(password);
651651
clear(password);
652-
byte[] privateKey = wallet.getPrivateBytes(passwd);
652+
Pair<byte[], WalletFile> pair = wallet.getPair(passwd);
653653
clear(passwd);
654+
byte[] privateKey = pair.getLeft();
655+
WalletFile wf = pair.getRight();
654656
if (ArrayUtils.isNotEmpty(privateKey)) {
655657
new BackupRecordManager().saveRecord(new BackupRecord(
656658
cmdName,
657-
wallet.getWalletFile().getSourceFile().getName(),
658-
encode58Check(wallet.getAddress()),
659+
wf.getSourceFile().getName(),
660+
wf.getAddress(),
659661
LocalDateTime.now()));
660662
}
661663
return privateKey;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,16 @@ public byte[] getPrivateBytes(byte[] password) throws CipherException, IOExcepti
378378
return decrypt2PrivateBytes(password, loadWalletFile());
379379
}
380380

381+
public Pair<byte[], WalletFile> getPair(byte[] password) throws CipherException, IOException {
382+
WalletFile wf = loadWalletFile();
383+
byte[] bytes = decrypt2PrivateBytes(password, wf);
384+
return Pair.of(bytes, wf);
385+
}
386+
381387
public String exportKeystore(String walletChannel, File exportFullDir) throws IOException {
382388
String ret;
383389
try {
384-
WalletFile wf = this.walletFile.get(0);
390+
WalletFile wf = getWalletFile();
385391
String walletAddress = wf.getAddress();
386392
String walletHexAddress = getHexAddress(wf.getAddress());
387393
String originalAddress = wf.getAddress();

0 commit comments

Comments
 (0)