mirror of https://gitee.com/y_project/RuoYi.git
修复委托监控地址为空报错bug
parent
166b5ef6ad
commit
44cd5c2297
|
@ -2,6 +2,7 @@ package com.ruoyi.system.domain;
|
|||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
|
||||
/**
|
||||
* trx兑能量记录对象 trx_exchange_info
|
||||
*
|
||||
|
@ -20,10 +21,31 @@ public class TrxExchange extends BaseEntity
|
|||
/** 实际出账账户 */
|
||||
private String accountAddress;
|
||||
|
||||
private String monitorAddress;
|
||||
|
||||
private Long transferNumber;
|
||||
|
||||
private Long lockNum;
|
||||
|
||||
private Long price;
|
||||
|
||||
|
||||
public String getMonitorAddress() {
|
||||
return monitorAddress;
|
||||
}
|
||||
|
||||
public void setMonitorAddress(String monitorAddress) {
|
||||
this.monitorAddress = monitorAddress;
|
||||
}
|
||||
|
||||
public Long getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Long price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getFromAddress() {
|
||||
return fromAddress;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
|||
import com.google.common.base.Preconditions;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.AccountAddressInfo;
|
||||
import com.ruoyi.common.core.domain.entity.MonitorAddressInfo;
|
||||
import com.ruoyi.common.core.domain.entity.TenantInfo;
|
||||
import com.ruoyi.common.core.domain.entity.TrxExchangeInfo;
|
||||
|
@ -13,10 +14,12 @@ import com.ruoyi.common.core.text.Convert;
|
|||
import com.ruoyi.common.utils.DictUtils;
|
||||
import com.ruoyi.common.utils.ShiroUtils;
|
||||
import com.ruoyi.system.domain.TrxExchange;
|
||||
import com.ruoyi.system.mapper.AccountAddressInfoMapper;
|
||||
import com.ruoyi.system.mapper.MonitorAddressInfoMapper;
|
||||
import com.ruoyi.system.mapper.TenantInfoMapper;
|
||||
import com.ruoyi.system.service.ITenantInfoService;
|
||||
import com.ruoyi.system.service.ITrxExchangeInfoService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -39,7 +42,8 @@ public class TenantInfoServiceImpl implements ITenantInfoService
|
|||
private ITrxExchangeInfoService trxExchangeInfoService;
|
||||
@Autowired
|
||||
private MonitorAddressInfoMapper monitorAddressInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private AccountAddressInfoMapper accountAddressInfoMapper;
|
||||
/**
|
||||
* 查询租户
|
||||
*
|
||||
|
@ -175,21 +179,40 @@ public class TenantInfoServiceImpl implements ITenantInfoService
|
|||
|
||||
Preconditions.checkState(CollectionUtil.isEmpty(trxExchangeInfos), "该接收能量地址已在任务中,请勿重复发起");
|
||||
|
||||
String accountAddress = null;
|
||||
String monitorAddress = null;
|
||||
if (StringUtils.isNotEmpty(tenantInfo.getMonitorAddress())){
|
||||
MonitorAddressInfo monitorAddressInfoExample = new MonitorAddressInfo();
|
||||
monitorAddressInfoExample.setMonitorAddress(tenantInfo.getMonitorAddress());
|
||||
monitorAddressInfoExample.setIsValid(UserConstants.YES);
|
||||
List<MonitorAddressInfo> monitorAddressInfoList = monitorAddressInfoMapper.selectMonitorAddressInfoList(monitorAddressInfoExample);
|
||||
Preconditions.checkState(CollectionUtil.isNotEmpty(monitorAddressInfoList), "监听地址不存在或者已失效,无法再次委托能量");
|
||||
|
||||
MonitorAddressInfo monitorAddressInfoExample = new MonitorAddressInfo();
|
||||
monitorAddressInfoExample.setMonitorAddress(tenantInfo.getMonitorAddress());
|
||||
monitorAddressInfoExample.setIsValid(UserConstants.YES);
|
||||
List<MonitorAddressInfo> monitorAddressInfoList = monitorAddressInfoMapper.selectMonitorAddressInfoList(monitorAddressInfoExample);
|
||||
MonitorAddressInfo monitorAddressInfo = monitorAddressInfoList.get(0);
|
||||
accountAddress = monitorAddressInfo.getAccountAddress();
|
||||
|
||||
Preconditions.checkState(CollectionUtil.isNotEmpty(monitorAddressInfoList), "监听地址不存在或者已失效,无法再次委托能量");
|
||||
monitorAddress = monitorAddressInfo.getMonitorAddress();
|
||||
}else {
|
||||
AccountAddressInfo accountAddressInfo = new AccountAddressInfo();
|
||||
accountAddressInfo.setIsValid("Y");
|
||||
List<AccountAddressInfo> accountAddressInfoList = accountAddressInfoMapper.selectAccountAddressInfoList(accountAddressInfo);
|
||||
Preconditions.checkState(CollectionUtil.isNotEmpty(accountAddressInfoList), "无有效的出账地址无法委托能量");
|
||||
|
||||
accountAddress = accountAddressInfoList.get(0).getAddress();
|
||||
|
||||
}
|
||||
|
||||
MonitorAddressInfo monitorAddressInfo = monitorAddressInfoList.get(0);
|
||||
|
||||
TrxExchange trxExchange = new TrxExchange();
|
||||
trxExchange.setFromAddress(tenantInfo.getReceiverAddress());
|
||||
trxExchange.setAccountAddress(monitorAddressInfo.getAccountAddress());
|
||||
|
||||
trxExchange.setAccountAddress(accountAddress);
|
||||
trxExchange.setTransferNumber(tenantInfo.getTransferCount());
|
||||
|
||||
trxExchange.setPrice(tenantInfo.getPrice());
|
||||
|
||||
trxExchange.setMonitorAddress(monitorAddress);
|
||||
|
||||
long between = DateUtil.between(DateUtil.date(), DateUtil.endOfDay(DateUtil.date()), DateUnit.HOUR);
|
||||
trxExchange.setLockNum(between + 1);
|
||||
|
||||
|
|
|
@ -155,13 +155,13 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
Long transferNumber = trxExchange.getTransferNumber();
|
||||
//实际锁定周期
|
||||
long lockPeriod = trxExchange.getLockNum() * 1200;
|
||||
String systronApiSwitch = configService.selectConfigByKey("sys.tron.api");
|
||||
// String systronApiSwitch = configService.selectConfigByKey("sys.tron.api");
|
||||
|
||||
String fromAddress = trxExchange.getFromAddress();
|
||||
|
||||
String dictValue = DictUtils.getDictValue("sys_delegate_status", "已委托");
|
||||
// String dictValue = DictUtils.getDictValue("sys_delegate_status", "已委托");
|
||||
|
||||
TrxExchangeInfo trxExchangeInfo = null;
|
||||
// TrxExchangeInfo trxExchangeInfo = null;
|
||||
String userName = ShiroUtils.getLoginName();
|
||||
String busiType = DictUtils.getDictValue("sys_busi_type", "闪兑套餐");
|
||||
if (isTenant) {
|
||||
|
@ -169,71 +169,28 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
} else if (lockPeriod > 1200 && lockPeriod <= 24 * 1200) {
|
||||
busiType = DictUtils.getDictValue("sys_busi_type", "笔数套餐");
|
||||
}
|
||||
if (UserConstants.YES.equals(systronApiSwitch)) {
|
||||
String accountAddress = trxExchange.getAccountAddress();
|
||||
String decryptPrivateKey = accountAddressInfoService.getDecryptPrivateKey(accountAddress);
|
||||
// if (UserConstants.YES.equals(systronApiSwitch)) {
|
||||
String accountAddress = trxExchange.getAccountAddress();
|
||||
String decryptPrivateKey = accountAddressInfoService.getDecryptPrivateKey(accountAddress);
|
||||
|
||||
String tronApiKey = DictUtils.getDictValue("sys_tron_api_key", "synp@outlook");
|
||||
String tronApiKey = DictUtils.getDictValue("sys_tron_api_key", "synp@outlook");
|
||||
|
||||
ApiWrapper apiWrapper = ApiWrapper.ofMainnet(decryptPrivateKey, tronApiKey);
|
||||
ApiWrapper apiWrapper = ApiWrapper.ofMainnet(decryptPrivateKey, tronApiKey);
|
||||
|
||||
calcBalanceAndDelegate(null,
|
||||
apiWrapper,
|
||||
accountAddress,
|
||||
transferNumber,
|
||||
fromAddress,
|
||||
lockPeriod,
|
||||
null,
|
||||
null,
|
||||
busiType,
|
||||
null,
|
||||
userName);
|
||||
/* Response.AccountResourceMessage accountResource = apiWrapper.getAccountResource(accountAddress);
|
||||
|
||||
//总用于质押换取能量的trx上限
|
||||
long balance = getBalance(accountResource, transferNumber);
|
||||
|
||||
String delegateResourceTxid = getDelegateResourceTxid(apiWrapper, accountAddress, balance, fromAddress, lockPeriod);
|
||||
|
||||
|
||||
trxExchangeInfo = TrxExchangeInfo.builder()
|
||||
.delegateAmountTrx(balance)
|
||||
.tranferCount(transferNumber)
|
||||
.busiType(busiType)
|
||||
.lockPeriod(lockPeriod)
|
||||
.accountAddress(trxExchange.getAccountAddress())
|
||||
.fromAddress(fromAddress)
|
||||
.delegateTxId(delegateResourceTxid)
|
||||
.delegateStatus(dictValue)
|
||||
.fcu(userName)
|
||||
.lcu(userName)
|
||||
.build();*/
|
||||
|
||||
} else {
|
||||
// String busiType = DictUtils.getDictValue("sys_busi_type", "闪兑套餐");
|
||||
// if (isTenant) {
|
||||
// busiType = DictUtils.getDictValue("sys_busi_type", "天数套餐");
|
||||
// } else if (lockPeriod > 1200 && lockPeriod <= 24 * 1200) {
|
||||
// busiType = DictUtils.getDictValue("sys_busi_type", "笔数套餐");
|
||||
// }
|
||||
trxExchangeInfo = TrxExchangeInfo.builder()
|
||||
.delegateAmountTrx(0L)
|
||||
.tranferCount(transferNumber)
|
||||
.lockPeriod(lockPeriod)
|
||||
.busiType(busiType)
|
||||
.lockPeriod(lockPeriod)
|
||||
.accountAddress(trxExchange.getAccountAddress())
|
||||
.fromAddress(fromAddress)
|
||||
.delegateStatus(dictValue)
|
||||
.fcu(userName)
|
||||
.lcu(userName)
|
||||
.build();
|
||||
}
|
||||
|
||||
return trxExchangeInfoMapper.insertTrxExchangeInfo(trxExchangeInfo);
|
||||
calcBalanceAndDelegate(null,
|
||||
apiWrapper,
|
||||
accountAddress,
|
||||
transferNumber,
|
||||
fromAddress,
|
||||
lockPeriod,
|
||||
trxExchange.getMonitorAddress(),
|
||||
trxExchange.getPrice(),
|
||||
busiType,
|
||||
null,
|
||||
userName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 按照单个地址监听方法
|
||||
*
|
||||
|
@ -401,7 +358,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
|
||||
long lockPeriod = 1200L;
|
||||
long transferCount = 0L;
|
||||
Integer price = null;
|
||||
Long price = null;
|
||||
String busiType = DictUtils.getDictValue("sys_busi_type", "闪兑套餐");
|
||||
|
||||
//查询是否是按天支付的租户
|
||||
|
@ -413,7 +370,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
List<TenantInfo> tenantInfoList = tenantInfoMapper.selectTenantInfoList(tenantInfoExample);
|
||||
TenantInfo tenantInfo = null;
|
||||
if (tenantInfoList.size() > 0) {
|
||||
tenantInfo = tenantInfoList.get(0);
|
||||
tenantInfo = tenantInfoList.get(0);
|
||||
Long exchangeAmount = tenantInfo.getExchangeAmount();
|
||||
//判断入账金额是否与转入金额相等,如果相等则设置为已支付
|
||||
if (amount != exchangeAmount) {
|
||||
|
@ -437,10 +394,10 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
lockPeriod = 1200L * 24;
|
||||
busiType = DictUtils.getDictValue("sys_busi_type", "天数套餐");
|
||||
transferCount = tenantInfo.getTransferCount();
|
||||
price = tenantInfo.getPrice().intValue();
|
||||
price = tenantInfo.getPrice();
|
||||
|
||||
} else {
|
||||
price = monitorAddressAccount.getPrice();
|
||||
price = monitorAddressAccount.getPrice().longValue();
|
||||
transferCount = amount / price;
|
||||
|
||||
if (transferCount < 1) {
|
||||
|
@ -461,7 +418,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
calcBalanceAndDelegate(txID, apiWrapper, accountAddress, transferCount, ownerAddress, lockPeriod, toAddress, price, busiType, amount, "system");
|
||||
//持久化之后放redis
|
||||
redisTemplate.opsForValue().set("transfer_trx_" + txID, txID, 1, TimeUnit.DAYS);
|
||||
if (tenantInfo !=null){
|
||||
if (tenantInfo != null) {
|
||||
tenantInfoMapper.updateTenantInfo(tenantInfo);
|
||||
}
|
||||
|
||||
|
@ -488,26 +445,29 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
String ownerAddress,
|
||||
long lockPeriod,
|
||||
String toAddress,
|
||||
Integer price,
|
||||
Long price,
|
||||
String busiType,
|
||||
Long amount,
|
||||
String currentUser) throws Exception {
|
||||
|
||||
String systronApiSwitch = configService.selectConfigByKey("sys.tron.api");
|
||||
Long balance = null;
|
||||
String delegateResourceTxid = null;
|
||||
if (UserConstants.YES.equals(systronApiSwitch)) {
|
||||
Response.AccountResourceMessage accountResource = apiWrapper.getAccountResource(accountAddress);
|
||||
|
||||
Response.AccountResourceMessage accountResource = apiWrapper.getAccountResource(accountAddress);
|
||||
//总用于质押换取能量的trx上限
|
||||
balance = getBalance(accountResource, transferCount);
|
||||
|
||||
//总用于质押换取能量的trx上限
|
||||
long balance = getBalance(accountResource, transferCount);
|
||||
|
||||
/* lock_period: 锁定周期,以区块时间(3s)为单位,表示锁定多少个区块的时间,当lock为true时,该字段有效。如果代理锁定期为1天,则lock_period为:28800*/
|
||||
|
||||
String delegateResourceTxid = getDelegateResourceTxid(apiWrapper, accountAddress, balance, ownerAddress, lockPeriod);
|
||||
/* lock_period: 锁定周期,以区块时间(3s)为单位,表示锁定多少个区块的时间,当lock为true时,该字段有效。如果代理锁定期为1天,则lock_period为:28800*/
|
||||
|
||||
delegateResourceTxid = getDelegateResourceTxid(apiWrapper, accountAddress, balance, ownerAddress, lockPeriod);
|
||||
}
|
||||
TrxExchangeInfo trxExchangeInfo = TrxExchangeInfo.builder()
|
||||
.fromAddress(AddressUtil.hexToBase58(ownerAddress))
|
||||
.toAddress(AddressUtil.hexToBase58(toAddress))
|
||||
.accountAddress(accountAddress)
|
||||
.price(Long.valueOf(price))
|
||||
.price(price)
|
||||
.trxTxId(txID)
|
||||
.tranferCount(transferCount)
|
||||
.busiType(busiType)
|
||||
|
@ -590,7 +550,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
TenantInfo tenantInfo = null;
|
||||
if (tenantInfoList.size() > 0) {
|
||||
Response.AccountResourceMessage accountResource = apiWrapper.getAccountResource(accountAddress);
|
||||
tenantInfo = tenantInfoList.get(0);
|
||||
tenantInfo = tenantInfoList.get(0);
|
||||
|
||||
if (UserConstants.NO.equals(tenantInfo.getIsPaid())) {
|
||||
return;
|
||||
|
@ -632,7 +592,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
receiverAddress,
|
||||
newLockPeriod,
|
||||
monitorAddress,
|
||||
tenantInfo.getPrice() == null ? null : tenantInfo.getPrice().intValue(),
|
||||
tenantInfo.getPrice(),
|
||||
busiType,
|
||||
null,
|
||||
"system");
|
||||
|
@ -665,7 +625,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
|
|||
trxExchangeInfoMapper.insertTrxExchangeInfo(trxExchangeInfoNew);*/
|
||||
}
|
||||
|
||||
if (tenantInfo != null){
|
||||
if (tenantInfo != null) {
|
||||
|
||||
tenantInfoMapper.updateTenantInfo(tenantInfo);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package com.ruoyi.system.util;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.tron.trident.core.ApiWrapper;
|
||||
import org.tron.trident.utils.Base58Check;
|
||||
|
||||
public class AddressUtil {
|
||||
public static String hexToBase58(String address) {
|
||||
if (StringUtils.isEmpty(address)){
|
||||
return null;
|
||||
}
|
||||
ByteString bytes = ApiWrapper.parseAddress(address);
|
||||
return Base58Check.bytesToBase58(bytes.toByteArray());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue