添加校验
This commit is contained in:
1 parent
219bc724b2
commit
430582253b
2 files changed
+39
No files matched your search
+36
@@ -34,6 +34,9 @@ public class WalletOperationEstimateService {
|
||||
ITronService tron = tronServiceProvider.getCurrentService();
|
||||
ApiWrapper api = tron.buildApiWrapper();
|
||||
try {
|
||||
if ("delegate".equals(operationType)) {
|
||||
validateDelegationTarget(tron, api, wallet, request.getToAddress());
|
||||
}
|
||||
long energy = estimateEnergy(operationType, tron, api, wallet, request);
|
||||
long bandwidth = estimateBandwidth(operationType, tron, api, wallet, request);
|
||||
EnergyAndBandwidthVo current = tron.energyAndBandwidth(wallet.getToken());
|
||||
@@ -79,6 +82,39 @@ public class WalletOperationEstimateService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TRON 协议禁止向未激活账户代理资源。该检查使用只读客户端,
|
||||
* 必须在请求配置密码及解密私钥之前完成。
|
||||
*/
|
||||
public void validateDelegationTarget(WalletAddressPlus wallet, String targetAddress) {
|
||||
ITronService tron = tronServiceProvider.getCurrentService();
|
||||
ApiWrapper api = tron.buildApiWrapper();
|
||||
try {
|
||||
validateDelegationTarget(tron, api, wallet, targetAddress);
|
||||
} finally {
|
||||
api.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDelegationTarget(ITronService tron, ApiWrapper api,
|
||||
WalletAddressPlus wallet, String targetAddress) {
|
||||
String target = targetAddress == null ? "" : targetAddress.trim();
|
||||
if (target.equals(wallet.getToken())) {
|
||||
throw new CustomException("不能将资源代理给当前钱包自身");
|
||||
}
|
||||
try {
|
||||
Response.Account account = api.getAccount(target);
|
||||
if (account == null || account.getAddress() == null || account.getAddress().isEmpty()) {
|
||||
throw new CustomException("目标地址在当前 " + tron.type()
|
||||
+ " 网络尚未激活,请先向该地址转入 TRX 激活账户后再代理");
|
||||
}
|
||||
} catch (CustomException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
throw new CustomException("目标地址无效或账户状态查询失败,请确认地址和当前网络", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private long estimateEnergy(String operationType, ITronService tron, ApiWrapper api,
|
||||
WalletAddressPlus wallet, WalletOperationRequest request) {
|
||||
if (!"usdt".equals(operationType)) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ruoyi.system.demo.WalletEnvelopeEncryptionDemo;
|
||||
import com.ruoyi.system.domain.UsdtConfig;
|
||||
import com.ruoyi.system.domain.WalletAddressPlus;
|
||||
import com.ruoyi.system.mapper.UsdtConfigMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.crypto.ChildNumber;
|
||||
import org.bitcoinj.crypto.DeterministicKey;
|
||||
import org.bitcoinj.crypto.HDPath;
|
||||
@@ -23,6 +24,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/** 使用配置密码在内存中解锁指定 HD 钱包,并执行需要签名的链上操作。 */
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WalletSigningService {
|
||||
@Autowired
|
||||
@@ -58,6 +60,7 @@ public class WalletSigningService {
|
||||
} catch (CustomException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
throw new CustomException("钱包解密或链上签名操作失败", e);
|
||||
} finally {
|
||||
if (api != null) {
|
||||
|
||||
Reference in new issue
Block a user