Skip to content

Commit cf2f831

Browse files
authored
feat(api): add resource price query API (#667)
1 parent ccec909 commit cf2f831

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ For more information on a specific command, just type the command on terminal wh
9999
| [UnfreezeBalanceV2](#How-to-freezev2) | [DelegateResource](#How-to-freezev2) | [UnDelegateResource](#How-to-freezev2) |
100100
| [WithdrawExpireUnfreeze](#How-to-freezev2) | [CancelAllUnfreezeV2](#How-to-freezev2) |[GetDelegatedResourceV2](#How-to-freezev2) |
101101
| [GetDelegatedResourceAccountIndexV2](#How-to-freezev2) | [GetCanDelegatedMaxSize](#How-to-freezev2) | [GetAvailableUnfreezeCount](#How-to-freezev2) |
102-
| [GetCanWithdrawUnfreezeAmount](#How-to-freezev2) | | |
102+
| [GetCanWithdrawUnfreezeAmount](#How-to-freezev2) |[GetBandwidthPrices](#Prices) | [GetEnergyPrices](#Prices)|
103+
| [GetMemoFee](#Prices) |||
103104

104105
Type any one of the listed commands, to display how-to tips.
105106

@@ -1473,6 +1474,36 @@ wallet> getCanWithdrawUnfreezeAmount TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 16711003
14731474
{
14741475
"amount": 9000000
14751476
}
1477+
```
1478+
> getbandwidthprices
1479+
> get historical unit price of bandwidth
1480+
1481+
Example:
1482+
```console
1483+
wallet> getBandwidthPrices
1484+
{
1485+
"prices": "0:10,1606537680000:40,1614238080000:140,1626581880000:1000,1626925680000:140,1627731480000:1000"
1486+
}
1487+
```
1488+
> getenergyprices
1489+
> get historical unit price of energy
1490+
1491+
Example:
1492+
```console
1493+
wallet> getEnergyPrices
1494+
{
1495+
"prices": "0:100,1575871200000:10,1606537680000:40,1614238080000:140,1635739080000:280,1681895880000:420"
1496+
}
1497+
```
1498+
> getmemofee
1499+
> get memo fee
1500+
1501+
Example:
1502+
```console
1503+
wallet> getMemoFee
1504+
{
1505+
"prices": "0:0,1675492680000:1000000"
1506+
}
14761507
```
14771508

14781509

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public class Client {
115115
"GetAssetIssueByName",
116116
"GetAssetIssueListByName",
117117
"GetBalance",
118+
"GetBandwidthPrices",
118119
"GetBlock",
119120
"GetBlockById",
120121
"GetBlockByIdOrNum",
@@ -132,6 +133,7 @@ public class Client {
132133
"GetAvailableUnfreezeCount",
133134
"GetCanWithdrawUnfreezeAmount",
134135
"GetDiversifier",
136+
"GetEnergyPrices",
135137
"GetExchange",
136138
"GetExpandedSpendingKey",
137139
"GetIncomingViewingKey",
@@ -140,6 +142,7 @@ public class Client {
140142
"GetMarketOrderListByPair",
141143
"GetMarketPairList",
142144
"GetMarketPriceByPair",
145+
"GetMemoFee",
143146
"GetNextMaintenanceTime",
144147
"GetNkFromNsk",
145148
"GetProposal",
@@ -258,6 +261,7 @@ public class Client {
258261
"GetAssetIssueByName",
259262
"GetAssetIssueListByName",
260263
"GetBalance",
264+
"GetBandwidthPrices",
261265
"GetBlock",
262266
"GetBlockById",
263267
"GetBlockByIdOrNum",
@@ -275,6 +279,7 @@ public class Client {
275279
"GetAvailableUnfreezeCount",
276280
"GetCanWithdrawUnfreezeAmount",
277281
"GetDiversifier",
282+
"GetEnergyPrices",
278283
"GetExchange",
279284
"GetExpandedSpendingKey",
280285
"GetIncomingViewingKey",
@@ -283,6 +288,7 @@ public class Client {
283288
"GetMarketOrderListByPair",
284289
"GetMarketPairList",
285290
"GetMarketPriceByPair",
291+
"GetMemoFee",
286292
"GetNextMaintenanceTime",
287293
"GetNkFromNsk",
288294
"GetProposal",
@@ -1533,6 +1539,36 @@ private void cancelAllUnfreezeV2(String[] parameters)
15331539
}
15341540
}
15351541

1542+
private void getBandwidthPrices(String[] parameters) {
1543+
if (parameters.length > 0) {
1544+
System.out.println("Use GetBandwidthPrices command with below syntax: ");
1545+
System.out.println("GetBandwidthPrices");
1546+
return;
1547+
}
1548+
PricesResponseMessage result = walletApiWrapper.getBandwidthPrices();
1549+
System.out.println("The BandwidthPrices is " + result.getPrices());
1550+
}
1551+
1552+
private void getEnergyPrices(String[] parameters) {
1553+
if (parameters.length > 0) {
1554+
System.out.println("Use GetEnergyPrices command with below syntax: ");
1555+
System.out.println("GetEnergyPrices");
1556+
return;
1557+
}
1558+
PricesResponseMessage result = walletApiWrapper.getEnergyPrices();
1559+
System.out.println("The EnergyPrices is "+ result.getPrices());
1560+
}
1561+
1562+
private void getMemoFee(String[] parameters) {
1563+
if (parameters.length > 0) {
1564+
System.out.println("Use GetMemoFee command with below syntax: ");
1565+
System.out.println("GetMemoFee");
1566+
return;
1567+
}
1568+
PricesResponseMessage result = walletApiWrapper.getMemoFee();
1569+
System.out.println("The MemoFee is " + result.getPrices());
1570+
}
1571+
15361572
private void unfreezeAsset(String[] parameters) throws IOException,
15371573
CipherException, CancelException {
15381574
System.out.println("Use UnfreezeAsset command like: ");
@@ -4938,6 +4974,18 @@ private void run() {
49384974
getBlockByIdOrNum(parameters);
49394975
break;
49404976
}
4977+
case "getbandwidthprices": {
4978+
getBandwidthPrices(parameters);
4979+
break;
4980+
}
4981+
case "getenergyprices": {
4982+
getEnergyPrices(parameters);
4983+
break;
4984+
}
4985+
case "getmemofee": {
4986+
getMemoFee(parameters);
4987+
break;
4988+
}
49414989
case "exit":
49424990
case "quit": {
49434991
System.out.println("Exit !!!");

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,18 @@ public GrpcAPI.NumberMessage getBrokerage(byte[] ownerAddress) {
12931293
return WalletApi.getBrokerage(ownerAddress);
12941294
}
12951295

1296+
public PricesResponseMessage getBandwidthPrices() {
1297+
return WalletApi.getBandwidthPrices();
1298+
}
1299+
1300+
public PricesResponseMessage getEnergyPrices() {
1301+
return WalletApi.getEnergyPrices();
1302+
}
1303+
1304+
public PricesResponseMessage getMemoFee() {
1305+
return WalletApi.getMemoFee();
1306+
}
1307+
12961308
public boolean scanShieldedTRC20NoteByIvk(byte[] address, final String ivk,
12971309
final String ak, final String nk,
12981310
long start, long end, String[] events) {

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,29 @@ public NumberMessage getBrokerage(byte[] address) {
10011001
}
10021002
}
10031003

1004+
public PricesResponseMessage getBandwidthPrices() {
1005+
EmptyMessage message = EmptyMessage.newBuilder().build();
1006+
if (blockingStubSolidity != null) {
1007+
return blockingStubSolidity.getBandwidthPrices(message);
1008+
} else {
1009+
return blockingStubFull.getBandwidthPrices(message);
1010+
}
1011+
}
1012+
1013+
public PricesResponseMessage getEnergyPrices() {
1014+
EmptyMessage message = EmptyMessage.newBuilder().build();
1015+
if (blockingStubSolidity != null) {
1016+
return blockingStubSolidity.getEnergyPrices(message);
1017+
} else {
1018+
return blockingStubFull.getEnergyPrices(message);
1019+
}
1020+
}
1021+
1022+
public PricesResponseMessage getMemoFee() {
1023+
EmptyMessage message = EmptyMessage.newBuilder().build();
1024+
return blockingStubFull.getMemoFee(message);
1025+
}
1026+
10041027
public Optional<TransactionInfoList> getTransactionInfoByBlockNum(long blockNum) {
10051028
TransactionInfoList transactionInfoList;
10061029
NumberMessage.Builder builder = NumberMessage.newBuilder();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.tron.api.GrpcAPI.OvkDecryptParameters;
5858
import org.tron.api.GrpcAPI.OvkDecryptTRC20Parameters;
5959
import org.tron.api.GrpcAPI.PaymentAddressMessage;
60+
import org.tron.api.GrpcAPI.PricesResponseMessage;
6061
import org.tron.api.GrpcAPI.PrivateParameters;
6162
import org.tron.api.GrpcAPI.PrivateParametersWithoutAsk;
6263
import org.tron.api.GrpcAPI.PrivateShieldedTRC20Parameters;
@@ -2730,6 +2731,18 @@ public static GrpcAPI.NumberMessage getBrokerage(byte[] owner) {
27302731
return rpcCli.getBrokerage(owner);
27312732
}
27322733

2734+
public static PricesResponseMessage getBandwidthPrices() {
2735+
return rpcCli.getBandwidthPrices();
2736+
}
2737+
2738+
public static PricesResponseMessage getEnergyPrices() {
2739+
return rpcCli.getEnergyPrices();
2740+
}
2741+
2742+
public static PricesResponseMessage getMemoFee() {
2743+
return rpcCli.getMemoFee();
2744+
}
2745+
27332746
public static Optional<DecryptNotesTRC20> scanShieldedTRC20NoteByIvk(
27342747
IvkDecryptTRC20Parameters parameters, boolean showErrorMsg) {
27352748
try {

0 commit comments

Comments
 (0)