From 71fa3ae767ce460edd75968ebbdd27116e09abf7 Mon Sep 17 00:00:00 2001 From: chaozhu Date: Fri, 9 Dec 2022 15:48:00 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat(freezeV2):=20merge=20feature=20?= =?UTF-8?q?=E2=80=98stake=202.0=E2=80=99=20into=20release=20v4.7.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/tron/common/utils/Utils.java | 38 ++ src/main/java/org/tron/walletcli/Client.java | 391 ++++++++++++++++++ .../org/tron/walletcli/WalletApiWrapper.java | 85 ++++ .../org/tron/walletserver/GrpcClient.java | 119 ++++++ .../java/org/tron/walletserver/WalletApi.java | 173 ++++++++ src/main/protos/api/api.proto | 78 ++++ src/main/protos/core/Tron.proto | 32 ++ .../core/contract/balance_contract.proto | 31 ++ 8 files changed, 947 insertions(+) diff --git a/src/main/java/org/tron/common/utils/Utils.java b/src/main/java/org/tron/common/utils/Utils.java index 079f609d5..caa517565 100644 --- a/src/main/java/org/tron/common/utils/Utils.java +++ b/src/main/java/org/tron/common/utils/Utils.java @@ -41,6 +41,7 @@ import org.tron.common.crypto.Hash; import org.tron.common.crypto.Sha256Sm3Hash; import org.tron.keystore.StringUtils; +import org.tron.protos.contract.BalanceContract; import org.tron.walletserver.WalletApi; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.Transaction; @@ -581,6 +582,43 @@ public static JSONObject printTransactionToJSON(Transaction transaction, boolean contractJson = JSONObject .parseObject(JsonFormat.printToString(marketCancelOrderContract, selfType)); break; + // new freeze begin + case FreezeBalanceV2Contract: + BalanceContract.FreezeBalanceV2Contract freezeBalanceV2Contract = + contractParameter.unpack(BalanceContract.FreezeBalanceV2Contract.class); + contractJson = + JSONObject.parseObject( + JsonFormat.printToString(freezeBalanceV2Contract, selfType)); + break; + case UnfreezeBalanceV2Contract: + BalanceContract.UnfreezeBalanceV2Contract unfreezeBalanceV2Contract = + contractParameter.unpack(BalanceContract.UnfreezeBalanceV2Contract.class); + contractJson = + JSONObject.parseObject( + JsonFormat.printToString(unfreezeBalanceV2Contract, selfType)); + break; + case WithdrawExpireUnfreezeContract: + BalanceContract.WithdrawExpireUnfreezeContract withdrawExpireUnfreezeContract = + contractParameter.unpack(BalanceContract.WithdrawExpireUnfreezeContract.class); + contractJson = + JSONObject.parseObject( + JsonFormat.printToString(withdrawExpireUnfreezeContract, selfType)); + break; + case DelegateResourceContract: + BalanceContract.DelegateResourceContract delegateResourceContract = + contractParameter.unpack(BalanceContract.DelegateResourceContract.class); + contractJson = + JSONObject.parseObject( + JsonFormat.printToString(delegateResourceContract, selfType)); + break; + case UnDelegateResourceContract: + BalanceContract.UnDelegateResourceContract unDelegateResourceContract = + contractParameter.unpack(BalanceContract.UnDelegateResourceContract.class); + contractJson = + JSONObject.parseObject( + JsonFormat.printToString(unDelegateResourceContract, selfType)); + break; + // new freeze end // todo add other contract default: } diff --git a/src/main/java/org/tron/walletcli/Client.java b/src/main/java/org/tron/walletcli/Client.java index f84d5c731..5b2b3a3e3 100755 --- a/src/main/java/org/tron/walletcli/Client.java +++ b/src/main/java/org/tron/walletcli/Client.java @@ -65,6 +65,7 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContractDataWrapper; import org.tron.walletserver.WalletApi; +import org.tron.protos.contract.Common.ResourceCode; @@ -96,6 +97,7 @@ public class Client { "ExchangeTransaction", "ExchangeWithdraw", "FreezeBalance", + "FreezeBalanceV2", "GenerateAddress", // "GenerateShieldedAddress", "GenerateShieldedTRC20Address", @@ -119,6 +121,12 @@ public class Client { "GetContract contractAddress", "GetContractInfo contractAddress", "GetDelegatedResource", + "GetDelegatedResourceV2", + "GetDelegatedResourceAccountIndex", + "GetDelegatedResourceAccountIndexV2", + "GetCanDelegatedMaxSize", + "GetAvailableUnfreezeCount", + "GetCanWithdrawUnfreezeAmount", "GetDiversifier", "GetExchange", "GetExpandedSpendingKey", @@ -192,6 +200,7 @@ public class Client { "TriggerContract contractAddress method args isHex fee_limit value", "UnfreezeAsset", "UnfreezeBalance", + "UnfreezeBalanceV2", "UpdateAccount", "UpdateAccountPermission", "UpdateAsset", @@ -201,6 +210,9 @@ public class Client { "UpdateWitness", "VoteWitness", "WithdrawBalance", + "WithdrawExpireUnfreeze", + "DelegateResource", + "UnDelegateResource", }; // note: this is sorted by alpha @@ -249,7 +261,12 @@ public class Client { "GetContract", "GetContractInfo", "GetDelegatedResource", + "GetDelegatedResourceV2", "GetDelegatedResourceAccountIndex", + "GetDelegatedResourceAccountIndexV2", + "GetCanDelegatedMaxSize", + "GetAvailableUnfreezeCount", + "GetCanWithdrawUnfreezeAmount", "GetDiversifier", "GetExchange", "GetExpandedSpendingKey", @@ -1243,6 +1260,45 @@ private void freezeBalance(String[] parameters) } } + private void freezeBalanceV2(String[] parameters) + throws IOException, CipherException, CancelException { + if (parameters == null || !(parameters.length == 2 || parameters.length == 3)) { + System.out.println("Use freezeBalanceV2 command with below syntax: "); + System.out.println("freezeBalanceV2 [OwnerAddress] frozen_balance " + + "[ResourceCode:0 BANDWIDTH,1 ENERGY,2 TRON_POWER]"); + return; + } + + int index = 0; + boolean hasOwnerAddressPara = false; + byte[] ownerAddress = getAddressBytes(parameters[index]); + if (ownerAddress != null) { + index++; + hasOwnerAddressPara = true; + } + + long frozen_balance = Long.parseLong(parameters[index++]); + int resourceCode = 0; + + if ((!hasOwnerAddressPara && (parameters.length == 2)) || + (hasOwnerAddressPara && (parameters.length == 3))) { + try { + resourceCode = Integer.parseInt(parameters[index]); + } catch (NumberFormatException e) { + System.out.println("freezeBalanceV2 [ResourceCode:0 BANDWIDTH,1 ENERGY,2 TRON_POWER]"); + return; + } + } + + boolean result = walletApiWrapper.freezeBalanceV2(ownerAddress, frozen_balance + , resourceCode); + if (result) { + System.out.println("freezeBalanceV2 successful !!!"); + } else { + System.out.println("freezeBalanceV2 failed !!!"); + } + } + private void unfreezeBalance(String[] parameters) throws IOException, CipherException, CancelException { if (parameters == null || parameters.length < 1 || parameters.length > 3) { @@ -1281,6 +1337,174 @@ private void unfreezeBalance(String[] parameters) } } + private void unfreezeBalanceV2(String[] parameters) + throws IOException, CipherException, CancelException { + if (parameters == null || !(parameters.length == 2 || parameters.length == 3)) { + System.out.println("Use unfreezeBalanceV2 command with below syntax: "); + System.out.println( + "unfreezeBalanceV2 [OwnerAddress] unfreezeBalance ResourceCode(0 BANDWIDTH,1 ENERGY,2 TRON_POWER)"); + return; + } + + int index = 0; + byte[] ownerAddress = null; + long unfreezeBalance = 0; + int resourceCode = 0; + if (parameters.length == 2) { + unfreezeBalance = Long.parseLong(parameters[index++]); + resourceCode = Integer.parseInt(parameters[index++]); + } else if (parameters.length == 3) { + ownerAddress = getAddressBytes(parameters[index]); + if (ownerAddress != null) { + index++; + unfreezeBalance = Long.parseLong(parameters[index++]); + resourceCode = Integer.parseInt(parameters[index++]); + } else { + System.out.println( + "unfreezeBalanceV2 OwnerAddress is invalid"); + return; + } + } + + boolean result = walletApiWrapper.unfreezeBalanceV2(ownerAddress, unfreezeBalance, resourceCode); + if (result) { + System.out.println("unfreezeBalanceV2 successful !!!"); + } else { + System.out.println("unfreezeBalanceV2 failed !!!"); + } + } + + private void withdrawExpireUnfreeze(String[] parameters) + throws IOException, CipherException, CancelException { + if (parameters == null || !(parameters.length == 0 || parameters.length == 1)) { + System.out.println("Use withdrawExpireUnfreeze command with below syntax: "); + System.out.println( + "withdrawExpireUnfreeze OwnerAddress"); + return; + } + + byte[] ownerAddress = null; + if (parameters.length == 1) { + ownerAddress = getAddressBytes(parameters[0]); + if (ownerAddress == null) { + System.out.println( + "withdrawExpireUnfreeze OwnerAddress is invalid"); + return; + } + } + + boolean result = walletApiWrapper.withdrawExpireUnfreeze(ownerAddress); + if (result) { + System.out.println("withdrawExpireUnfreeze successful !!!"); + } else { + System.out.println("withdrawExpireUnfreeze failed !!!"); + } + } + + private void delegateResource(String[] parameters) + throws IOException, CipherException, CancelException { + if (parameters == null || !(parameters.length == 3 || parameters.length == 4 || parameters.length == 5)) { + System.out.println("Use delegateResource command with below syntax: "); + System.out.println( + "delegateResource [OwnerAddress] balance ResourceCode(0 BANDWIDTH,1 ENERGY), ReceiverAddress [lock]"); + return; + } + + int index = 0; + byte[] ownerAddress = null; + long balance = 0; + int resourceCode = 0; + byte[] receiverAddress = null; + boolean lock = false; + + if (parameters.length == 3) { + balance = Long.parseLong(parameters[index++]); + resourceCode = Integer.parseInt(parameters[index++]); + receiverAddress = getAddressBytes(parameters[index++]); + if (receiverAddress == null) { + System.out.println( + "delegateResource receiverAddress is invalid"); + return; + } + } else if (parameters.length == 4 || parameters.length == 5) { + ownerAddress = getAddressBytes(parameters[index++]); + if (ownerAddress != null) { + balance = Long.parseLong(parameters[index++]); + resourceCode = Integer.parseInt(parameters[index++]); + receiverAddress = getAddressBytes(parameters[index++]); + if (receiverAddress == null) { + System.out.println( + "delegateResource receiverAddress is invalid"); + return; + } + if (parameters.length == 5) { + lock = Boolean.parseBoolean(parameters[index++]); + } + } if (ownerAddress == null) { + System.out.println( + "delegateResource ownerAddress is invalid"); + return; + } + } + + + boolean result = walletApiWrapper.delegateresource( + ownerAddress, balance, resourceCode, receiverAddress, lock); + if (result) { + System.out.println("delegateResource successful !!!"); + } else { + System.out.println("delegateResource failed !!!"); + } + } + + private void unDelegateResource(String[] parameters) + throws IOException, CipherException, CancelException { + if (parameters == null || !(parameters.length == 3 || parameters.length == 4)) { + System.out.println("Use unDelegateResource command with below syntax: "); + System.out.println( + "unDelegateResource [OwnerAddress] balance ResourceCode(0 BANDWIDTH,1 ENERGY), ReceiverAddress"); + return; + } + + int index = 0; + byte[] ownerAddress = null; + long balance = 0; + int resourceCode = 0; + byte[] receiverAddress = null; + if (parameters.length == 3) { + balance = Long.parseLong(parameters[index++]); + resourceCode = Integer.parseInt(parameters[index++]); + receiverAddress = getAddressBytes(parameters[index++]); + if (receiverAddress == null) { + System.out.println( + "unDelegateResource receiverAddress is invalid"); + return; + } + } else if (parameters.length == 4) { + ownerAddress = getAddressBytes(parameters[index++]); + if (ownerAddress != null) { + balance = Long.parseLong(parameters[index++]); + resourceCode = Integer.parseInt(parameters[index++]); + receiverAddress = getAddressBytes(parameters[index++]); + if (receiverAddress == null) { + System.out.println( + "unDelegateResource receiverAddress is invalid"); + return; + } + } if (ownerAddress == null) { + System.out.println( + "unDelegateResource ownerAddress is invalid"); + return; + } + } + boolean result = walletApiWrapper.undelegateresource(ownerAddress, balance, resourceCode, receiverAddress); + if (result) { + System.out.println("unDelegateResource successful !!!"); + } else { + System.out.println("unDelegateResource failed !!!"); + } + } + private void unfreezeAsset(String[] parameters) throws IOException, CipherException, CancelException { System.out.println("Use UnfreezeAsset command like: "); @@ -1435,7 +1659,130 @@ private void getDelegatedResource(String[] parameters) { } } + private void getDelegatedResourceAccountIndex(String[] parameters) { + if (parameters == null || parameters.length != 1) { + System.out.println("Using getDelegatedResourceAccountIndex command needs 1 parameters like: "); + System.out.println("getDelegatedResourceAccountIndex ownerAddress"); + return; + } + String ownerAddress = parameters[0]; + Optional result = WalletApi.getDelegatedResourceAccountIndex(ownerAddress); + if (result.isPresent()) { + DelegatedResourceAccountIndex delegatedResourceAccountIndex = result.get(); + System.out.println(Utils.formatMessageString(delegatedResourceAccountIndex)); + } else { + System.out.println("GetDelegatedResourceAccountIndex failed !!!"); + } + } + + private void getDelegatedResourceV2(String[] parameters) { + if (parameters == null || parameters.length != 2) { + System.out.println("Using getdelegatedresourcev2 command needs 2 parameters like: "); + System.out.println("getdelegatedresourcev2 fromAddress toAddress"); + return; + } + String fromAddress = parameters[0]; + String toAddress = parameters[1]; + Optional result = WalletApi.getDelegatedResourceV2(fromAddress, toAddress); + if (result.isPresent()) { + DelegatedResourceList delegatedResourceList = result.get(); + System.out.println(Utils.formatMessageString(delegatedResourceList)); + } else { + System.out.println("GetDelegatedResourceV2 failed !!!"); + } + } + + private void getDelegatedResourceAccountIndexV2(String[] parameters) { + if (parameters == null || parameters.length != 1) { + System.out.println("Using getDelegatedResourceAccountIndexV2 command needs 1 parameters like: "); + System.out.println("getdelegatedresourceaccountindexv2 ownerAddress"); + return; + } + String ownerAddress = parameters[0]; + Optional result = WalletApi.getDelegatedResourceAccountIndexV2(ownerAddress); + if (result.isPresent()) { + DelegatedResourceAccountIndex delegatedResourceAccountIndex = result.get(); + System.out.println(Utils.formatMessageString(delegatedResourceAccountIndex)); + } else { + System.out.println("GetDelegatedResourceAccountIndexV2 failed !!!"); + } + } + + private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherException, IOException, CancelException { + if (parameters == null || !(parameters.length == 1 || parameters.length == 2)) { + System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: "); + System.out.println("getcanwithdrawunfreezeamount [ownerAddress] timestamp"); + return; + } + int index = 0; + long timestamp = 0; + byte[] ownerAddress = getAddressBytes(parameters[index]); + if (ownerAddress != null) { + index++; + } + timestamp = Long.parseLong(parameters[index++]); + if (timestamp < 0) { + System.out.println("Invalid param, timestamp >= 0"); + return; + } + + Optional result = walletApiWrapper. + getCanWithdrawUnfreezeAmount(ownerAddress, timestamp); + if (result.isPresent()) { + CanWithdrawUnfreezeAmountResponseMessage canWithdrawUnfreezeAmountResponseMessage = result.get(); + System.out.println(Utils.formatMessageString(canWithdrawUnfreezeAmountResponseMessage)); + } else { + System.out.println("GetCanWithdrawUnfreezeAmount failed !!!"); + } + } + + private void getCanDelegatedMaxSize(String[] parameters) throws CipherException, IOException, CancelException { + if (parameters == null || !(parameters.length == 1 || parameters.length == 2)) { + System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: "); + System.out.println("getcandelegatedmaxsize [ownerAddress] type"); + return; + } + int index = 0; + int type = 0; + byte[] ownerAddress = getAddressBytes(parameters[index]); + if (ownerAddress != null) { + index++; + } + type = Integer.parseInt(parameters[index++]); + if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) { + System.out.println("getcandelegatedmaxsize param type must be: 0 or 1"); + return; + } + + Optional result = walletApiWrapper.getCanDelegatedMaxSize(ownerAddress, type); + if (result.isPresent()) { + CanDelegatedMaxSizeResponseMessage canDelegatedMaxSizeResponseMessage = result.get(); + System.out.println(Utils.formatMessageString(canDelegatedMaxSizeResponseMessage)); + } else { + System.out.println("GetCanDelegatedMaxSize failed !!!"); + } + } + + private void getAvailableUnfreezeCount(String[] parameters) throws CipherException, IOException, CancelException { + if (parameters == null || !(parameters.length == 0 || parameters.length == 1)) { + System.out.println("Using getavailableunfreezecount command needs 1 parameters like: "); + System.out.println("getavailableunfreezecount [owner_address] "); + return; + } + int index = 0; + byte[] ownerAddress = null; + if (parameters.length == 1) { + ownerAddress = getAddressBytes(parameters[index]); + } + Optional result = walletApiWrapper.getAvailableUnfreezeCount(ownerAddress); + if (result.isPresent()) { + GetAvailableUnfreezeCountResponseMessage getAvailableUnfreezeCountResponseMessage = result.get(); + System.out.println(Utils.formatMessageString(getAvailableUnfreezeCountResponseMessage)); + } else { + System.out.println("GetAvailableUnfreezeCount failed !!!"); + } + } private void exchangeCreate(String[] parameters) throws IOException, CipherException, CancelException { @@ -4001,10 +4348,30 @@ private void run() { freezeBalance(parameters); break; } + case "freezebalancev2": { + freezeBalanceV2(parameters); + break; + } case "unfreezebalance": { unfreezeBalance(parameters); break; } + case "unfreezebalancev2": { + unfreezeBalanceV2(parameters); + break; + } + case "withdrawexpireunfreeze": { + withdrawExpireUnfreeze(parameters); + break; + } + case "delegateresource": { + delegateResource(parameters); + break; + } + case "undelegateresource": { + unDelegateResource(parameters); + break; + } case "withdrawbalance": { withdrawBalance(parameters); break; @@ -4041,6 +4408,30 @@ private void run() { getDelegatedResource(parameters); break; } + case "getdelegatedresourceaccountindex": { + getDelegatedResourceAccountIndex(parameters); + break; + } + case "getdelegatedresourcev2": { + getDelegatedResourceV2(parameters); + break; + } + case "getdelegatedresourceaccountindexv2": { + getDelegatedResourceAccountIndexV2(parameters); + break; + } + case "getcandelegatedmaxsize": { + getCanDelegatedMaxSize(parameters); + break; + } + case "getavailableunfreezecount": { + getAvailableUnfreezeCount(parameters); + break; + } + case "getcanwithdrawunfreezeamount": { + getCanWithdrawUnfreezeAmount(parameters); + break; + } case "exchangecreate": { exchangeCreate(parameters); break; diff --git a/src/main/java/org/tron/walletcli/WalletApiWrapper.java b/src/main/java/org/tron/walletcli/WalletApiWrapper.java index 5778eceaa..d68f666d6 100644 --- a/src/main/java/org/tron/walletcli/WalletApiWrapper.java +++ b/src/main/java/org/tron/walletcli/WalletApiWrapper.java @@ -482,6 +482,17 @@ public boolean freezeBalance(byte[] ownerAddress, long frozen_balance, long froz receiverAddress); } + public boolean freezeBalanceV2(byte[] ownerAddress, long frozen_balance, + int resourceCode) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: freezeBalanceV2 failed, Please login first !!"); + return false; + } + + return wallet.freezeBalanceV2(ownerAddress, frozen_balance, resourceCode); + } + public boolean buyStorage(byte[] ownerAddress, long quantity) throws CipherException, IOException, CancelException { if (wallet == null || !wallet.isLoginState()) { @@ -523,6 +534,80 @@ public boolean unfreezeBalance(byte[] ownerAddress, int resourceCode, byte[] rec return wallet.unfreezeBalance(ownerAddress, resourceCode, receiverAddress); } + public boolean unfreezeBalanceV2(byte[] ownerAddress, long unfreezeBalance + , int resourceCode) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: unfreezeBalanceV2 failed, Please login first !!"); + return false; + } + + return wallet.unfreezeBalanceV2(ownerAddress, unfreezeBalance, resourceCode); + } + + public boolean withdrawExpireUnfreeze(byte[] ownerAddress) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: withdrawExpireUnfreeze failed, Please login first !!"); + return false; + } + + return wallet.withdrawExpireUnfreeze(ownerAddress); + } + + public boolean delegateresource(byte[] ownerAddress, long balance + , int resourceCode, byte[] receiverAddress, boolean lock) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: delegateresource failed, Please login first !!"); + return false; + } + + return wallet.delegateResource(ownerAddress, balance + , resourceCode, receiverAddress, lock); + } + + public boolean undelegateresource(byte[] ownerAddress, long balance + , int resourceCode, byte[] receiverAddress) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: undelegateresource failed, Please login first !!"); + return false; + } + + return wallet.unDelegateResource(ownerAddress, balance, resourceCode, receiverAddress); + } + + public Optional getCanWithdrawUnfreezeAmount( + byte[] ownerAddress, long timestamp) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: getCanWithdrawUnfreezeAmount failed, Please login first !!"); + return Optional.empty(); + } + + return wallet.getCanWithdrawUnfreezeAmount(ownerAddress, timestamp); + } + + public Optional getCanDelegatedMaxSize(byte[] ownerAddress, int type) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: getCanDelegatedMaxSize failed, Please login first !!"); + return Optional.empty(); + } + + return wallet.getCanDelegatedMaxSize(ownerAddress, type); + } + + public Optional getAvailableUnfreezeCount(byte[] ownerAddress) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: getAvailableUnfreezeCount failed, Please login first !!"); + return Optional.empty(); + } + + return wallet.getAvailableUnfreezeCount(ownerAddress); + } public boolean unfreezeAsset(byte[] ownerAddress) throws CipherException, IOException, CancelException { diff --git a/src/main/java/org/tron/walletserver/GrpcClient.java b/src/main/java/org/tron/walletserver/GrpcClient.java index 2ea3ea9c0..a83a9a7d0 100644 --- a/src/main/java/org/tron/walletserver/GrpcClient.java +++ b/src/main/java/org/tron/walletserver/GrpcClient.java @@ -43,6 +43,7 @@ import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract; import org.tron.protos.contract.AssetIssueContractOuterClass.UnfreezeAssetContract; import org.tron.protos.contract.AssetIssueContractOuterClass.UpdateAssetContract; +import org.tron.protos.contract.BalanceContract; import org.tron.protos.contract.BalanceContract.FreezeBalanceContract; import org.tron.protos.contract.BalanceContract.TransferContract; import org.tron.protos.contract.BalanceContract.UnfreezeBalanceContract; @@ -263,6 +264,10 @@ public TransactionExtention createTransaction2(FreezeBalanceContract contract) { return blockingStubFull.freezeBalance2(contract); } + public TransactionExtention createTransaction2(BalanceContract.FreezeBalanceV2Contract contract) { + return blockingStubFull.freezeBalanceV2(contract); + } + public Transaction createTransaction(WithdrawBalanceContract contract) { return blockingStubFull.withdrawBalance(contract); } @@ -279,6 +284,22 @@ public TransactionExtention createTransaction2(UnfreezeBalanceContract contract) return blockingStubFull.unfreezeBalance2(contract); } + public TransactionExtention createTransactionV2(BalanceContract.UnfreezeBalanceV2Contract contract) { + return blockingStubFull.unfreezeBalanceV2(contract); + } + + public TransactionExtention createTransactionV2(BalanceContract.WithdrawExpireUnfreezeContract contract) { + return blockingStubFull.withdrawExpireUnfreeze(contract); + } + + public TransactionExtention createTransactionV2(BalanceContract.DelegateResourceContract contract) { + return blockingStubFull.delegateResource(contract); + } + + public TransactionExtention createTransactionV2(BalanceContract.UnDelegateResourceContract contract) { + return blockingStubFull.unDelegateResource(contract); + } + public Transaction createTransaction(UnfreezeAssetContract contract) { return blockingStubFull.unfreezeAsset(contract); } @@ -360,6 +381,104 @@ public Optional getDelegatedResource(String fromAddress, return Optional.ofNullable(delegatedResource); } + public Optional getDelegatedResourceAccountIndex(String ownerAddress) { + ByteString ownerAddressBS = ByteString.copyFrom( + Objects.requireNonNull(WalletApi.decodeFromBase58Check(ownerAddress))); + + BytesMessage request = BytesMessage.newBuilder() + .setValue(ownerAddressBS) + .build(); + DelegatedResourceAccountIndex delegatedResourceAccountIndex; + if (blockingStubSolidity != null) { + delegatedResourceAccountIndex = blockingStubSolidity.getDelegatedResourceAccountIndex(request); + } else { + delegatedResourceAccountIndex = blockingStubFull.getDelegatedResourceAccountIndex(request); + } + return Optional.ofNullable(delegatedResourceAccountIndex); + } + + public Optional getDelegatedResourceV2(String fromAddress, + String toAddress) { + ByteString fromAddressBS = ByteString.copyFrom( + Objects.requireNonNull(WalletApi.decodeFromBase58Check(fromAddress))); + ByteString toAddressBS = ByteString.copyFrom( + Objects.requireNonNull(WalletApi.decodeFromBase58Check(toAddress))); + + DelegatedResourceMessage request = DelegatedResourceMessage.newBuilder() + .setFromAddress(fromAddressBS) + .setToAddress(toAddressBS) + .build(); + DelegatedResourceList delegatedResource; + if (blockingStubSolidity != null) { + delegatedResource = blockingStubSolidity.getDelegatedResourceV2(request); + } else { + delegatedResource = blockingStubFull.getDelegatedResourceV2(request); + } + return Optional.ofNullable(delegatedResource); + } + + public Optional getDelegatedResourceAccountIndexV2(String ownerAddress) { + ByteString ownerAddressBS = ByteString.copyFrom( + Objects.requireNonNull(WalletApi.decodeFromBase58Check(ownerAddress))); + + BytesMessage request = BytesMessage.newBuilder() + .setValue(ownerAddressBS) + .build(); + DelegatedResourceAccountIndex delegatedResourceAccountIndex; + if (blockingStubSolidity != null) { + delegatedResourceAccountIndex = blockingStubSolidity.getDelegatedResourceAccountIndexV2(request); + } else { + delegatedResourceAccountIndex = blockingStubFull.getDelegatedResourceAccountIndexV2(request); + } + return Optional.ofNullable(delegatedResourceAccountIndex); + } + + public Optional getCanDelegatedMaxSize( + byte[] ownerAddress, int type) { + ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); + CanDelegatedMaxSizeRequestMessage request = CanDelegatedMaxSizeRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .setType(type) + .build(); + CanDelegatedMaxSizeResponseMessage canDelegatedMaxSizeResponseMessage; + if (blockingStubSolidity != null) { + canDelegatedMaxSizeResponseMessage = blockingStubSolidity.getCanDelegatedMaxSize(request); + } else { + canDelegatedMaxSizeResponseMessage = blockingStubFull.getCanDelegatedMaxSize(request); + } + return Optional.ofNullable(canDelegatedMaxSizeResponseMessage); + } + + public Optional getCanWithdrawUnfreezeAmount( + byte[] ownerAddress, long timestamp) { + ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); + CanWithdrawUnfreezeAmountRequestMessage request = CanWithdrawUnfreezeAmountRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .setTimestamp(timestamp) + .build(); + CanWithdrawUnfreezeAmountResponseMessage canDelegatedMaxSizeResponseMessage; + if (blockingStubSolidity != null) { + canDelegatedMaxSizeResponseMessage = blockingStubSolidity.getCanWithdrawUnfreezeAmount(request); + } else { + canDelegatedMaxSizeResponseMessage = blockingStubFull.getCanWithdrawUnfreezeAmount(request); + } + return Optional.ofNullable(canDelegatedMaxSizeResponseMessage); + } + + public Optional getAvailableUnfreezeCount( + byte[] ownerAddress) { + ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); + GetAvailableUnfreezeCountRequestMessage request = GetAvailableUnfreezeCountRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .build(); + GetAvailableUnfreezeCountResponseMessage getAvailableUnfreezeCountResponseMessage; + if (blockingStubSolidity != null) { + getAvailableUnfreezeCountResponseMessage = blockingStubSolidity.getAvailableUnfreezeCount(request); + } else { + getAvailableUnfreezeCountResponseMessage = blockingStubFull.getAvailableUnfreezeCount(request); + } + return Optional.ofNullable(getAvailableUnfreezeCountResponseMessage); + } public Optional listExchanges() { ExchangeList exchangeList; diff --git a/src/main/java/org/tron/walletserver/WalletApi.java b/src/main/java/org/tron/walletserver/WalletApi.java index a000cace5..a11bdcab5 100644 --- a/src/main/java/org/tron/walletserver/WalletApi.java +++ b/src/main/java/org/tron/walletserver/WalletApi.java @@ -97,6 +97,7 @@ import org.tron.keystore.Wallet; import org.tron.keystore.WalletFile; import org.tron.keystore.WalletUtils; +import org.tron.protos.Protocol; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.ChainParameters; @@ -123,6 +124,7 @@ import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract; import org.tron.protos.contract.AssetIssueContractOuterClass.UnfreezeAssetContract; import org.tron.protos.contract.AssetIssueContractOuterClass.UpdateAssetContract; +import org.tron.protos.contract.BalanceContract; import org.tron.protos.contract.BalanceContract.FreezeBalanceContract; import org.tron.protos.contract.BalanceContract.TransferContract; import org.tron.protos.contract.BalanceContract.UnfreezeBalanceContract; @@ -1295,6 +1297,20 @@ public boolean freezeBalance( } } + public boolean freezeBalanceV2( + byte[] ownerAddress, + long frozen_balance, + int resourceCode) + throws CipherException, IOException, CancelException { + BalanceContract.FreezeBalanceV2Contract contract = + createFreezeBalanceContractV2( + ownerAddress, frozen_balance, resourceCode); + + TransactionExtention transactionExtention = rpcCli.createTransaction2(contract); + return processTransactionExtention(transactionExtention); + } + + public boolean buyStorage(byte[] ownerAddress, long quantity) throws CipherException, IOException, CancelException { BuyStorageContract contract = createBuyStorageContract(ownerAddress, quantity); @@ -1342,6 +1358,23 @@ private FreezeBalanceContract createFreezeBalanceContract( return builder.build(); } + private BalanceContract.FreezeBalanceV2Contract createFreezeBalanceContractV2( + byte[] address, + long frozen_balance, + int resourceCode) { + if (address == null) { + address = getAddress(); + } + + BalanceContract.FreezeBalanceV2Contract.Builder builder = BalanceContract.FreezeBalanceV2Contract.newBuilder(); + ByteString byteAddress = ByteString.copyFrom(address); + builder.setOwnerAddress(byteAddress) + .setFrozenBalance(frozen_balance) + .setResourceValue(resourceCode); + + return builder.build(); + } + private BuyStorageContract createBuyStorageContract(byte[] address, long quantity) { if (address == null) { address = getAddress(); @@ -1391,6 +1424,41 @@ public boolean unfreezeBalance(byte[] ownerAddress, int resourceCode, byte[] rec } } + public boolean unfreezeBalanceV2(byte[] ownerAddress, long unfreezeBalance + , int resourceCode) + throws CipherException, IOException, CancelException { + BalanceContract.UnfreezeBalanceV2Contract contract = + createUnfreezeBalanceContractV2(ownerAddress, unfreezeBalance, resourceCode); + TransactionExtention transactionExtention = rpcCli.createTransactionV2(contract); + return processTransactionExtention(transactionExtention); + } + + public boolean withdrawExpireUnfreeze(byte[] ownerAddress) + throws CipherException, IOException, CancelException { + BalanceContract.WithdrawExpireUnfreezeContract contract = + createWithdrawExpireUnfreezeContract(ownerAddress); + TransactionExtention transactionExtention = rpcCli.createTransactionV2(contract); + return processTransactionExtention(transactionExtention); + } + + public boolean delegateResource(byte[] ownerAddress, long balance + ,int resourceCode, byte[] receiverAddress, boolean lock) + throws CipherException, IOException, CancelException { + BalanceContract.DelegateResourceContract contract = createDelegateResourceContract( + ownerAddress, balance, resourceCode, receiverAddress, lock); + TransactionExtention transactionExtention = rpcCli.createTransactionV2(contract); + return processTransactionExtention(transactionExtention); + } + + public boolean unDelegateResource(byte[] ownerAddress, long balance + ,int resourceCode, byte[] receiverAddress) + throws CipherException, IOException, CancelException { + BalanceContract.UnDelegateResourceContract contract = + createUnDelegateResourceContract(ownerAddress, balance, resourceCode, receiverAddress); + TransactionExtention transactionExtention = rpcCli.createTransactionV2(contract); + return processTransactionExtention(transactionExtention); + } + private UnfreezeBalanceContract createUnfreezeBalanceContract( byte[] address, int resourceCode, byte[] receiverAddress) { if (address == null) { @@ -1411,6 +1479,72 @@ private UnfreezeBalanceContract createUnfreezeBalanceContract( return builder.build(); } + private BalanceContract.UnfreezeBalanceV2Contract createUnfreezeBalanceContractV2( + byte[] address, long unfreezeBalance, int resourceCode) { + if (address == null) { + address = getAddress(); + } + + BalanceContract.UnfreezeBalanceV2Contract.Builder builder = + BalanceContract.UnfreezeBalanceV2Contract.newBuilder(); + ByteString byteAddreess = ByteString.copyFrom(address); + builder.setOwnerAddress(byteAddreess).setResourceValue(resourceCode).setUnfreezeBalance(unfreezeBalance); + + return builder.build(); + } + + private BalanceContract.WithdrawExpireUnfreezeContract createWithdrawExpireUnfreezeContract(byte[] address) { + if (address == null) { + address = getAddress(); + } + + BalanceContract.WithdrawExpireUnfreezeContract.Builder builder = + BalanceContract.WithdrawExpireUnfreezeContract.newBuilder(); + ByteString byteAddreess = ByteString.copyFrom(address); + builder.setOwnerAddress(byteAddreess); + + return builder.build(); + } + + private BalanceContract.DelegateResourceContract createDelegateResourceContract( + byte[] address, long balance + ,int resourceCode, byte[] receiver, boolean lock) { + if (address == null) { + address = getAddress(); + } + + BalanceContract.DelegateResourceContract.Builder builder = + BalanceContract.DelegateResourceContract.newBuilder(); + ByteString byteAddreess = ByteString.copyFrom(address); + ByteString byteReceiverAddreess = ByteString.copyFrom(receiver); + builder.setOwnerAddress(byteAddreess) + .setResourceValue(resourceCode) + .setBalance(balance) + .setReceiverAddress(byteReceiverAddreess) + .setLock(lock); + + return builder.build(); + } + + private BalanceContract.UnDelegateResourceContract createUnDelegateResourceContract( + byte[] address, long balance + ,int resourceCode, byte[] receiver) { + if (address == null) { + address = getAddress(); + } + + BalanceContract.UnDelegateResourceContract.Builder builder = + BalanceContract.UnDelegateResourceContract.newBuilder(); + ByteString byteAddreess = ByteString.copyFrom(address); + ByteString byteReceiverAddreess = ByteString.copyFrom(receiver); + builder.setOwnerAddress(byteAddreess) + .setResourceValue(resourceCode) + .setBalance(balance) + .setReceiverAddress(byteReceiverAddreess); + + return builder.build(); + } + public boolean unfreezeAsset(byte[] ownerAddress) throws CipherException, IOException, CancelException { UnfreezeAssetContract contract = createUnfreezeAssetContract(ownerAddress); @@ -1508,6 +1642,45 @@ public static Optional getDelegatedResource( return rpcCli.getDelegatedResource(fromAddress, toAddress); } + public static Optional getDelegatedResourceAccountIndex( + String ownerAddress) { + return rpcCli.getDelegatedResourceAccountIndex(ownerAddress); + } + + public static Optional getDelegatedResourceV2( + String fromAddress, String toAddress) { + return rpcCli.getDelegatedResourceV2(fromAddress, toAddress); + } + + public static Optional getDelegatedResourceAccountIndexV2( + String ownerAddress) { + return rpcCli.getDelegatedResourceAccountIndexV2(ownerAddress); + } + + public Optional getCanWithdrawUnfreezeAmount( + byte[] ownerAddress, long timestamp) { + if (ownerAddress == null) { + ownerAddress = this.getAddress(); + } + return rpcCli.getCanWithdrawUnfreezeAmount(ownerAddress, timestamp); + } + + public Optional getCanDelegatedMaxSize( + byte[] ownerAddress, int type) { + if (ownerAddress == null) { + ownerAddress = this.getAddress(); + } + return rpcCli.getCanDelegatedMaxSize(ownerAddress, type); + } + + public Optional getAvailableUnfreezeCount( + byte[] ownerAddress) { + if (ownerAddress == null) { + ownerAddress = this.getAddress(); + } + return rpcCli.getAvailableUnfreezeCount(ownerAddress); + } + public static Optional listExchanges() { return rpcCli.listExchanges(); } diff --git a/src/main/protos/api/api.proto b/src/main/protos/api/api.proto index 6cfa57986..56c714c8d 100644 --- a/src/main/protos/api/api.proto +++ b/src/main/protos/api/api.proto @@ -226,6 +226,10 @@ service Wallet { //Use this function instead of FreezeBalance. rpc FreezeBalance2 (FreezeBalanceContract) returns (TransactionExtention) { } + //Use this function when FreezeBalanceV2. + rpc FreezeBalanceV2 (FreezeBalanceV2Contract) returns (TransactionExtention) { + } + //Please use UnfreezeBalance2 instead of this function. rpc UnfreezeBalance (UnfreezeBalanceContract) returns (Transaction) { option (google.api.http) = { @@ -239,6 +243,20 @@ service Wallet { //Use this function instead of UnfreezeBalance. rpc UnfreezeBalance2 (UnfreezeBalanceContract) returns (TransactionExtention) { } + //Use this function when UnfreezeBalanceV2. + rpc UnfreezeBalanceV2 (UnfreezeBalanceV2Contract) returns (TransactionExtention) { + } + + + rpc WithdrawExpireUnfreeze (WithdrawExpireUnfreezeContract) returns (TransactionExtention) { + } + + rpc DelegateResource (DelegateResourceContract) returns (TransactionExtention) { + } + + rpc UnDelegateResource (UnDelegateResourceContract) returns (TransactionExtention) { + } + //Please use UnfreezeAsset2 instead of this function. rpc UnfreezeAsset (UnfreezeAssetContract) returns (Transaction) { option (google.api.http) = { @@ -459,6 +477,26 @@ service Wallet { rpc GetDelegatedResource (DelegatedResourceMessage) returns (DelegatedResourceList) { }; + rpc GetDelegatedResourceV2 (DelegatedResourceMessage) returns (DelegatedResourceList) { + }; + + rpc GetDelegatedResourceAccountIndex (BytesMessage) returns (DelegatedResourceAccountIndex) { + }; + + rpc GetDelegatedResourceAccountIndexV2 (BytesMessage) returns (DelegatedResourceAccountIndex) { + }; + + rpc GetCanDelegatedMaxSize (CanDelegatedMaxSizeRequestMessage) returns (CanDelegatedMaxSizeResponseMessage) { + }; + + rpc GetAvailableUnfreezeCount (GetAvailableUnfreezeCountRequestMessage) + returns (GetAvailableUnfreezeCountResponseMessage) { + }; + + rpc GetCanWithdrawUnfreezeAmount (CanWithdrawUnfreezeAmountRequestMessage) + returns (CanWithdrawUnfreezeAmountResponseMessage) { + } + rpc ListProposals (EmptyMessage) returns (ProposalList) { option (google.api.http) = { post: "/wallet/listproposals" @@ -871,9 +909,26 @@ service WalletSolidity { rpc GetDelegatedResource (DelegatedResourceMessage) returns (DelegatedResourceList) { }; + rpc GetDelegatedResourceV2 (DelegatedResourceMessage) returns (DelegatedResourceList) { + }; + rpc GetDelegatedResourceAccountIndex (BytesMessage) returns (DelegatedResourceAccountIndex) { }; + rpc GetDelegatedResourceAccountIndexV2 (BytesMessage) returns (DelegatedResourceAccountIndex) { + }; + + rpc GetCanDelegatedMaxSize (CanDelegatedMaxSizeRequestMessage) returns (CanDelegatedMaxSizeResponseMessage) { + }; + + rpc GetAvailableUnfreezeCount (GetAvailableUnfreezeCountRequestMessage) + returns (GetAvailableUnfreezeCountResponseMessage) { + }; + + rpc GetCanWithdrawUnfreezeAmount (CanWithdrawUnfreezeAmountRequestMessage) + returns (CanWithdrawUnfreezeAmountResponseMessage) { + } + rpc GetExchangeById (BytesMessage) returns (Exchange) { }; @@ -1070,6 +1125,29 @@ message DelegatedResourceList { repeated DelegatedResource delegatedResource = 1; } +message GetAvailableUnfreezeCountRequestMessage { + bytes owner_address = 1; +} +message GetAvailableUnfreezeCountResponseMessage { + int64 count = 1; +} + +message CanDelegatedMaxSizeRequestMessage { + int32 type = 1; + bytes owner_address = 2; +} +message CanDelegatedMaxSizeResponseMessage { + int64 max_size = 1; +} + +message CanWithdrawUnfreezeAmountRequestMessage { + bytes owner_address = 1; + int64 timestamp = 2; +} +message CanWithdrawUnfreezeAmountResponseMessage { + int64 amount = 1; +} + // Gossip node list message NodeList { repeated Node nodes = 1; diff --git a/src/main/protos/core/Tron.proto b/src/main/protos/core/Tron.proto index fcf0e8758..c9c230864 100644 --- a/src/main/protos/core/Tron.proto +++ b/src/main/protos/core/Tron.proto @@ -2,6 +2,7 @@ syntax = "proto3"; import "google/protobuf/any.proto"; import "core/Discover.proto"; +import "core/contract/common.proto"; package protocol; @@ -128,6 +129,8 @@ message Account { // the identity of this account, case insensitive bytes account_id = 23; + int64 net_window_size = 24; + message AccountResource { // energy resource, get from frozen int64 energy_usage = 1; @@ -145,12 +148,31 @@ message Account { int64 storage_usage = 7; int64 latest_exchange_storage_time = 8; + int64 energy_window_size = 9; + + int64 delegated_frozenV2_balance_for_energy = 10; + int64 acquired_delegated_frozenV2_balance_for_energy = 11; } AccountResource account_resource = 26; bytes codeHash = 30; Permission owner_permission = 31; Permission witness_permission = 32; repeated Permission active_permission = 33; + + message FreezeV2 { + ResourceCode type = 1; + int64 amount = 2; + } + message UnFreezeV2 { + ResourceCode type = 1; + int64 unfreeze_amount = 3; + int64 unfreeze_expire_time = 4; + } + repeated FreezeV2 frozenV2 = 34; + repeated UnFreezeV2 unfrozenV2 = 35; + + int64 delegated_frozenV2_balance_for_bandwidth = 36; + int64 acquired_delegated_frozenV2_balance_for_bandwidth = 37; } @@ -284,6 +306,11 @@ message Transaction { ShieldedTransferContract = 51; MarketSellAssetContract = 52; MarketCancelOrderContract = 53; + FreezeBalanceV2Contract = 54; + UnfreezeBalanceV2Contract = 55; + WithdrawExpireUnfreezeContract = 56; + DelegateResourceContract = 57; + UnDelegateResourceContract = 58; } ContractType type = 1; google.protobuf.Any parameter = 2; @@ -326,6 +353,8 @@ message Transaction { int64 exchange_withdraw_another_amount = 20; int64 exchange_id = 21; int64 shielded_transaction_fee = 22; + + int64 withdraw_expire_amount = 27; } message raw { @@ -384,6 +413,8 @@ message TransactionInfo { bytes orderId = 25; repeated MarketOrderDetail orderDetails = 26; int64 packingFee = 27; + + int64 withdraw_expire_amount = 28; } message TransactionRet { @@ -547,6 +578,7 @@ message DelegatedResourceAccountIndex { bytes account = 1; repeated bytes fromAccounts = 2; repeated bytes toAccounts = 3; + int64 timestamp = 4; } message NodeInfo { diff --git a/src/main/protos/core/contract/balance_contract.proto b/src/main/protos/core/contract/balance_contract.proto index 82a93d6a3..54dcc4c40 100644 --- a/src/main/protos/core/contract/balance_contract.proto +++ b/src/main/protos/core/contract/balance_contract.proto @@ -81,3 +81,34 @@ message AccountBalanceResponse { int64 balance = 1; BlockBalanceTrace.BlockIdentifier block_identifier = 2; } + +message FreezeBalanceV2Contract { + bytes owner_address = 1; + int64 frozen_balance = 2; + ResourceCode resource = 3; +} + +message UnfreezeBalanceV2Contract { + bytes owner_address = 1; + int64 unfreeze_balance = 2; + ResourceCode resource = 3; +} + +message WithdrawExpireUnfreezeContract { + bytes owner_address = 1; +} + +message DelegateResourceContract { + bytes owner_address = 1; + ResourceCode resource = 2; + int64 balance = 3; + bytes receiver_address = 4; + bool lock = 5; +} + +message UnDelegateResourceContract { + bytes owner_address = 1; + ResourceCode resource = 2; + int64 balance = 3; + bytes receiver_address = 4; +} \ No newline at end of file From 214e5d478bfe6db7f3d2c476eff36d4d4a78c549 Mon Sep 17 00:00:00 2001 From: chaozhu Date: Thu, 15 Dec 2022 14:01:54 +0800 Subject: [PATCH 2/9] update README.md file --- README.md | 350 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 349 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e3dff8e05..c93b8a081 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,10 @@ For more information on a specific command, just type the command on terminal wh | [ShowShieldedTRC20AddressInfo](#How-to-transfer-shielded-TRC20-token) | [TransferAsset](#How-to-issue-TRC10-tokens) | [TriggerContract](#How-to-use-smart-contracts) | | [UnfreezeAsset](#How-to-issue-TRC10-tokens) | [UnfreezeBalance](#How-to-delegate-resource) |[UpdateAsset](#How-to-issue-TRC10-tokens) | | [UpdateBrokerage](#Brokerage) | [UpdateEnergyLimit](#How-to-use-smart-contracts) |[UpdateSetting](#How-to-use-smart-contracts) | -| [UpdateAccountPermission](#How-to-use-the-multi-signature-feature-of-wallet-cli) | [VoteWitness](#How-to-vote) | +| [UpdateAccountPermission](#How-to-use-the-multi-signature-feature-of-wallet-cli) | [VoteWitness](#How-to-vote) | [FreezeBalanceV2](#How-to-freezev2) | +| [UnfreezeBalanceV2](#How-to-freezev2) | [DelegateResource](#How-to-freezev2) | [UnDelegateResource](#How-to-freezev2) | +| [WithdrawExpireUnfreeze](#How-to-freezev2) | [GetDelegatedResourceV2](#How-to-freezev2) | [GetDelegatedResourceAccountIndexV2](#How-to-freezev2) | +| [GetCanDelegatedMaxSize](#How-to-freezev2) | [GetAvailableUnfreezeCount](#How-to-freezev2) | [GetCanWithdrawUnfreezeAmount](#How-to-freezev2) | Type any one of the listed commands, to display how-to tips. @@ -1087,6 +1090,351 @@ getDelegatedResource fromAddress toAddress getDelegatedResourceAccountIndex address > get the information that address is delegated to other account resources + +## How to freezev2 + +### freezev2/unfreezev2 resource + + > freezeBalanceV2 [OwnerAddress] frozen_balance [ResourceCode:0 BANDWIDTH,1 ENERGY,2 TRON_POWER] + +OwnerAddress +> The address of the account that initiated the transaction, optional, default is the address of the login account. + +frozen_balance +> The amount of frozen, the unit is the smallest unit (Sun), the minimum is 1000000sun. + +ResourceCode +> 0 BANDWIDTH;1 ENERGY + +Example: +```console +wallet> FreezeBalanceV2 TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 1000000000000000 0 +txid is 82244829971b4235d98a9f09ba67ddb09690ac2f879ad93e09ba3ec1ab29177d +wallet> GetTransactionById 82244829971b4235d98a9f09ba67ddb09690ac2f879ad93e09ba3ec1ab29177d +{ + "ret":[ + { + "contractRet":"SUCCESS" + } + ], + "signature":[ + "4faa3772fa3d3e4792e8126cafed2dc2c5c069cd09c29532f0119bc982bf356004772e16fad86e401f5818c35b96d214d693efab06997ca2f07044d4494f12fd01" + ], + "txID":"82244829971b4235d98a9f09ba67ddb09690ac2f879ad93e09ba3ec1ab29177d", + "raw_data":{ + "contract":[ + { + "parameter":{ + "value":{ + "frozen_balance":1000000000000000, + "owner_address":"4159e3741a68ec3e1ebba80ad809d5ccd31674236e" + }, + "type_url":"type.googleapis.com/protocol.FreezeBalanceV2Contract" + }, + "type":"FreezeBalanceV2Contract" + } + ], + "ref_block_bytes":"0000", + "ref_block_hash":"19b59068c6058ff4", + "expiration":1671109891800, + "timestamp":1671088291796 + }, + "raw_data_hex":"0a020000220819b59068c6058ff440d8ada5afd1305a5c083612580a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e747261637412200a154159e3741a68ec3e1ebba80ad809d5ccd31674236e1080809aa6eaafe30170d4fffea4d130" +} +``` + + > unfreezeBalanceV2 [OwnerAddress] unfreezeBalance ResourceCode(0 BANDWIDTH,1 ENERGY,2 TRON_POWER) + +OwnerAddress +> The address of the account that initiated the transaction, optional, default is the address of the login account. + +unfreezeBalance +> The amount of unfreeze, the unit is the smallest unit (Sun) + +ResourceCode +> 0 BANDWIDTH;1 ENERGY + +Example: +```console +wallet> UnFreezeBalanceV2 TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 9000000 0 +txid is dcfea1d92fc928d24c88f7f71a03ae8105d0b5b112d6d48be93d3b9c73bea634 +wallet> GetTransactionById dcfea1d92fc928d24c88f7f71a03ae8105d0b5b112d6d48be93d3b9c73bea634 +{ + "ret":[ + { + "contractRet":"SUCCESS" + } + ], + "signature":[ + "f73a278f742c11e8e5ede693ca09b0447a804fcb28ea2bfdfd8545bb05da7be44bd08cfaa92bd4d159178f763fcf753f28d5296bd0c3d4557532cce3b256b9da00" + ], + "txID":"dcfea1d92fc928d24c88f7f71a03ae8105d0b5b112d6d48be93d3b9c73bea634", + "raw_data":{ + "contract":[ + { + "parameter":{ + "value":{ + "owner_address":"4159e3741a68ec3e1ebba80ad809d5ccd31674236e", + "unfreeze_balance":9000000 + }, + "type_url":"type.googleapis.com/protocol.UnfreezeBalanceV2Contract" + }, + "type":"UnfreezeBalanceV2Contract" + } + ], + "ref_block_bytes":"0000", + "ref_block_hash":"19b59068c6058ff4", + "expiration":1671119916913, + "timestamp":1671098316907 + }, + "raw_data_hex":"0a020000220819b59068c6058ff440f19e89b4d1305a5a083712560a36747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e556e667265657a6542616c616e63655632436f6e7472616374121c0a154159e3741a68ec3e1ebba80ad809d5ccd31674236e10c0a8a50470ebf0e2a9d130" +} +``` + +### delegate/undelegate resource + + > delegateResource [OwnerAddress] balance ResourceCode(0 BANDWIDTH,1 ENERGY), ReceiverAddress [lock] + +OwnerAddress +> The address of the account that initiated the transaction, optional, default is the address of the login account. + +balance +> The amount of delegate, the unit is the smallest unit (Sun), the minimum is 1000000sun. + +ResourceCode +> 0 BANDWIDTH;1 ENERGY + +ReceiverAddress +> The address of the account + +lock +> default is false, set true if need lock delegate for 3 days + +Example: +```console +wallet> DelegateResource TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 10000000 0 TQ4gjjpAjLNnE67UFbmK5wVt5fzLfyEVs3 true +txid is 363ac0b82b6ad3e0d3cad90f7d72b3eceafe36585432a3e013389db36152b6ed +wallet> GetTransactionById 363ac0b82b6ad3e0d3cad90f7d72b3eceafe36585432a3e013389db36152b6ed +{ + "ret":[ + { + "contractRet":"SUCCESS" + } + ], + "signature":[ + "1f57fd78456136faadc5091b47f5fd27a8e1181621e49129df6a4062499429fb48ee72e5f9a9ff5bfb7f2575f01f4076f7d4b89ca382d36af46a6fa4bc749f4301" + ], + "txID":"363ac0b82b6ad3e0d3cad90f7d72b3eceafe36585432a3e013389db36152b6ed", + "raw_data":{ + "contract":[ + { + "parameter":{ + "value":{ + "balance":10000000, + "receiver_address":"419a9afe56e155ef0ff3f680d00ecf19deff60bdca", + "lock":true, + "owner_address":"4159e3741a68ec3e1ebba80ad809d5ccd31674236e" + }, + "type_url":"type.googleapis.com/protocol.DelegateResourceContract" + }, + "type":"DelegateResourceContract" + } + ], + "ref_block_bytes":"0000", + "ref_block_hash":"19b59068c6058ff4", + "expiration":1671120059226, + "timestamp":1671098459216 + }, + "raw_data_hex":"0a020000220819b59068c6058ff440daf691b4d1305a720839126e0a35747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e44656c65676174655265736f75726365436f6e747261637412350a154159e3741a68ec3e1ebba80ad809d5ccd31674236e1880ade2042215419a9afe56e155ef0ff3f680d00ecf19deff60bdca280170d0c8eba9d130" +} + +``` + + > unDelegateResource [OwnerAddress] balance ResourceCode(0 BANDWIDTH,1 ENERGY), ReceiverAddress + +OwnerAddress +> The address of the account that initiated the transaction, optional, default is the address of the login account. + +balance +> The amount of unDelegate, the unit is the smallest unit (Sun) + +ResourceCode +> 0 BANDWIDTH;1 ENERGY + +ReceiverAddress +> The address of the account + +Example: +```console +wallet> UnDelegateResource TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 1000000 0 TQ4gjjpAjLNnE67UFbmK5wVt5fzLfyEVs3 +txid is feb334794cf361fd351728026ccf7319e6ae90eba622b9eb53c626cdcae4965c +wallet> GetTransactionById feb334794cf361fd351728026ccf7319e6ae90eba622b9eb53c626cdcae4965c +{ + "ret":[ + { + "contractRet":"SUCCESS" + } + ], + "signature":[ + "85a41a4e44780ffbe0841a44fd71cf621f129d98e84984cfca68e03364f781aa7f9d44177af0b40d82da052feec9f47a399ed6e51be66c5db07cb13477dcde8c01" + ], + "txID":"feb334794cf361fd351728026ccf7319e6ae90eba622b9eb53c626cdcae4965c", + "raw_data":{ + "contract":[ + { + "parameter":{ + "value":{ + "balance":1000000, + "receiver_address":"419a9afe56e155ef0ff3f680d00ecf19deff60bdca", + "owner_address":"4159e3741a68ec3e1ebba80ad809d5ccd31674236e" + }, + "type_url":"type.googleapis.com/protocol.UnDelegateResourceContract" + }, + "type":"UnDelegateResourceContract" + } + ], + "ref_block_bytes":"0000", + "ref_block_hash":"19b59068c6058ff4", + "expiration":1671120342283, + "timestamp":1671098742280 + }, + "raw_data_hex":"0a020000220819b59068c6058ff4408b9aa3b4d1305a71083a126d0a37747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e556e44656c65676174655265736f75726365436f6e747261637412320a154159e3741a68ec3e1ebba80ad809d5ccd31674236e18c0843d2215419a9afe56e155ef0ff3f680d00ecf19deff60bdca7088ecfca9d130" +} +``` + + > withdrawExpireUnfreeze [OwnerAddress] + +OwnerAddress +> The address of the account that initiated the transaction, optional, default is the address of the login account. + +Example: +```console +wallet> withdrawexpireunfreeze TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh +txid is e5763ab8dfb1e7ed076770d55cf3c1ddaf36d75e23ec8330f99df7e98f54a147 +wallet> GetTransactionById e5763ab8dfb1e7ed076770d55cf3c1ddaf36d75e23ec8330f99df7e98f54a147 +{ + "ret":[ + { + "contractRet":"SUCCESS" + } + ], + "signature":[ + "f8f02b5aa634b8666862a6d2ed68fcfd90afc616d14062952b0b09f0404d9bca6c4d3dc6dab082784950ff1ded235a07dab0d738c8a202be9451d5ca92b8eece01" + ], + "txID":"e5763ab8dfb1e7ed076770d55cf3c1ddaf36d75e23ec8330f99df7e98f54a147", + "raw_data":{ + "contract":[ + { + "parameter":{ + "value":{ + "owner_address":"4159e3741a68ec3e1ebba80ad809d5ccd31674236e" + }, + "type_url":"type.googleapis.com/protocol.WithdrawExpireUnfreezeContract" + }, + "type":"WithdrawExpireUnfreezeContract" + } + ], + "ref_block_bytes":"0000", + "ref_block_hash":"19b59068c6058ff4", + "expiration":1671122055318, + "timestamp":1671100455315 + }, + "raw_data_hex":"0a020000220819b59068c6058ff44096e18bb5d1305a5a083812560a3b747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5769746864726177457870697265556e667265657a65436f6e747261637412170a154159e3741a68ec3e1ebba80ad809d5ccd31674236e7093b3e5aad130" +} +``` + +### get resource delegation information use v2 API + + > getDelegatedResourceV2 fromAddress toAddress +> get the information from the fromAddress to the toAddress resource delegate use v2 API + +fromAddress +> The address of the account that start the delegate + +toAddress +> The address of the account that receive the delegate + +Example: +```console +wallet> getDelegatedResourceV2 TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh TQ4gjjpAjLNnE67UFbmK5wVt5fzLfyEVs3 +{ + "delegatedResource": [ + { + "from": "TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh", + "to": "TQ4gjjpAjLNnE67UFbmK5wVt5fzLfyEVs3", + "frozen_balance_for_bandwidth": 10000000 + } + ] +} +``` + + > getDelegatedResourceAccountIndexV2 address +> get the information that address is delegated to other account resources use v2 API + +address +> The address of the account that start the delegate or receive the delegate + +Example: +```console +wallet> getDelegatedResourceAccountIndexV2 TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh +{ + "account": "TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh", + "toAccounts": [ + "TQ4gjjpAjLNnE67UFbmK5wVt5fzLfyEVs3" + ] +} +``` + + > getcandelegatedmaxsize [ownerAddress] type +> get the max size that the ownerAddress can delegate use delegateResource + +ownerAddress +> The address of the account that start the delegate, optional, default is the address of the login account. + +type +> 0 bandwidth, 1 energy + +Example: +```console +wallet> getCanDelegatedMaxSize 0 +{ + "max_size": 999999978708334 +} +``` + + > getavailableunfreezecount [ownerAddress] +> get the available unfreeze count that the ownerAddress can call unfreezeBalanceV2 + +ownerAddress +> The address of the account that initiated the transaction, optional, default is the address of the login account. + +Example: +```console +wallet> getAvailableUnfreezeCount +{ + "count": 31 +} +``` + + > getcanwithdrawunfreezeamount [ownerAddress] timestamp +> get the withdraw unfreeze amount that the ownerAddress can get by withdrawexpireunfreeze + +ownerAddress +> The address of the account that initiated the transaction, optional, default is the address of the login account. + +timestamp +> get can withdraw unfreeze amount until timestamp, + + +Example: +```console +wallet> getCanWithdrawUnfreezeAmount 1671100335000 +{ + "amount": 9000000 +} +``` + + ## Wallet related commands **RegisterWallet** From 31bed1fd010195e715786a1c555f710b72aa1fa9 Mon Sep 17 00:00:00 2001 From: chaozhu Date: Mon, 26 Dec 2022 14:24:49 +0800 Subject: [PATCH 3/9] add some param check --- .../common/utils/HttpSelfFormatFieldName.java | 16 ++++++++ src/main/java/org/tron/walletcli/Client.java | 39 ++++++++++++------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/tron/common/utils/HttpSelfFormatFieldName.java b/src/main/java/org/tron/common/utils/HttpSelfFormatFieldName.java index e1f5f3463..83ca4f30a 100644 --- a/src/main/java/org/tron/common/utils/HttpSelfFormatFieldName.java +++ b/src/main/java/org/tron/common/utils/HttpSelfFormatFieldName.java @@ -115,6 +115,22 @@ public class HttpSelfFormatFieldName { AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_from_address", 1); AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_to_address", 1); + //FreezeBalanceV2Contract + AddressFieldNameMap.put("protocol.FreezeBalanceV2Contract.owner_address", 1); + //UnfreezeBalanceV2Contract + AddressFieldNameMap.put("protocol.UnfreezeBalanceV2Contract.owner_address", 1); + //WithdrawExpireUnfreezeContract + AddressFieldNameMap.put("protocol.WithdrawExpireUnfreezeContract.owner_address", 1); + //DelegateResourceContract + AddressFieldNameMap.put("protocol.DelegateResourceContract.owner_address", 1); + AddressFieldNameMap.put("protocol.DelegateResourceContract.receiver_address", 1); + //UnDelegateResourceContract + AddressFieldNameMap.put("protocol.UnDelegateResourceContract.owner_address", 1); + AddressFieldNameMap.put("protocol.UnDelegateResourceContract.receiver_address", 1); + AddressFieldNameMap.put("protocol.CanDelegatedMaxSizeRequestMessage.owner_address", 1); + AddressFieldNameMap.put("protocol.GetAvailableUnfreezeCountRequestMessage.owner_address", 1); + AddressFieldNameMap.put("protocol.CanWithdrawUnfreezeAmountRequestMessage.owner_address", 1); + //***** Tron.proto ***** //AccountId AddressFieldNameMap.put("protocol.AccountId.address", 1); diff --git a/src/main/java/org/tron/walletcli/Client.java b/src/main/java/org/tron/walletcli/Client.java index 5b2b3a3e3..a7971838c 100755 --- a/src/main/java/org/tron/walletcli/Client.java +++ b/src/main/java/org/tron/walletcli/Client.java @@ -1427,24 +1427,19 @@ private void delegateResource(String[] parameters) return; } } else if (parameters.length == 4 || parameters.length == 5) { - ownerAddress = getAddressBytes(parameters[index++]); + ownerAddress = getAddressBytes(parameters[index]); if (ownerAddress != null) { - balance = Long.parseLong(parameters[index++]); - resourceCode = Integer.parseInt(parameters[index++]); - receiverAddress = getAddressBytes(parameters[index++]); - if (receiverAddress == null) { - System.out.println( - "delegateResource receiverAddress is invalid"); - return; - } - if (parameters.length == 5) { - lock = Boolean.parseBoolean(parameters[index++]); - } - } if (ownerAddress == null) { + index ++; + } + balance = Long.parseLong(parameters[index++]); + resourceCode = Integer.parseInt(parameters[index++]); + receiverAddress = getAddressBytes(parameters[index++]); + if (receiverAddress == null) { System.out.println( - "delegateResource ownerAddress is invalid"); + "delegateResource receiverAddress is invalid"); return; } + lock = Boolean.parseBoolean(parameters[index++]); } @@ -1719,7 +1714,13 @@ private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherExce byte[] ownerAddress = getAddressBytes(parameters[index]); if (ownerAddress != null) { index++; + if (parameters.length != 2) { + System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: "); + System.out.println("getcanwithdrawunfreezeamount [ownerAddress] timestamp"); + return; + } } + timestamp = Long.parseLong(parameters[index++]); if (timestamp < 0) { System.out.println("Invalid param, timestamp >= 0"); @@ -1747,8 +1748,15 @@ private void getCanDelegatedMaxSize(String[] parameters) throws CipherException, byte[] ownerAddress = getAddressBytes(parameters[index]); if (ownerAddress != null) { index++; + if (parameters.length < 2) { + System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: "); + System.out.println("getcandelegatedmaxsize [ownerAddress] type"); + return ; + } } + type = Integer.parseInt(parameters[index++]); + if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) { System.out.println("getcandelegatedmaxsize param type must be: 0 or 1"); return; @@ -1773,6 +1781,9 @@ private void getAvailableUnfreezeCount(String[] parameters) throws CipherExcepti byte[] ownerAddress = null; if (parameters.length == 1) { ownerAddress = getAddressBytes(parameters[index]); + if (ownerAddress == null) { + return ; + } } Optional result = walletApiWrapper.getAvailableUnfreezeCount(ownerAddress); From 5b9eaf86a6b837557686b9b0eabd4e9af8a0ec90 Mon Sep 17 00:00:00 2001 From: chaozhu Date: Mon, 26 Dec 2022 17:43:27 +0800 Subject: [PATCH 4/9] query api not need check login --- src/main/java/org/tron/walletcli/Client.java | 19 ++++++++---- .../org/tron/walletcli/WalletApiWrapper.java | 31 ------------------- .../java/org/tron/walletserver/WalletApi.java | 15 ++------- 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/tron/walletcli/Client.java b/src/main/java/org/tron/walletcli/Client.java index a7971838c..3109173b3 100755 --- a/src/main/java/org/tron/walletcli/Client.java +++ b/src/main/java/org/tron/walletcli/Client.java @@ -90,6 +90,7 @@ public class Client { "CreateAccount", "CreateProposal", "CreateWitness", + "DelegateResource", "DeleteProposal", "DeployContract contractName ABI byteCode constructor params isHex fee_limit consume_user_resource_percent origin_energy_limit value token_value token_id ", "ExchangeCreate", @@ -198,6 +199,7 @@ public class Client { "TransferAsset", "TriggerConstantContract contractAddress method args isHex", "TriggerContract contractAddress method args isHex fee_limit value", + "UnDelegateResource", "UnfreezeAsset", "UnfreezeBalance", "UnfreezeBalanceV2", @@ -211,8 +213,6 @@ public class Client { "VoteWitness", "WithdrawBalance", "WithdrawExpireUnfreeze", - "DelegateResource", - "UnDelegateResource", }; // note: this is sorted by alpha @@ -231,6 +231,7 @@ public class Client { "CreateAccount", "CreateProposal", "CreateWitness", + "DelegateResource", "DeleteProposal", "DeployContract", "ExchangeCreate", @@ -238,6 +239,7 @@ public class Client { "ExchangeTransaction", "ExchangeWithdraw", "FreezeBalance", + "FreezeBalanceV2", "GenerateAddress", // "GenerateShieldedAddress", "GenerateShieldedTRC20Address", @@ -338,8 +340,10 @@ public class Client { "TransferAsset", "TriggerConstantContract", "TriggerContract", + "UnDelegateResource", "UnfreezeAsset", "UnfreezeBalance", + "UnfreezeBalanceV2", "UpdateAccount", "UpdateAccountPermission", "UpdateAsset", @@ -349,6 +353,7 @@ public class Client { "UpdateWitness", "VoteWitness", "WithdrawBalance", + "WithdrawExpireUnfreeze", }; private byte[] inputPrivateKey() throws IOException { @@ -1727,8 +1732,8 @@ private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherExce return; } - Optional result = walletApiWrapper. - getCanWithdrawUnfreezeAmount(ownerAddress, timestamp); + Optional result = WalletApi.getCanWithdrawUnfreezeAmount( + ownerAddress, timestamp); if (result.isPresent()) { CanWithdrawUnfreezeAmountResponseMessage canWithdrawUnfreezeAmountResponseMessage = result.get(); System.out.println(Utils.formatMessageString(canWithdrawUnfreezeAmountResponseMessage)); @@ -1762,7 +1767,7 @@ private void getCanDelegatedMaxSize(String[] parameters) throws CipherException, return; } - Optional result = walletApiWrapper.getCanDelegatedMaxSize(ownerAddress, type); + Optional result = WalletApi.getCanDelegatedMaxSize(ownerAddress, type); if (result.isPresent()) { CanDelegatedMaxSizeResponseMessage canDelegatedMaxSizeResponseMessage = result.get(); System.out.println(Utils.formatMessageString(canDelegatedMaxSizeResponseMessage)); @@ -1782,11 +1787,13 @@ private void getAvailableUnfreezeCount(String[] parameters) throws CipherExcepti if (parameters.length == 1) { ownerAddress = getAddressBytes(parameters[index]); if (ownerAddress == null) { + System.out.println("Using getavailableunfreezecount command needs 1 parameters like: "); + System.out.println("getavailableunfreezecount [owner_address] "); return ; } } - Optional result = walletApiWrapper.getAvailableUnfreezeCount(ownerAddress); + Optional result = WalletApi.getAvailableUnfreezeCount(ownerAddress); if (result.isPresent()) { GetAvailableUnfreezeCountResponseMessage getAvailableUnfreezeCountResponseMessage = result.get(); System.out.println(Utils.formatMessageString(getAvailableUnfreezeCountResponseMessage)); diff --git a/src/main/java/org/tron/walletcli/WalletApiWrapper.java b/src/main/java/org/tron/walletcli/WalletApiWrapper.java index d68f666d6..68cd2dd89 100644 --- a/src/main/java/org/tron/walletcli/WalletApiWrapper.java +++ b/src/main/java/org/tron/walletcli/WalletApiWrapper.java @@ -577,37 +577,6 @@ public boolean undelegateresource(byte[] ownerAddress, long balance return wallet.unDelegateResource(ownerAddress, balance, resourceCode, receiverAddress); } - - public Optional getCanWithdrawUnfreezeAmount( - byte[] ownerAddress, long timestamp) - throws CipherException, IOException, CancelException { - if (wallet == null || !wallet.isLoginState()) { - System.out.println("Warning: getCanWithdrawUnfreezeAmount failed, Please login first !!"); - return Optional.empty(); - } - - return wallet.getCanWithdrawUnfreezeAmount(ownerAddress, timestamp); - } - - public Optional getCanDelegatedMaxSize(byte[] ownerAddress, int type) - throws CipherException, IOException, CancelException { - if (wallet == null || !wallet.isLoginState()) { - System.out.println("Warning: getCanDelegatedMaxSize failed, Please login first !!"); - return Optional.empty(); - } - - return wallet.getCanDelegatedMaxSize(ownerAddress, type); - } - - public Optional getAvailableUnfreezeCount(byte[] ownerAddress) - throws CipherException, IOException, CancelException { - if (wallet == null || !wallet.isLoginState()) { - System.out.println("Warning: getAvailableUnfreezeCount failed, Please login first !!"); - return Optional.empty(); - } - - return wallet.getAvailableUnfreezeCount(ownerAddress); - } public boolean unfreezeAsset(byte[] ownerAddress) throws CipherException, IOException, CancelException { diff --git a/src/main/java/org/tron/walletserver/WalletApi.java b/src/main/java/org/tron/walletserver/WalletApi.java index a11bdcab5..344c92533 100644 --- a/src/main/java/org/tron/walletserver/WalletApi.java +++ b/src/main/java/org/tron/walletserver/WalletApi.java @@ -1657,27 +1657,18 @@ public static Optional getDelegatedResou return rpcCli.getDelegatedResourceAccountIndexV2(ownerAddress); } - public Optional getCanWithdrawUnfreezeAmount( + public static Optional getCanWithdrawUnfreezeAmount( byte[] ownerAddress, long timestamp) { - if (ownerAddress == null) { - ownerAddress = this.getAddress(); - } return rpcCli.getCanWithdrawUnfreezeAmount(ownerAddress, timestamp); } - public Optional getCanDelegatedMaxSize( + public static Optional getCanDelegatedMaxSize( byte[] ownerAddress, int type) { - if (ownerAddress == null) { - ownerAddress = this.getAddress(); - } return rpcCli.getCanDelegatedMaxSize(ownerAddress, type); } - public Optional getAvailableUnfreezeCount( + public static Optional getAvailableUnfreezeCount( byte[] ownerAddress) { - if (ownerAddress == null) { - ownerAddress = this.getAddress(); - } return rpcCli.getAvailableUnfreezeCount(ownerAddress); } From 8dd116f92fd222f1694d744cbca67e68d974c7be Mon Sep 17 00:00:00 2001 From: chaozhu Date: Wed, 28 Dec 2022 16:15:42 +0800 Subject: [PATCH 5/9] fix some parameter verification problems --- README.md | 12 +- src/main/java/org/tron/walletcli/Client.java | 140 ++++++++++++++----- 2 files changed, 112 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index c93b8a081..cbbfdebaf 100644 --- a/README.md +++ b/README.md @@ -1385,7 +1385,7 @@ wallet> getDelegatedResourceAccountIndexV2 TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh } ``` - > getcandelegatedmaxsize [ownerAddress] type + > getcandelegatedmaxsize ownerAddress type > get the max size that the ownerAddress can delegate use delegateResource ownerAddress @@ -1396,13 +1396,13 @@ type Example: ```console -wallet> getCanDelegatedMaxSize 0 +wallet> getCanDelegatedMaxSize TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 0 { "max_size": 999999978708334 } ``` - > getavailableunfreezecount [ownerAddress] + > getavailableunfreezecount ownerAddress > get the available unfreeze count that the ownerAddress can call unfreezeBalanceV2 ownerAddress @@ -1410,13 +1410,13 @@ ownerAddress Example: ```console -wallet> getAvailableUnfreezeCount +wallet> getAvailableUnfreezeCount TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh { "count": 31 } ``` - > getcanwithdrawunfreezeamount [ownerAddress] timestamp + > getcanwithdrawunfreezeamount ownerAddress timestamp > get the withdraw unfreeze amount that the ownerAddress can get by withdrawexpireunfreeze ownerAddress @@ -1428,7 +1428,7 @@ timestamp Example: ```console -wallet> getCanWithdrawUnfreezeAmount 1671100335000 +wallet> getCanWithdrawUnfreezeAmount TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 1671100335000 { "amount": 9000000 } diff --git a/src/main/java/org/tron/walletcli/Client.java b/src/main/java/org/tron/walletcli/Client.java index 3109173b3..c13b18341 100755 --- a/src/main/java/org/tron/walletcli/Client.java +++ b/src/main/java/org/tron/walletcli/Client.java @@ -1444,9 +1444,12 @@ private void delegateResource(String[] parameters) "delegateResource receiverAddress is invalid"); return; } - lock = Boolean.parseBoolean(parameters[index++]); - } + if (parameters.length == 5 || + (ownerAddress == null && parameters.length == 4)) { + lock = Boolean.parseBoolean(parameters[index++]); + } + } boolean result = walletApiWrapper.delegateresource( ownerAddress, balance, resourceCode, receiverAddress, lock); @@ -1708,28 +1711,54 @@ private void getDelegatedResourceAccountIndexV2(String[] parameters) { } } + private void outputGetCanWithdrawUnfreezeAmountTip() { + System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: "); + System.out.println("getcanwithdrawunfreezeamount ownerAddress timestamp"); + } + private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherException, IOException, CancelException { if (parameters == null || !(parameters.length == 1 || parameters.length == 2)) { - System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: "); - System.out.println("getcanwithdrawunfreezeamount [ownerAddress] timestamp"); + this.outputGetCanWithdrawUnfreezeAmountTip(); return; } int index = 0; long timestamp = 0; - byte[] ownerAddress = getAddressBytes(parameters[index]); - if (ownerAddress != null) { - index++; - if (parameters.length != 2) { - System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: "); - System.out.println("getcanwithdrawunfreezeamount [ownerAddress] timestamp"); + byte[] ownerAddress = null; + + if (parameters.length == 1) { + try { + timestamp = Long.parseLong(parameters[index]); + if (timestamp < 0) { + System.out.println("Invalid param, timestamp >= 0"); + return; + } + } catch (NumberFormatException nfe) { + this.outputGetCanWithdrawUnfreezeAmountTip(); return; } - } - timestamp = Long.parseLong(parameters[index++]); - if (timestamp < 0) { - System.out.println("Invalid param, timestamp >= 0"); - return; + ownerAddress = this.getLoginAddreess(); + if (ownerAddress == null) { + System.out.println("getcanwithdrawunfreezeamount ownerAddress is invalid"); + return ; + } + } else if (parameters.length == 2) { + ownerAddress = getAddressBytes(parameters[index++]); + if (ownerAddress == null) { + this.outputGetCanWithdrawUnfreezeAmountTip(); + return; + } + + try { + timestamp = Long.parseLong(parameters[index]); + if (timestamp < 0) { + System.out.println("Invalid param, timestamp >= 0"); + return; + } + } catch (NumberFormatException nfe) { + this.outputGetCanWithdrawUnfreezeAmountTip(); + return; + } } Optional result = WalletApi.getCanWithdrawUnfreezeAmount( @@ -1742,29 +1771,55 @@ private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherExce } } + + private void outputGetCanDelegatedMaxSizeTip() { + System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: "); + System.out.println("getcandelegatedmaxsize ownerAddress type"); + } + private void getCanDelegatedMaxSize(String[] parameters) throws CipherException, IOException, CancelException { if (parameters == null || !(parameters.length == 1 || parameters.length == 2)) { - System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: "); - System.out.println("getcandelegatedmaxsize [ownerAddress] type"); + this.outputGetCanDelegatedMaxSizeTip(); return; } int index = 0; int type = 0; - byte[] ownerAddress = getAddressBytes(parameters[index]); - if (ownerAddress != null) { - index++; - if (parameters.length < 2) { - System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: "); - System.out.println("getcandelegatedmaxsize [ownerAddress] type"); - return ; + byte[] ownerAddress = null; + + if (parameters.length == 1) { + try { + type = Integer.parseInt(parameters[index]); + if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) { + System.out.println("getcandelegatedmaxsize type must be: 0 or 1"); + return; + } + } catch (NumberFormatException nfe) { + this.outputGetCanDelegatedMaxSizeTip(); + return; } - } - type = Integer.parseInt(parameters[index++]); + ownerAddress = this.getLoginAddreess(); + if (ownerAddress == null) { + System.out.println("getcandelegatedmaxsize ownerAddress is invalid"); + return ; + } + } else if (parameters.length == 2) { + ownerAddress = getAddressBytes(parameters[index++]); + if (ownerAddress == null) { + this.outputGetCanDelegatedMaxSizeTip(); + return ; + } - if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) { - System.out.println("getcandelegatedmaxsize param type must be: 0 or 1"); - return; + try { + type = Integer.parseInt(parameters[index]); + if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) { + System.out.println("getcandelegatedmaxsize type must be: 0 or 1"); + return; + } + } catch (NumberFormatException nfe) { + this.outputGetCanDelegatedMaxSizeTip(); + return; + } } Optional result = WalletApi.getCanDelegatedMaxSize(ownerAddress, type); @@ -1776,10 +1831,14 @@ private void getCanDelegatedMaxSize(String[] parameters) throws CipherException, } } + private void outputGetAvailableUnfreezeCountTip() { + System.out.println("Using getavailableunfreezecount command needs 1 parameters like: "); + System.out.println("getavailableunfreezecount owner_address "); + } + private void getAvailableUnfreezeCount(String[] parameters) throws CipherException, IOException, CancelException { if (parameters == null || !(parameters.length == 0 || parameters.length == 1)) { - System.out.println("Using getavailableunfreezecount command needs 1 parameters like: "); - System.out.println("getavailableunfreezecount [owner_address] "); + this.outputGetAvailableUnfreezeCountTip(); return; } int index = 0; @@ -1787,10 +1846,15 @@ private void getAvailableUnfreezeCount(String[] parameters) throws CipherExcepti if (parameters.length == 1) { ownerAddress = getAddressBytes(parameters[index]); if (ownerAddress == null) { - System.out.println("Using getavailableunfreezecount command needs 1 parameters like: "); - System.out.println("getavailableunfreezecount [owner_address] "); - return ; + this.outputGetAvailableUnfreezeCountTip(); + return; } + } else { + ownerAddress = this.getLoginAddreess(); + if (ownerAddress == null) { + this.outputGetAvailableUnfreezeCountTip(); + return; + } } Optional result = WalletApi.getAvailableUnfreezeCount(ownerAddress); @@ -4818,6 +4882,14 @@ private void getChainParameters() { } } + private byte[] getLoginAddreess() { + if (walletApiWrapper.isLoginState()) { + String ownerAddressStr = walletApiWrapper.getAddress(); + return WalletApi.decodeFromBase58Check(ownerAddressStr); + } + return null; + } + private void getBlockByIdOrNum(String[] parameters) { String idOrNum = null; boolean detail = false; From 593c475d16eec10570dda0591995dae15ffa208c Mon Sep 17 00:00:00 2001 From: "daniel.cao" Date: Thu, 29 Dec 2022 12:36:36 +0800 Subject: [PATCH 6/9] feat(DynamicEnergy): add dynamic energy apis for wallet --- src/main/java/org/tron/walletcli/Client.java | 65 +++++++++++++++++++ .../org/tron/walletcli/WalletApiWrapper.java | 12 ++++ .../org/tron/walletserver/GrpcClient.java | 4 ++ .../java/org/tron/walletserver/WalletApi.java | 34 ++++++++++ src/main/protos/api/api.proto | 9 +++ src/main/protos/core/Tron.proto | 1 + .../protos/core/contract/smart_contract.proto | 7 ++ 7 files changed, 132 insertions(+) diff --git a/src/main/java/org/tron/walletcli/Client.java b/src/main/java/org/tron/walletcli/Client.java index c13b18341..27eae01b0 100755 --- a/src/main/java/org/tron/walletcli/Client.java +++ b/src/main/java/org/tron/walletcli/Client.java @@ -93,6 +93,7 @@ public class Client { "DelegateResource", "DeleteProposal", "DeployContract contractName ABI byteCode constructor params isHex fee_limit consume_user_resource_percent origin_energy_limit value token_value token_id ", + "EstimateEnergy", "ExchangeCreate", "ExchangeInject", "ExchangeTransaction", @@ -234,6 +235,7 @@ public class Client { "DelegateResource", "DeleteProposal", "DeployContract", + "EstimateEnergy", "ExchangeCreate", "ExchangeInject", "ExchangeTransaction", @@ -2734,6 +2736,65 @@ private void triggerConstantContract(String[] parameters) ownerAddress, contractAddress, callValue, input, 0, tokenValue, tokenId, true); } + private void estimateEnergy(String[] parameters) + throws IOException, CipherException, CancelException { + + if (parameters == null || (parameters.length != 5 && parameters.length != 8)) { + System.out.println("EstimateEnergy needs 5 or 8 parameters like: "); + System.out.println("EstimateEnergy ownerAddress(use # if you own)" + + " contractAddress method args isHex " + + "[value token_value token_id(e.g: TRXTOKEN, use # if don't provided)]"); + return; + } + + int idx = 0; + + String ownerAddressStr = parameters[idx++]; + byte[] ownerAddress = null; + if (!"#".equals(ownerAddressStr)) { + ownerAddress = WalletApi.decodeFromBase58Check(ownerAddressStr); + if (ownerAddress == null) { + System.out.println("Invalid Owner Address."); + return; + } + } + + String contractAddressStr = parameters[idx++]; + byte[] contractAddress = WalletApi.decodeFromBase58Check(contractAddressStr); + if (contractAddress == null) { + System.out.println("Invalid Contract Address."); + return; + } + + String methodStr = parameters[idx++]; + String argsStr = parameters[idx++]; + boolean isHex = Boolean.parseBoolean(parameters[idx++]); + long callValue = 0; + long tokenValue = 0; + String tokenId = ""; + if (parameters.length == 8) { + callValue = Long.parseLong(parameters[idx++]); + tokenValue = Long.parseLong(parameters[idx++]); + tokenId = parameters[idx]; + } + + if (argsStr.equalsIgnoreCase("#")) { + argsStr = ""; + } + + if (tokenId.equalsIgnoreCase("#")) { + tokenId = ""; + } + + byte[] input = new byte[0]; + if (!methodStr.equalsIgnoreCase("#")) { + input = Hex.decode(AbiUtil.parseMethod(methodStr, argsStr, isHex)); + } + + walletApiWrapper.estimateEnergy( + ownerAddress, contractAddress, callValue, input, tokenValue, tokenId); + } + private void getContract(String[] parameters) { if (parameters == null || parameters.length != 1) { @@ -4658,6 +4719,10 @@ private void run() { triggerConstantContract(parameters); break; } + case "estimateenergy": { + estimateEnergy(parameters); + break; + } case "getcontract": { getContract(parameters); break; diff --git a/src/main/java/org/tron/walletcli/WalletApiWrapper.java b/src/main/java/org/tron/walletcli/WalletApiWrapper.java index 68cd2dd89..eb587d64b 100644 --- a/src/main/java/org/tron/walletcli/WalletApiWrapper.java +++ b/src/main/java/org/tron/walletcli/WalletApiWrapper.java @@ -779,6 +779,18 @@ public boolean callContract(byte[] ownerAddress, byte[] contractAddress, long ca isConstant); } + public boolean estimateEnergy(byte[] ownerAddress, byte[] contractAddress, long callValue, + byte[] data, long tokenValue, String tokenId) + throws CipherException, IOException, CancelException { + if (wallet == null || !wallet.isLoginState()) { + System.out.println("Warning: estimateEnergy failed, Please login first !!"); + return false; + } + + return wallet + .estimateEnergy(ownerAddress, contractAddress, callValue, data, tokenValue, tokenId); + } + public boolean accountPermissionUpdate(byte[] ownerAddress, String permission) throws IOException, CipherException, CancelException { if (wallet == null || !wallet.isLoginState()) { diff --git a/src/main/java/org/tron/walletserver/GrpcClient.java b/src/main/java/org/tron/walletserver/GrpcClient.java index a83a9a7d0..eac321095 100644 --- a/src/main/java/org/tron/walletserver/GrpcClient.java +++ b/src/main/java/org/tron/walletserver/GrpcClient.java @@ -937,6 +937,10 @@ public TransactionExtention triggerConstantContract(TriggerSmartContract request return blockingStubFull.triggerConstantContract(request); } + public EstimateEnergyMessage estimateEnergy(TriggerSmartContract request) { + return blockingStubFull.estimateEnergy(request); + } + public SmartContract getContract(byte[] address) { ByteString byteString = ByteString.copyFrom(address); BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(byteString).build(); diff --git a/src/main/java/org/tron/walletserver/WalletApi.java b/src/main/java/org/tron/walletserver/WalletApi.java index 344c92533..a0a57e349 100644 --- a/src/main/java/org/tron/walletserver/WalletApi.java +++ b/src/main/java/org/tron/walletserver/WalletApi.java @@ -44,6 +44,7 @@ import org.tron.api.GrpcAPI.DiversifierMessage; import org.tron.api.GrpcAPI.EasyTransferResponse; import org.tron.api.GrpcAPI.EmptyMessage; +import org.tron.api.GrpcAPI.EstimateEnergyMessage; import org.tron.api.GrpcAPI.ExchangeList; import org.tron.api.GrpcAPI.ExpandedSpendingKeyMessage; import org.tron.api.GrpcAPI.IncomingViewingKeyDiversifierMessage; @@ -2376,6 +2377,39 @@ public boolean triggerContract( return processTransactionExtention(transactionExtention); } + public boolean estimateEnergy( + byte[] owner, + byte[] contractAddress, + long callValue, + byte[] data, + long tokenValue, + String tokenId) + throws IOException, CipherException, CancelException { + if (owner == null) { + owner = getAddress(); + } + + TriggerSmartContract triggerContract = triggerCallContract(owner, contractAddress, callValue, + data, tokenValue, tokenId); + + EstimateEnergyMessage estimateEnergyMessage = rpcCli.estimateEnergy(triggerContract); + + if (estimateEnergyMessage == null) { + System.out.println("RPC create call trx failed!"); + return false; + } + + if (!estimateEnergyMessage.getResult().getResult()) { + System.out.println("RPC estimate energy failed!"); + System.out.println("Code = " + estimateEnergyMessage.getResult().getCode()); + System.out + .println("Message = " + estimateEnergyMessage.getResult().getMessage().toStringUtf8()); + return false; + } + System.out.println("Estimate energy result = " + Utils.formatMessageString(estimateEnergyMessage)); + return true; + } + public static SmartContract getContract(byte[] address) { return rpcCli.getContract(address); } diff --git a/src/main/protos/api/api.proto b/src/main/protos/api/api.proto index 56c714c8d..5a40c75ab 100644 --- a/src/main/protos/api/api.proto +++ b/src/main/protos/api/api.proto @@ -460,6 +460,9 @@ service Wallet { rpc TriggerConstantContract (TriggerSmartContract) returns (TransactionExtention) { } + rpc EstimateEnergy (TriggerSmartContract) returns (EstimateEnergyMessage) { + } + rpc ClearContractABI (ClearABIContract) returns (TransactionExtention) { } @@ -1281,6 +1284,12 @@ message TransactionExtention { int64 energy_used = 5; repeated TransactionInfo.Log logs = 6; repeated InternalTransaction internal_transactions = 7; + int64 energy_penalty = 8; +} + +message EstimateEnergyMessage { + Return result = 1; + int64 energy_required = 2; } message BlockExtention { diff --git a/src/main/protos/core/Tron.proto b/src/main/protos/core/Tron.proto index c9c230864..e2a402c4d 100644 --- a/src/main/protos/core/Tron.proto +++ b/src/main/protos/core/Tron.proto @@ -259,6 +259,7 @@ message ResourceReceipt { int64 net_usage = 5; int64 net_fee = 6; Transaction.Result.contractResult result = 7; + int64 energy_penalty_total = 8; } message MarketOrderDetail { diff --git a/src/main/protos/core/contract/smart_contract.proto b/src/main/protos/core/contract/smart_contract.proto index 40fbb5b7d..ede03e88f 100644 --- a/src/main/protos/core/contract/smart_contract.proto +++ b/src/main/protos/core/contract/smart_contract.proto @@ -58,6 +58,12 @@ message SmartContract { int32 version = 11; } +message ContractState { + int64 energy_usage = 1; + int64 energy_factor = 2; + int64 update_cycle = 3; +} + message CreateSmartContract { bytes owner_address = 1; SmartContract new_contract = 2; @@ -94,4 +100,5 @@ message UpdateEnergyLimitContract { message SmartContractDataWrapper { SmartContract smart_contract = 1; bytes runtimecode = 2; + ContractState contract_state = 3; } From 2fbc9f972301a66867a38bcb1bdf3f50fd0a191d Mon Sep 17 00:00:00 2001 From: "daniel.cao" Date: Tue, 3 Jan 2023 14:37:59 +0800 Subject: [PATCH 7/9] feat(DynamicEnergy): optimize estimate energy cmd parameters parse --- src/main/java/org/tron/walletcli/Client.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/walletcli/Client.java b/src/main/java/org/tron/walletcli/Client.java index 27eae01b0..c0ca0ce10 100755 --- a/src/main/java/org/tron/walletcli/Client.java +++ b/src/main/java/org/tron/walletcli/Client.java @@ -4279,7 +4279,8 @@ public static String[] getCmd(String cmdLine) { || cmdLine.toLowerCase().startsWith("deployconstantcontract") || cmdLine.toLowerCase().startsWith("triggercontract") || cmdLine.toLowerCase().startsWith("triggerconstantcontract") - || cmdLine.toLowerCase().startsWith("updateaccountpermission")) { + || cmdLine.toLowerCase().startsWith("updateaccountpermission") + || cmdLine.toLowerCase().startsWith("estimateenergy")) { return cmdLine.split("\\s+", -1); } String[] strArray = cmdLine.split("\""); From 0c3abf929a149d306e24aa778e3367bb2df44375 Mon Sep 17 00:00:00 2001 From: liukai Date: Wed, 11 Jan 2023 11:37:48 +0800 Subject: [PATCH 8/9] feat(zksnark): update zksnark 1. update zksnark dependency --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9a5221a42..54016c42b 100644 --- a/build.gradle +++ b/build.gradle @@ -89,7 +89,7 @@ dependencies { compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2' compile group: 'org.jline', name: 'jline', version: '3.15.0' - compile 'com.github.tronprotocol:zksnark-java-sdk:master-SNAPSHOT' + compile 'io.github.tronprotocol:zksnark-java-sdk:1.0.0' } protobuf { From 4ce756d59cf877db92d1e790acc7a68b267c9444 Mon Sep 17 00:00:00 2001 From: forfreeday Date: Wed, 11 Jan 2023 12:27:40 +0800 Subject: [PATCH 9/9] feat(stake): add new protobuf 1. modify api.proto 2. modify smart_contract.proto 3. modify Tron.proto --- src/main/protos/api/api.proto | 177 +++++++++-- src/main/protos/core/Tron.proto | 284 ++++++++++++++---- .../protos/core/contract/smart_contract.proto | 139 +++++---- 3 files changed, 452 insertions(+), 148 deletions(-) diff --git a/src/main/protos/api/api.proto b/src/main/protos/api/api.proto index 6cfa57986..95871f5aa 100644 --- a/src/main/protos/api/api.proto +++ b/src/main/protos/api/api.proto @@ -11,9 +11,9 @@ import "core/contract/balance_contract.proto"; import "core/contract/proposal_contract.proto"; import "core/contract/storage_contract.proto"; import "core/contract/exchange_contract.proto"; +import "core/contract/market_contract.proto"; import "core/contract/smart_contract.proto"; import "core/contract/shield_contract.proto"; -import "core/contract/market_contract.proto"; option java_package = "org.tron.api"; //Specify the name of the package that generated the Java file option java_outer_classname = "GrpcAPI"; //Specify the class name of the generated Java file @@ -41,7 +41,6 @@ service Wallet { }; }; - rpc GetAccountBalance (AccountBalanceRequest) returns (AccountBalanceResponse) { option (google.api.http) = { post: "/wallet/getaccountbalance" @@ -62,7 +61,6 @@ service Wallet { }; }; - //Please use CreateTransaction2 instead of this function. rpc CreateTransaction (TransferContract) returns (Transaction) { option (google.api.http) = { @@ -226,6 +224,10 @@ service Wallet { //Use this function instead of FreezeBalance. rpc FreezeBalance2 (FreezeBalanceContract) returns (TransactionExtention) { } + //Use this function when FreezeBalanceV2. + rpc FreezeBalanceV2 (FreezeBalanceV2Contract) returns (TransactionExtention) { + } + //Please use UnfreezeBalance2 instead of this function. rpc UnfreezeBalance (UnfreezeBalanceContract) returns (Transaction) { option (google.api.http) = { @@ -239,6 +241,10 @@ service Wallet { //Use this function instead of UnfreezeBalance. rpc UnfreezeBalance2 (UnfreezeBalanceContract) returns (TransactionExtention) { } + //Use this function when UnfreezeBalanceV2. + rpc UnfreezeBalanceV2 (UnfreezeBalanceV2Contract) returns (TransactionExtention) { + } + //Please use UnfreezeAsset2 instead of this function. rpc UnfreezeAsset (UnfreezeAssetContract) returns (Transaction) { option (google.api.http) = { @@ -265,6 +271,16 @@ service Wallet { //Use this function instead of WithdrawBalance. rpc WithdrawBalance2 (WithdrawBalanceContract) returns (TransactionExtention) { } + + rpc WithdrawExpireUnfreeze (WithdrawExpireUnfreezeContract) returns (TransactionExtention) { + } + + rpc DelegateResource (DelegateResourceContract) returns (TransactionExtention) { + } + + rpc UnDelegateResource (UnDelegateResourceContract) returns (TransactionExtention) { + } + //Please use UpdateAsset2 instead of this function. rpc UpdateAsset (UpdateAssetContract) returns (Transaction) { option (google.api.http) = { @@ -309,6 +325,28 @@ service Wallet { rpc ExchangeTransaction (ExchangeTransactionContract) returns (TransactionExtention) { } + rpc MarketSellAsset (MarketSellAssetContract) returns (TransactionExtention) { + } + + rpc MarketCancelOrder (MarketCancelOrderContract) returns (TransactionExtention) { + } + + rpc GetMarketOrderById (BytesMessage) returns (MarketOrder) { + } + + rpc GetMarketOrderByAccount (BytesMessage) returns (MarketOrderList) { + } + + rpc GetMarketPriceByPair (MarketOrderPair) returns (MarketPriceList) { + } + + rpc GetMarketOrderListByPair (MarketOrderPair) returns (MarketOrderList) { + } + + rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) { + } + + rpc ListNodes (EmptyMessage) returns (NodeList) { option (google.api.http) = { post: "/wallet/listnodes" @@ -442,6 +480,9 @@ service Wallet { rpc TriggerConstantContract (TriggerSmartContract) returns (TransactionExtention) { } + rpc EstimateEnergy (TriggerSmartContract) returns (EstimateEnergyMessage) { + } + rpc ClearContractABI (ClearABIContract) returns (TransactionExtention) { } @@ -459,6 +500,26 @@ service Wallet { rpc GetDelegatedResource (DelegatedResourceMessage) returns (DelegatedResourceList) { }; + rpc GetDelegatedResourceV2 (DelegatedResourceMessage) returns (DelegatedResourceList) { + }; + + rpc GetDelegatedResourceAccountIndex (BytesMessage) returns (DelegatedResourceAccountIndex) { + }; + + rpc GetDelegatedResourceAccountIndexV2 (BytesMessage) returns (DelegatedResourceAccountIndex) { + }; + + rpc GetCanDelegatedMaxSize (CanDelegatedMaxSizeRequestMessage) returns (CanDelegatedMaxSizeResponseMessage) { + }; + + rpc GetAvailableUnfreezeCount (GetAvailableUnfreezeCountRequestMessage) + returns (GetAvailableUnfreezeCountResponseMessage) { + }; + + rpc GetCanWithdrawUnfreezeAmount (CanWithdrawUnfreezeAmountRequestMessage) + returns (CanWithdrawUnfreezeAmountResponseMessage) { + } + rpc ListProposals (EmptyMessage) returns (ProposalList) { option (google.api.http) = { post: "/wallet/listproposals" @@ -728,7 +789,6 @@ service Wallet { rpc CreateShieldNullifier (NfParameters) returns (BytesMessage) { }; - // end for shiededTransaction //for shielded contract rpc CreateShieldedContractParameters (PrivateShieldedTRC20Parameters) returns (ShieldedTRC20Parameters) { @@ -748,7 +808,7 @@ service Wallet { rpc GetTriggerInputForShieldedTRC20Contract (ShieldedTRC20TriggerContractParameters) returns (BytesMessage) { }; - // end for shieldedTransaction + // end for shiededTransaction rpc CreateCommonTransaction (Transaction) returns (TransactionExtention) { }; @@ -756,28 +816,18 @@ service Wallet { rpc GetTransactionInfoByBlockNum (NumberMessage) returns (TransactionInfoList) { } - // for market - rpc MarketSellAsset (MarketSellAssetContract) returns (TransactionExtention) { + rpc GetBurnTrx (EmptyMessage) returns (NumberMessage) { } - rpc MarketCancelOrder (MarketCancelOrderContract) returns (TransactionExtention) { + rpc GetTransactionFromPending (BytesMessage) returns (Transaction) { } - rpc GetMarketOrderByAccount (BytesMessage) returns (MarketOrderList) { + rpc GetTransactionListFromPending (EmptyMessage) returns (TransactionIdList) { } - rpc GetMarketOrderById (BytesMessage) returns (MarketOrder) { + rpc GetPendingSize (EmptyMessage) returns (NumberMessage) { } - rpc GetMarketPriceByPair (MarketOrderPair) returns (MarketPriceList) { - } - - rpc GetMarketOrderListByPair (MarketOrderPair) returns (MarketOrderList) { - } - - rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) { - } - // end for market rpc GetBlock (BlockReq) returns (BlockExtention) { } }; @@ -871,9 +921,26 @@ service WalletSolidity { rpc GetDelegatedResource (DelegatedResourceMessage) returns (DelegatedResourceList) { }; + rpc GetDelegatedResourceV2 (DelegatedResourceMessage) returns (DelegatedResourceList) { + }; + rpc GetDelegatedResourceAccountIndex (BytesMessage) returns (DelegatedResourceAccountIndex) { }; + rpc GetDelegatedResourceAccountIndexV2 (BytesMessage) returns (DelegatedResourceAccountIndex) { + }; + + rpc GetCanDelegatedMaxSize (CanDelegatedMaxSizeRequestMessage) returns (CanDelegatedMaxSizeResponseMessage) { + }; + + rpc GetAvailableUnfreezeCount (GetAvailableUnfreezeCountRequestMessage) + returns (GetAvailableUnfreezeCountResponseMessage) { + }; + + rpc GetCanWithdrawUnfreezeAmount (CanWithdrawUnfreezeAmountRequestMessage) + returns (CanWithdrawUnfreezeAmountResponseMessage) { + } + rpc GetExchangeById (BytesMessage) returns (Exchange) { }; @@ -945,15 +1012,18 @@ service WalletSolidity { rpc TriggerConstantContract (TriggerSmartContract) returns (TransactionExtention) { } - rpc GetTransactionInfoByBlockNum (NumberMessage) returns (TransactionInfoList) { + rpc EstimateEnergy (TriggerSmartContract) returns (EstimateEnergyMessage) { } - rpc GetMarketOrderByAccount (BytesMessage) returns (MarketOrderList) { + rpc GetTransactionInfoByBlockNum (NumberMessage) returns (TransactionInfoList) { } rpc GetMarketOrderById (BytesMessage) returns (MarketOrder) { } + rpc GetMarketOrderByAccount (BytesMessage) returns (MarketOrderList) { + } + rpc GetMarketPriceByPair (MarketOrderPair) returns (MarketPriceList) { } @@ -962,6 +1032,9 @@ service WalletSolidity { rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) { } + + rpc GetBurnTrx (EmptyMessage) returns (NumberMessage) { + } rpc GetBlock (BlockReq) returns (BlockExtention) { } }; @@ -1012,6 +1085,18 @@ service Database { } }; +service Monitor { + rpc GetStatsInfo (EmptyMessage) returns (MetricsInfo) { + option (google.api.http) = { + post: "/monitor/getstatsinfo" + body: "*" + additional_bindings { + get: "/monitor/getstatsinfo" + } + }; + } +} + message Return { enum response_code { SUCCESS = 0; @@ -1062,6 +1147,9 @@ message BlockList { message TransactionList { repeated Transaction transaction = 1; } +message TransactionIdList { + repeated string txId = 1; +} message DelegatedResourceMessage { bytes fromAddress = 1; bytes toAddress = 2; @@ -1070,6 +1158,31 @@ message DelegatedResourceList { repeated DelegatedResource delegatedResource = 1; } +message GetAvailableUnfreezeCountRequestMessage { + bytes owner_address = 1; +} +message GetAvailableUnfreezeCountResponseMessage { + int64 count = 1; +} + +//GetCanDelegatedMaxSize +message CanDelegatedMaxSizeRequestMessage { + int32 type = 1; + bytes owner_address = 2; +} +message CanDelegatedMaxSizeResponseMessage { + int64 max_size = 1; +} + +//GetCanWithdrawUnfreezeAmount +message CanWithdrawUnfreezeAmountRequestMessage { + bytes owner_address = 1; + int64 timestamp = 2; +} +message CanWithdrawUnfreezeAmountResponseMessage { + int64 amount = 1; +} + // Gossip node list message NodeList { repeated Node nodes = 1; @@ -1187,7 +1300,7 @@ message EasyTransferAssetByPrivateMessage { message EasyTransferResponse { Transaction transaction = 1; Return result = 2; - bytes txid = 3; //transaction id = sha256(transaction.raw_data) + bytes txid = 3; //transaction id = sha256(transaction.rowdata) } message AddressPrKeyPairMessage { @@ -1197,12 +1310,18 @@ message AddressPrKeyPairMessage { message TransactionExtention { Transaction transaction = 1; - bytes txid = 2; //transaction id = sha256(transaction.raw_data) + bytes txid = 2; //transaction id = sha256(transaction.rowdata) repeated bytes constant_result = 3; Return result = 4; int64 energy_used = 5; repeated TransactionInfo.Log logs = 6; repeated InternalTransaction internal_transactions = 7; + int64 energy_penalty = 8; +} + +message EstimateEnergyMessage { + Return result = 1; + int64 energy_required = 2; } message BlockExtention { @@ -1285,7 +1404,7 @@ message OvkDecryptParameters { message DecryptNotes { message NoteTx { Note note = 1; - bytes txid = 2; //transaction id = sha256(transaction.raw_data) + bytes txid = 2; //transaction id = sha256(transaction.rowdata) int32 index = 3; //the index of note in receive } repeated NoteTx noteTxs = 1; @@ -1294,7 +1413,7 @@ message DecryptNotes { message DecryptNotesMarked { message NoteTx { Note note = 1; - bytes txid = 2; //transaction id = sha256(transaction.raw_data) + bytes txid = 2; //transaction id = sha256(transaction.rowdata) int32 index = 3; //the index of note in receive bool is_spend = 4; } @@ -1329,7 +1448,7 @@ message PrivateParameters { repeated ReceiveNote shielded_receives = 7; bytes transparent_to_address = 8; int64 to_amount = 9; - int64 timeout = 10; // timeout in seconds, it works only when it bigger than 0 + int64 timeout = 10; // timeout in seconds, it works only when it bigger than 0 } message PrivateParametersWithoutAsk { @@ -1342,7 +1461,7 @@ message PrivateParametersWithoutAsk { repeated ReceiveNote shielded_receives = 7; bytes transparent_to_address = 8; int64 to_amount = 9; - int64 timeout = 10; // timeout in seconds, it works only when it bigger than 0 + int64 timeout = 10; // timeout in seconds, it works only when it bigger than 0 } message SpendAuthSigParameters { @@ -1388,7 +1507,7 @@ message PaymentAddressMessage { string payment_address = 3; } -message ShieldedAddressInfo{ +message ShieldedAddressInfo { bytes sk = 1; bytes ask = 2; bytes nsk = 3; @@ -1507,4 +1626,4 @@ message ShieldedTRC20TriggerContractParameters { repeated BytesMessage spend_authority_signature = 2; string amount = 3; bytes transparent_to_address = 4; -} \ No newline at end of file +} diff --git a/src/main/protos/core/Tron.proto b/src/main/protos/core/Tron.proto index fcf0e8758..e6aac408f 100644 --- a/src/main/protos/core/Tron.proto +++ b/src/main/protos/core/Tron.proto @@ -2,6 +2,7 @@ syntax = "proto3"; import "google/protobuf/any.proto"; import "core/Discover.proto"; +import "core/contract/common.proto"; package protocol; @@ -58,6 +59,67 @@ message Exchange { int64 second_token_balance = 9; } +// market +message MarketOrder { + bytes order_id = 1; + bytes owner_address = 2; + int64 create_time = 3; + bytes sell_token_id = 4; + int64 sell_token_quantity = 5; + bytes buy_token_id = 6; + int64 buy_token_quantity = 7; // min to receive + int64 sell_token_quantity_remain = 9; + // When state != ACTIVE and sell_token_quantity_return !=0, + //it means that some sell tokens are returned to the account due to insufficient remaining amount + int64 sell_token_quantity_return = 10; + + enum State { + ACTIVE = 0; + INACTIVE = 1; + CANCELED = 2; + } + State state = 11; + + bytes prev = 12; + bytes next = 13; +} + +message MarketOrderList { + repeated MarketOrder orders = 1; +} + +message MarketOrderPairList { + repeated MarketOrderPair orderPair = 1; +} + +message MarketOrderPair{ + bytes sell_token_id = 1; + bytes buy_token_id = 2; +} + +message MarketAccountOrder { + bytes owner_address = 1; + repeated bytes orders = 2; // order_id list + int64 count = 3; // active count + int64 total_count = 4; +} + +message MarketPrice { + int64 sell_token_quantity = 1; + int64 buy_token_quantity = 2; +} + +message MarketPriceList { + bytes sell_token_id = 1; + bytes buy_token_id = 2; + repeated MarketPrice prices = 3; +} + +message MarketOrderIdList { + bytes head = 1; + bytes tail = 2; +} + message ChainParameters { repeated ChainParameter chainParameter = 1; message ChainParameter { @@ -100,6 +162,8 @@ message Account { int64 old_tron_power = 46; Frozen tron_power = 47; + bool asset_optimized = 60; + // this account create time int64 create_time = 0x09; // this last operation time, including transfer, voting and so on. //FIXME fix grammar @@ -128,6 +192,8 @@ message Account { // the identity of this account, case insensitive bytes account_id = 23; + int64 net_window_size = 24; + message AccountResource { // energy resource, get from frozen int64 energy_usage = 1; @@ -145,14 +211,32 @@ message Account { int64 storage_usage = 7; int64 latest_exchange_storage_time = 8; + int64 energy_window_size = 9; + + int64 delegated_frozenV2_balance_for_energy = 10; + int64 acquired_delegated_frozenV2_balance_for_energy = 11; } AccountResource account_resource = 26; bytes codeHash = 30; Permission owner_permission = 31; Permission witness_permission = 32; repeated Permission active_permission = 33; -} + message FreezeV2 { + ResourceCode type = 1; + int64 amount = 2; + } + message UnFreezeV2 { + ResourceCode type = 1; + int64 unfreeze_amount = 3; + int64 unfreeze_expire_time = 4; + } + repeated FreezeV2 frozenV2 = 34; + repeated UnFreezeV2 unfrozenV2 = 35; + + int64 delegated_frozenV2_balance_for_bandwidth = 36; + int64 acquired_delegated_frozenV2_balance_for_bandwidth = 37; +} message Key { bytes address = 1; @@ -237,6 +321,7 @@ message ResourceReceipt { int64 net_usage = 5; int64 net_fee = 6; Transaction.Result.contractResult result = 7; + int64 energy_penalty_total = 8; } message MarketOrderDetail { @@ -284,6 +369,11 @@ message Transaction { ShieldedTransferContract = 51; MarketSellAssetContract = 52; MarketCancelOrderContract = 53; + FreezeBalanceV2Contract = 54; + UnfreezeBalanceV2Contract = 55; + WithdrawExpireUnfreezeContract = 56; + DelegateResourceContract = 57; + UnDelegateResourceContract = 58; } ContractType type = 1; google.protobuf.Any parameter = 2; @@ -313,6 +403,7 @@ message Transaction { JVM_STACK_OVER_FLOW = 12; UNKNOWN = 13; TRANSFER_FAILED = 14; + INVALID_CODE = 15; } int64 fee = 1; code ret = 2; @@ -326,6 +417,11 @@ message Transaction { int64 exchange_withdraw_another_amount = 20; int64 exchange_id = 21; int64 shielded_transaction_fee = 22; + + + bytes orderId = 25; + repeated MarketOrderDetail orderDetails = 26; + int64 withdraw_expire_amount = 27; } message raw { @@ -334,9 +430,9 @@ message Transaction { bytes ref_block_hash = 4; int64 expiration = 8; repeated authority auths = 9; - // transaction note + // data not used bytes data = 10; - //only support size = 1, repeated list here for extension + //only support size = 1, repeated list here for extension repeated Contract contract = 11; // scripts not used bytes scripts = 12; @@ -345,7 +441,7 @@ message Transaction { } raw raw_data = 1; - // only support size = 1, repeated list here for muti-sig extension + // only support size = 1, repeated list here for muti-sig extension repeated bytes signature = 2; repeated Result ret = 5; } @@ -384,6 +480,8 @@ message TransactionInfo { bytes orderId = 25; repeated MarketOrderDetail orderDetails = 26; int64 packingFee = 27; + + int64 withdraw_expire_amount = 28; } message TransactionRet { @@ -413,7 +511,6 @@ message BlockHeader { bytes witness_address = 9; int32 version = 10; bytes accountStateRoot = 11; - bytes receiptsRoot = 12; } raw raw_data = 1; bytes witness_signature = 2; @@ -484,7 +581,7 @@ enum ReasonCode { TOO_MANY_PEERS = 0x04; DUPLICATE_PEER = 0x05; INCOMPATIBLE_PROTOCOL = 0x06; - NULL_IDENTITY = 0x07; + RANDOM_ELIMINATION = 0x07; PEER_QUITING = 0x08; UNEXPECTED_IDENTITY = 0x09; LOCAL_IDENTITY = 0x0A; @@ -502,6 +599,7 @@ enum ReasonCode { TIME_OUT = 0x20; CONNECT_FAIL = 0x21; TOO_MANY_PEERS_WITH_SAME_IP = 0x22; + LIGHT_NODE_SYNC_FAIL = 0x23; UNKNOWN = 0xFF; } @@ -521,6 +619,10 @@ message HelloMessage { BlockId genesisBlockId = 4; BlockId solidBlockId = 5; BlockId headBlockId = 6; + bytes address = 7; + bytes signature = 8; + int32 nodeType = 9; + int64 lowestBlockNum = 10; } message InternalTransaction { @@ -547,6 +649,7 @@ message DelegatedResourceAccountIndex { bytes account = 1; repeated bytes fromAccounts = 2; repeated bytes toAccounts = 3; + int64 timestamp = 4; } message NodeInfo { @@ -622,7 +725,7 @@ message NodeInfo { double cpuRate = 6; string javaVersion = 7; string osName = 8; - int64 jvmTotalMemoery = 9; + int64 jvmTotalMemory = 9; int64 jvmFreeMemory = 10; double processCpuRate = 11; repeated MemoryDescInfo memoryDescInfoList = 12; @@ -648,63 +751,138 @@ message NodeInfo { } } -// market -message MarketOrder { - bytes order_id = 1; - bytes owner_address = 2; - int64 create_time = 3; - bytes sell_token_id = 4; - int64 sell_token_quantity = 5; - bytes buy_token_id = 6; - int64 buy_token_quantity = 7; // min to receive - int64 sell_token_quantity_remain = 9; - // When state != ACTIVE and sell_token_quantity_return !=0, - //it means that some sell tokens are returned to the account due to insufficient remaining amount - int64 sell_token_quantity_return = 10; +message MetricsInfo { + int64 interval = 1; + NodeInfo node = 2; + BlockChainInfo blockchain = 3; + NetInfo net = 4; - enum State { - ACTIVE = 0; - INACTIVE = 1; - CANCELED = 2; + message NodeInfo { + string ip = 1; + int32 nodeType = 2; + string version = 3; + int32 backupStatus = 4; } - State state = 11; - bytes prev = 12; - bytes next = 13; -} + message BlockChainInfo { + int64 headBlockNum = 1; + int64 headBlockTimestamp = 2; + string headBlockHash = 3; + int32 forkCount = 4; + int32 failForkCount = 5; + RateInfo blockProcessTime = 6; + RateInfo tps = 7; + int32 transactionCacheSize = 8; + RateInfo missedTransaction = 9; + repeated Witness witnesses = 10; + int64 failProcessBlockNum = 11; + string failProcessBlockReason = 12; + repeated DupWitness dupWitness = 13; + + message Witness { + string address = 1; + int32 version = 2; + } -message MarketOrderList { - repeated MarketOrder orders = 1; -} + message DupWitness { + string address = 1; + int64 blockNum = 2; + int32 count = 3; + } + } -message MarketOrderPairList { - repeated MarketOrderPair orderPair = 1; -} + message RateInfo { + int64 count = 1; + double meanRate = 2; + double oneMinuteRate = 3; + double fiveMinuteRate = 4; + double fifteenMinuteRate = 5; + } -message MarketOrderPair{ - bytes sell_token_id = 1; - bytes buy_token_id = 2; -} + message NetInfo { + int32 errorProtoCount = 1; + ApiInfo api = 2; + int32 connectionCount = 3; + int32 validConnectionCount = 4; + RateInfo tcpInTraffic = 5; + RateInfo tcpOutTraffic = 6; + int32 disconnectionCount = 7; + repeated DisconnectionDetailInfo disconnectionDetail = 8; + RateInfo udpInTraffic = 9; + RateInfo udpOutTraffic = 10; + LatencyInfo latency = 11; + + message ApiInfo { + RateInfo qps = 1; + RateInfo failQps = 2; + RateInfo outTraffic = 3; + repeated ApiDetailInfo detail = 4; + + message ApiDetailInfo { + string name = 1; + RateInfo qps = 2; + RateInfo failQps = 3; + RateInfo outTraffic = 4; + } + } -message MarketAccountOrder { - bytes owner_address = 1; - repeated bytes orders = 2; // order_id list - int64 count = 3; // active count - int64 total_count = 4; + message DisconnectionDetailInfo { + string reason = 1; + int32 count = 2; + } + + message LatencyInfo { + int32 top99 = 1; + int32 top95 = 2; + int32 top75 = 3; + int32 totalCount = 4; + int32 delay1S = 5; + int32 delay2S = 6; + int32 delay3S = 7; + repeated LatencyDetailInfo detail = 8; + + message LatencyDetailInfo { + string witness = 1; + int32 top99 = 2; + int32 top95 = 3; + int32 top75 = 4; + int32 count = 5; + int32 delay1S = 6; + int32 delay2S = 7; + int32 delay3S = 8; + } + } + } } -message MarketPrice { - int64 sell_token_quantity = 1; - int64 buy_token_quantity = 2; +message PBFTMessage { + enum MsgType { + VIEW_CHANGE = 0; + REQUEST = 1; + PREPREPARE = 2; + PREPARE = 3; + COMMIT = 4; + } + enum DataType { + BLOCK = 0; + SRL = 1; + } + message Raw { + MsgType msg_type = 1; + DataType data_type = 2; + int64 view_n = 3; + int64 epoch = 4; + bytes data = 5; + } + Raw raw_data = 1; + bytes signature = 2; } -message MarketPriceList { - bytes sell_token_id = 1; - bytes buy_token_id = 2; - repeated MarketPrice prices = 3; +message PBFTCommitResult { + bytes data = 1; + repeated bytes signature = 2; } -message MarketOrderIdList { - bytes head = 1; - bytes tail = 2; +message SRL { + repeated bytes srAddress = 1; } diff --git a/src/main/protos/core/contract/smart_contract.proto b/src/main/protos/core/contract/smart_contract.proto index 40fbb5b7d..c913f7f75 100644 --- a/src/main/protos/core/contract/smart_contract.proto +++ b/src/main/protos/core/contract/smart_contract.proto @@ -9,89 +9,96 @@ option go_package = "github.com/tronprotocol/grpc-gateway/core"; import "core/Tron.proto"; message SmartContract { - message ABI { - message Entry { - enum EntryType { - UnknownEntryType = 0; - Constructor = 1; - Function = 2; - Event = 3; - Fallback = 4; - Receive = 5; - Error = 6; - } - message Param { - bool indexed = 1; - string name = 2; - string type = 3; - // SolidityType type = 3; - } - enum StateMutabilityType { - UnknownMutabilityType = 0; - Pure = 1; - View = 2; - Nonpayable = 3; - Payable = 4; - } + message ABI { + message Entry { + enum EntryType { + UnknownEntryType = 0; + Constructor = 1; + Function = 2; + Event = 3; + Fallback = 4; + Receive = 5; + Error = 6; + } + message Param { + bool indexed = 1; + string name = 2; + string type = 3; + // SolidityType type = 3; + } + enum StateMutabilityType { + UnknownMutabilityType = 0; + Pure = 1; + View = 2; + Nonpayable = 3; + Payable = 4; + } - bool anonymous = 1; - bool constant = 2; - string name = 3; - repeated Param inputs = 4; - repeated Param outputs = 5; - EntryType type = 6; - bool payable = 7; - StateMutabilityType stateMutability = 8; - } - repeated Entry entrys = 1; + bool anonymous = 1; + bool constant = 2; + string name = 3; + repeated Param inputs = 4; + repeated Param outputs = 5; + EntryType type = 6; + bool payable = 7; + StateMutabilityType stateMutability = 8; } - bytes origin_address = 1; - bytes contract_address = 2; - ABI abi = 3; - bytes bytecode = 4; - int64 call_value = 5; - int64 consume_user_resource_percent = 6; - string name = 7; - int64 origin_energy_limit = 8; - bytes code_hash = 9; - bytes trx_hash = 10; - int32 version = 11; + repeated Entry entrys = 1; + } + bytes origin_address = 1; + bytes contract_address = 2; + ABI abi = 3; + bytes bytecode = 4; + int64 call_value = 5; + int64 consume_user_resource_percent = 6; + string name = 7; + int64 origin_energy_limit = 8; + bytes code_hash = 9; + bytes trx_hash = 10; + int32 version = 11; +} + +message ContractState { + int64 energy_usage = 1; + int64 energy_factor = 2; + int64 update_cycle = 3; } message CreateSmartContract { - bytes owner_address = 1; - SmartContract new_contract = 2; - int64 call_token_value = 3; - int64 token_id = 4; + bytes owner_address = 1; + SmartContract new_contract = 2; + int64 call_token_value = 3; + int64 token_id = 4; } message TriggerSmartContract { - bytes owner_address = 1; - bytes contract_address = 2; - int64 call_value = 3; - bytes data = 4; - int64 call_token_value = 5; - int64 token_id = 6; + bytes owner_address = 1; + bytes contract_address = 2; + int64 call_value = 3; + bytes data = 4; + int64 call_token_value = 5; + int64 token_id = 6; } message ClearABIContract { - bytes owner_address = 1; - bytes contract_address = 2; + bytes owner_address = 1; + bytes contract_address = 2; } message UpdateSettingContract { - bytes owner_address = 1; - bytes contract_address = 2; - int64 consume_user_resource_percent = 3; + bytes owner_address = 1; + bytes contract_address = 2; + int64 consume_user_resource_percent = 3; } message UpdateEnergyLimitContract { - bytes owner_address = 1; - bytes contract_address = 2; - int64 origin_energy_limit = 3; + bytes owner_address = 1; + bytes contract_address = 2; + int64 origin_energy_limit = 3; } message SmartContractDataWrapper { - SmartContract smart_contract = 1; - bytes runtimecode = 2; -} + SmartContract smart_contract = 1; + bytes runtimecode = 2; + ContractState contract_state = 3; +} \ No newline at end of file