添加校验
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();
|
ITronService tron = tronServiceProvider.getCurrentService();
|
||||||
ApiWrapper api = tron.buildApiWrapper();
|
ApiWrapper api = tron.buildApiWrapper();
|
||||||
try {
|
try {
|
||||||
|
if ("delegate".equals(operationType)) {
|
||||||
|
validateDelegationTarget(tron, api, wallet, request.getToAddress());
|
||||||
|
}
|
||||||
long energy = estimateEnergy(operationType, tron, api, wallet, request);
|
long energy = estimateEnergy(operationType, tron, api, wallet, request);
|
||||||
long bandwidth = estimateBandwidth(operationType, tron, api, wallet, request);
|
long bandwidth = estimateBandwidth(operationType, tron, api, wallet, request);
|
||||||
EnergyAndBandwidthVo current = tron.energyAndBandwidth(wallet.getToken());
|
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,
|
private long estimateEnergy(String operationType, ITronService tron, ApiWrapper api,
|
||||||
WalletAddressPlus wallet, WalletOperationRequest request) {
|
WalletAddressPlus wallet, WalletOperationRequest request) {
|
||||||
if (!"usdt".equals(operationType)) {
|
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.UsdtConfig;
|
||||||
import com.ruoyi.system.domain.WalletAddressPlus;
|
import com.ruoyi.system.domain.WalletAddressPlus;
|
||||||
import com.ruoyi.system.mapper.UsdtConfigMapper;
|
import com.ruoyi.system.mapper.UsdtConfigMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bitcoinj.crypto.ChildNumber;
|
import org.bitcoinj.crypto.ChildNumber;
|
||||||
import org.bitcoinj.crypto.DeterministicKey;
|
import org.bitcoinj.crypto.DeterministicKey;
|
||||||
import org.bitcoinj.crypto.HDPath;
|
import org.bitcoinj.crypto.HDPath;
|
||||||
@@ -23,6 +24,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** 使用配置密码在内存中解锁指定 HD 钱包,并执行需要签名的链上操作。 */
|
/** 使用配置密码在内存中解锁指定 HD 钱包,并执行需要签名的链上操作。 */
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class WalletSigningService {
|
public class WalletSigningService {
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -58,6 +60,7 @@ public class WalletSigningService {
|
|||||||
} catch (CustomException e) {
|
} catch (CustomException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
throw new CustomException("钱包解密或链上签名操作失败", e);
|
throw new CustomException("钱包解密或链上签名操作失败", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
|
|||||||
Reference in new issue
Block a user