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