Skip to content

Commit 94580b6

Browse files
committed
feature(receiving QR code): add receive payment QR code
1 parent 8feaa21 commit 94580b6

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.tron.common.utils.Utils.printBanner;
2020
import static org.tron.common.utils.Utils.printHelp;
2121
import static org.tron.common.utils.Utils.printStackTrace;
22+
import static org.tron.common.utils.Utils.redBoldHighlight;
2223
import static org.tron.common.utils.Utils.successfulHighlight;
2324
import static org.tron.keystore.StringUtils.byte2Char;
2425
import static org.tron.keystore.StringUtils.char2Byte;
@@ -31,8 +32,10 @@
3132
import com.beust.jcommander.Parameter;
3233
import com.google.common.primitives.Longs;
3334
import com.google.protobuf.InvalidProtocolBufferException;
35+
import java.io.BufferedReader;
3436
import java.io.File;
3537
import java.io.IOException;
38+
import java.io.InputStreamReader;
3639
import java.math.BigInteger;
3740
import java.nio.file.Files;
3841
import java.nio.file.Path;
@@ -103,6 +106,7 @@ public class Client {
103106

104107
// note: this is sorted by alpha
105108
private static String[] commandList = {
109+
"AddressBook",
106110
"AddTransactionSign",
107111
"ApproveProposal",
108112
"AssetIssue",
@@ -180,6 +184,7 @@ public class Client {
180184
"GetTransactionInfoById",
181185
"GetTransactionSignWeight",
182186
"GetUsdtBalance",
187+
"GetUsdtTransferById",
183188
"Help",
184189
"ImportWallet",
185190
"ImportWalletByMnemonic",
@@ -205,6 +210,7 @@ public class Client {
205210
"ResetWallet",
206211
"SendCoin",
207212
"SetAccountId",
213+
"ShowReceivingQrCode",
208214
"SwitchNetwork",
209215
"SwitchWallet",
210216
"TransferAsset",
@@ -3973,6 +3979,10 @@ private void run() {
39733979
unlock(parameters);
39743980
break;
39753981
}
3982+
case "showreceivingqrcode": {
3983+
showReceivingQrCode();
3984+
break;
3985+
}
39763986
default: {
39773987
System.out.println("Invalid cmd: " + cmd);
39783988
help(new String[]{});
@@ -3997,6 +4007,45 @@ private void run() {
39974007
}
39984008
}
39994009

4010+
private void showReceivingQrCode() {
4011+
String address = walletApiWrapper.getAddress();
4012+
if (address == null) {
4013+
return;
4014+
}
4015+
4016+
ProcessBuilder pb = new ProcessBuilder("qrencode", "-t", "ANSIUTF8", address);
4017+
pb.redirectErrorStream(true);
4018+
try {
4019+
Process process = pb.start();
4020+
4021+
try (BufferedReader reader = new BufferedReader(
4022+
new InputStreamReader(process.getInputStream()))) {
4023+
String line;
4024+
while ((line = reader.readLine()) != null) {
4025+
System.out.println(line);
4026+
}
4027+
}
4028+
4029+
int exitCode = process.waitFor();
4030+
if (exitCode != 0) {
4031+
System.err.println("Warning: qrencode exited with code " + exitCode);
4032+
}
4033+
} catch (IOException | InterruptedException e) {
4034+
System.out.println(redBoldHighlight("Failed to generate QR code: " + e.getMessage()));
4035+
System.out.println(redBoldHighlight("Error: 'qrencode' command not found. Please install it first."));
4036+
System.out.println("Qrencode terminal installation command:");
4037+
System.out.println(greenBoldHighlight("Debian/Ubuntu:"));
4038+
System.out.println("sudo apt update && sudo apt install qrencode");
4039+
System.out.println(greenBoldHighlight("RHEL/CentOS:"));
4040+
System.out.println("sudo yum install epel-release && sudo yum install qrencode");
4041+
System.out.println(greenBoldHighlight("Fedora:"));
4042+
System.out.println("sudo dnf install qrencode");
4043+
System.out.println(greenBoldHighlight("macOS:"));
4044+
System.out.println("brew install qrencode");
4045+
Thread.currentThread().interrupt();
4046+
}
4047+
}
4048+
40004049
private void getUsdtTransferById(String[] parameters) throws IOException {
40014050
NetType netType = WalletApi.getCurrentNetwork();
40024051
if (netType != MAIN && netType != NILE && netType != SHASTA) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.tron.common.enums.NetType.CUSTOM;
44
import static org.tron.common.utils.AbiUtil.generateOccupationConstantPrivateKey;
55
import static org.tron.common.utils.ByteArray.toHexString;
6+
import static org.tron.common.utils.Utils.redBoldHighlight;
67
import static org.tron.keystore.StringUtils.byte2String;
78
import static org.tron.trident.core.Constant.TRANSACTION_DEFAULT_EXPIRATION_TIME;
89
import static org.tron.trident.core.NodeType.FULL_NODE;
@@ -59,7 +60,14 @@ public ApiClient(String fullnode, String solidityNode, boolean emptyFullNode, bo
5960
}
6061

6162
private void enableLocalCreate(NodeType nodeType) {
62-
Response.BlockExtention blockExtention = client.getBlock(false, nodeType);
63+
Response.BlockExtention blockExtention;
64+
try {
65+
blockExtention = client.getBlock(false, nodeType);
66+
} catch (Exception e) {
67+
String node = nodeType == FULL_NODE ? "fullnode" : "soliditynode";
68+
System.out.println(redBoldHighlight("The " + node + ".ip.list you configured in the config.conf file is invalid."));
69+
return;
70+
}
6371
BlockId blockId = Utils.getBlockId(blockExtention);
6472
long expire = blockExtention.getBlockHeader().getRawData().getTimestamp()
6573
+ TRANSACTION_DEFAULT_EXPIRATION_TIME;

src/main/resources/commands.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,43 @@ ViewTransactionHistory
777777
Summary:
778778
View transaction history. You can configure the maximum number of records that `maxRecords` can retain in `config.conf`, excluding the number of buffer records.
779779
Usage example:
780-
wallet> ViewTransactionHistory
780+
wallet> ViewTransactionHistory
781+
Syntax:
782+
AddressBook
783+
Summary:
784+
Addition, deletion, modification, and search of address book.
785+
Usage example:
786+
wallet> AddressBook
787+
Syntax:
788+
GetUsdtBalance [owner_address]
789+
Summary:
790+
Get the USDT balance of the current address.
791+
Usage example:
792+
wallet> GetUsdtBalance
793+
Syntax:
794+
GetUsdtTransferById txId
795+
Summary:
796+
Get USDT transfer transaction summary based on transaction ID.
797+
Usage example:
798+
wallet> GetUsdtTransferById a9e24b117ee0fa8007693dbd3741a9168a8d79d366828e667421c965cc8300a5
799+
Syntax:
800+
TransferUSDT [owner_address] to_address amount
801+
Summary:
802+
Make a USDT transfer.
803+
Usage example:
804+
wallet> TransferUSDT TEDapYSVvAZ3aYH7w8N9tMEEFKaNKUD5Bp 1000000
805+
Syntax:
806+
ShowReceivingQrCode
807+
Summary:
808+
Display Receive Payment QR Code for the current address.
809+
Executing this command requires installing 'qrencode' on the terminal in advance.
810+
Debian/Ubuntu:
811+
sudo apt update && sudo apt install qrencode
812+
RHEL/CentOS:
813+
sudo yum install epel-release && sudo yum install qrencode
814+
Fedora:
815+
sudo dnf install qrencode
816+
macOS:
817+
brew install qrencode
818+
Usage example:
819+
wallet> ShowReceivingQrCode

src/main/resources/help_summary.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
+---------------------------------------------------+-------------------------------------------------------------------------+
22
| COMMAND | SUMMARY |
33
+---------------------------------------------------+-------------------------------------------------------------------------+
4-
| ACCOUNT MANAGEMENT (12) | |
4+
| ACCOUNT MANAGEMENT (15) | |
55
+---------------------------------------------------+-------------------------------------------------------------------------+
66
| GenerateAddress | Generate an address and print out the address and private key |
77
| GetAccount | Get account details information |
88
| GetAccountById | Get account details information through account id |
99
| GetAddress | Get the address of the current account |
1010
| GetBalance | Get the current TRX balance of the account |
11+
| GetUsdtBalance | Get the current USDT balance of the account |
1112
| CreateAccount | Activating an account |
1213
| UpdateAccount | Update account name |
1314
| UpdateAccountPermission | Update account permissions |
1415
| SetAccountId | Sets a custom unique identifier for an account |
1516
| GetReward | Get the rewards that a SR or a user has not yet withdrawn |
1617
| WithdrawBalance | Withdraw rewards |
1718
| SendCoin | Create a TRX transfer transaction |
19+
| AddressBook | Addition, deletion, modification, and search of address book |
20+
| ShowReceivingQrCode | Display Receive Payment QR Code for the current address |
1821
|---------------------------------------------------+-------------------------------------------------------------------------+
1922
| RESOURCE MANAGEMENT (19) | |
2023
+---------------------------------------------------+-------------------------------------------------------------------------+
@@ -38,7 +41,7 @@
3841
| GetBandwidthPrices | Get historical bandwidth unit price |
3942
| GetEnergyPrices | Get historical energy unit price |
4043
|---------------------------------------------------+-------------------------------------------------------------------------+
41-
| TRANSACTIONS (9) | |
44+
| TRANSACTIONS (10) | |
4245
+---------------------------------------------------+-------------------------------------------------------------------------+
4346
| AddTransactionSign | Add signature to hex format transaction |
4447
| BroadcastTransaction | Broadcast transactions in hex string format |
@@ -48,11 +51,13 @@
4851
| GetTransactionInfoById | Get transaction information through transaction ID |
4952
| GetTransactionInfoByBlockNum | Get all transaction information through block number |
5053
| GetTransactionCountByBlockNum | Get the number of transactions through block number |
54+
| GetUsdtTransferById | Get USDT transfer transaction summary based on transaction ID |
5155
| ViewTransactionHistory | View transaction history |
5256
|---------------------------------------------------+-------------------------------------------------------------------------+
53-
| SMART CONTRACTS (10) | |
57+
| SMART CONTRACTS (11) | |
5458
+---------------------------------------------------+-------------------------------------------------------------------------+
5559
| DeployContract | Deploy a smart contract |
60+
| TransferUSDT | Make a USDT transfer |
5661
| TriggerContract | Create a smart contract transaction |
5762
| TriggerConstantContract | Dry-run a smart contract function |
5863
| EstimateEnergy | Estimate the energy of a smart contract transaction |

0 commit comments

Comments
 (0)