Skip to content

Commit

Permalink
feat(api): depreacate api estimateEnergyV2 (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
317787106 authored Feb 20, 2025
1 parent c2b739c commit d6a1dae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,12 @@ TransactionExtention approveProposal(String ownerAddress, long proposalId, boole
Response.EstimateEnergyMessage estimateEnergy(String ownerAddress, String contractAddress,
Function function);

Response.EstimateEnergyMessage estimateEnergyV2(String ownerAddress, String contractAddress,
String callData);
Response.EstimateEnergyMessage estimateEnergy(String ownerAddress,
String contractAddress, String callData, long callValue, long tokenValue, String tokenId);

@Deprecated
Response.EstimateEnergyMessage estimateEnergyV2(String ownerAddress, String contractAddress,
String callData, long callValue, long tokenValue, String tokenId);
String callData);

@Deprecated
TransactionBuilder triggerCallV2(String ownerAddress, String contractAddress, String callData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static ApiWrapper ofMainnet(String hexPrivateKey, String apiKey) {
*
* @param hexPrivateKey the binding private key. Operations require private key will all use this unless the private key is specified elsewhere.
* @return a ApiWrapper object
* @deprecated Since 0.9.3, scheduled for removal in future versions.
* @deprecated Since 0.9.2, scheduled for removal in future versions.
* This method will only be available before TronGrid prohibits the use without API key
*/
@Deprecated
Expand Down Expand Up @@ -1892,7 +1892,7 @@ private boolean isFuncInContract(Contract contract, Function function) {
* @param contractAddress smart contract address.
* @param function contract function.
* @return TransactionExtention.
* @deprecated Since 0.9.3, scheduled for removal in future versions.
* @deprecated Since 0.9.2, scheduled for removal in future versions.
* Use {@link #triggerConstantContract(String, String, Function)} instead.
*/
@Deprecated
Expand All @@ -1909,7 +1909,7 @@ public TransactionExtention constantCall(String ownerAddress, String contractAdd
* @param contractAddress smart contract address.
* @param callData The data passed along with a transaction that allows us to interact with smart contracts.
* @return TransactionExtention.
* @deprecated Since 0.9.3, scheduled for removal in future versions.
* @deprecated Since 0.9.2, scheduled for removal in future versions.
* Use {@link #triggerConstantContract(String, String, String)} instead.
*/
@Deprecated
Expand Down Expand Up @@ -1965,7 +1965,7 @@ public TransactionExtention triggerConstantContract(String ownerAddress, String
* @param contractAddress smart contract address
* @param function contract function
* @return transaction builder. Users may set other fields, e.g. feeLimit
* @deprecated Since 0.9.3, scheduled for removal in future versions.
* @deprecated Since 0.9.2, scheduled for removal in future versions.
* Use {@link #triggerConstantContract(String, String, Function)} instead.
*/
@Deprecated
Expand All @@ -1983,7 +1983,7 @@ public TransactionBuilder triggerCall(String ownerAddress, String contractAddres
* @param contractAddress smart contract address
* @param callData The data passed along with a transaction that allows us to interact with smart contracts.
* @return transaction builder. TransactionExtention detail.
* @deprecated Since 0.9.3, scheduled for removal in future versions.
* @deprecated Since 0.9.2, scheduled for removal in future versions.
* Use {@link #triggerConstantContract(String, String, String)} instead.
*/
@Deprecated
Expand Down Expand Up @@ -2264,11 +2264,11 @@ public Block getBlockById(String blockID) {
/**
* Estimate the energy required for the successful execution of smart contract transactions
* This API is closed by default in tron node.
* To open this interface, the two coniguration items vm.estimateEnergy and vm.supportConstant
* To open this interface, the two configuration items vm.estimateEnergy and vm.supportConstant
* must be enabled in the node configuration file at the same time.
*
* @param ownerAddress Owner address that triggers the contract. If visible=true, use base58check format, otherwise use hex format.
* For constant call you can use the all-zero address.
* @param ownerAddress Owner address that triggers the contract. If visible=true, use base58check
* format, otherwise use hex format. For constant call you can use the all-zero address.
* @param contractAddress Smart contract address.
* @param function contract function
* @return EstimateEnergyMessage. Estimated energy to run the contract
Expand All @@ -2282,6 +2282,29 @@ public Response.EstimateEnergyMessage estimateEnergy(String ownerAddress, String
return blockingStub.estimateEnergy(trigger);
}

/**
* Estimate the energy required for the successful execution of smart contract transactions
* This API is closed by default in tron node. To open this interface, the two configuration
* items vm.estimateEnergy and vm.supportConstant must be enabled in the node configuration file
* at the same time.
*
* @param ownerAddress Owner address that triggers the contract. If visible=true, use base58check
* format, otherwise use hex format. For constant call you can use the all-zero address.
* @param contractAddress Smart contract address.
* @param callData The data passed along with a transaction that allows us to interact with smart contracts.
* @param callValue call Value. If TRX not used, use 0.
* @param tokenValue token Value, If token10 not used, use 0.
* @param tokenId token10 ID, If token10 not used, use null.
* @return EstimateEnergyMessage. Estimated energy to run the contract
*/
@Override
public Response.EstimateEnergyMessage estimateEnergy(String ownerAddress,
String contractAddress, String callData, long callValue, long tokenValue, String tokenId) {
TriggerSmartContract trigger = buildTrigger(ownerAddress, contractAddress, callData, callValue,
tokenValue, tokenId);
return blockingStub.estimateEnergy(trigger);
}

/**
* Estimate the energy required for the successful execution of smart contract transactions
* This API is closed by default in tron node. To open this interface, the two configuration
Expand All @@ -2294,6 +2317,8 @@ public Response.EstimateEnergyMessage estimateEnergy(String ownerAddress, String
* @param contractAddress Smart contract address.
* @param callData The data passed along with a transaction that allows us to interact with smart contracts.
* @return EstimateEnergyMessage. Estimated energy to run the contract
* @deprecated Since 0.9.2, scheduled for removal in future versions.
* Use {@link #estimateEnergy(String, String, String, long, long, String)} instead.
*/
@Override
public Response.EstimateEnergyMessage estimateEnergyV2(String ownerAddress,
Expand All @@ -2303,14 +2328,6 @@ public Response.EstimateEnergyMessage estimateEnergyV2(String ownerAddress,
return blockingStub.estimateEnergy(trigger);
}

@Override
public Response.EstimateEnergyMessage estimateEnergyV2(String ownerAddress,
String contractAddress, String callData, long callValue, long tokenValue, String tokenId) {
TriggerSmartContract trigger = buildTrigger(ownerAddress, contractAddress, callData, callValue,
tokenValue, tokenId);
return blockingStub.estimateEnergy(trigger);
}

/**
* construct TriggerSmartContract
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void testEstimateEnergyV2WithCallValue() {
Collections.singletonList(new TypeReference<Uint256>() {
}));
String encodedHex = FunctionEncoder.encode(depositFunction);
EstimateEnergyMessage estimateEnergyMessage = client.estimateEnergyV2(fromAddr, strx,
EstimateEnergyMessage estimateEnergyMessage = client.estimateEnergy(fromAddr, strx,
encodedHex, 1_000_000L, 0, "");
//System.out.println(estimateEnergyMessage.getEnergyRequired());
assertTrue(estimateEnergyMessage.getEnergyRequired() > 0);
Expand Down

0 comments on commit d6a1dae

Please sign in to comment.