|
|
|
@ -81,6 +81,10 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
@Autowired |
|
|
|
|
@Qualifier("asyncExecutorNftPush") |
|
|
|
|
private Executor asyncExecutorNftPush; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
@Qualifier("asyncExecutorNftRqurest") |
|
|
|
|
private Executor asyncExecutorNftRqurest; |
|
|
|
|
@Autowired |
|
|
|
|
private IPrivateKeyService privateKeyService; |
|
|
|
|
@Autowired |
|
|
|
@ -300,7 +304,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
|
public AjaxResult push(CheckArgs checkArgs) { |
|
|
|
|
public AjaxResult push(CheckArgs checkArgs) { |
|
|
|
|
//判断参数
|
|
|
|
|
if (null == checkArgs) { |
|
|
|
|
return AjaxResult.error("参数为空!"); |
|
|
|
@ -374,14 +378,14 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
opt.withGasPrice(contractConfig.getGasPrice()); |
|
|
|
|
//获取账户余额
|
|
|
|
|
BigInteger balance = cfx.getBalance(account.getAddress()).sendAndGet(); |
|
|
|
|
Account sponsorWhitelistControlAccount=Account.create(cfx,AESUtil.decrypt(contractConfig.getPrivateKey())); |
|
|
|
|
SponsorWhitelistControl sponsorWhitelistControl=new SponsorWhitelistControl(sponsorWhitelistControlAccount); |
|
|
|
|
Account sponsorWhitelistControlAccount = Account.create(cfx, AESUtil.decrypt(contractConfig.getPrivateKey())); |
|
|
|
|
SponsorWhitelistControl sponsorWhitelistControl = new SponsorWhitelistControl(sponsorWhitelistControlAccount); |
|
|
|
|
Address address = new Address(contractConfig.getContract()); |
|
|
|
|
//获取代付账户余额
|
|
|
|
|
BigInteger sponsoredBalanceForCollateral = sponsorWhitelistControl.getSponsoredBalanceForCollateral(address.getABIAddress()); |
|
|
|
|
//剩余燃气值
|
|
|
|
|
BigInteger sponsoredBalanceForGas = sponsorWhitelistControl.getSponsoredBalanceForGas(address.getABIAddress()); |
|
|
|
|
log.info("[--------------------->mintNft][balance]{}[sponsoredBalanceForCollateral:]{}[sponsoredBalanceForGas:]{}", balance,sponsoredBalanceForCollateral,sponsoredBalanceForGas); |
|
|
|
|
log.info("[--------------------->mintNft][balance]{}[sponsoredBalanceForCollateral:]{}[sponsoredBalanceForGas:]{}", balance, sponsoredBalanceForCollateral, sponsoredBalanceForGas); |
|
|
|
|
if (balance.compareTo(new BigInteger("40000000000000000000")) < 0) { |
|
|
|
|
log.info("[--------------------->mintNft][balance not enough 50]{}", balance); |
|
|
|
|
//sms notice
|
|
|
|
@ -404,7 +408,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
est = confluxExecutor.getEstimate(cfx, new Address(owner), |
|
|
|
|
new Address(contract), AddressUtil.getHexAddress(owner), tokenIds); |
|
|
|
|
//判断所需要的费用
|
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed())<0){ |
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed()) < 0) { |
|
|
|
|
return AjaxResult.error("代付余额不足"); |
|
|
|
|
} |
|
|
|
|
log.info("[--------------------->mintNft][GasUsed]{}", est.getGasUsed()); |
|
|
|
@ -423,11 +427,11 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
est = confluxExecutor.getEstimateDataStr(cfx, new Address(owner), |
|
|
|
|
new Address(contract), AddressUtil.getHexAddress(owner), tokenIds, tokenURIs); |
|
|
|
|
//判断所需要的费用
|
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed())<0){ |
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed()) < 0) { |
|
|
|
|
return AjaxResult.error("代付余额不足"); |
|
|
|
|
} |
|
|
|
|
log.info("[--------------------->mintNft][GasUsed]{}", est.getGasUsed()); |
|
|
|
|
log.info("[--------------------->mintNft][StorageCollateralized]{}", est.getStorageCollateralized()); |
|
|
|
|
log.info("[--------------------->awardItemDataStr][GasUsed]{}", est.getGasUsed()); |
|
|
|
|
log.info("[--------------------->awardItemDataStr][StorageCollateralized]{}", est.getStorageCollateralized()); |
|
|
|
|
opt.withGasLimit(est.getGasUsed()); |
|
|
|
|
opt.withStorageLimit(est.getStorageCollateralized()); |
|
|
|
|
hash = confluxExecutor.awardItemDataStr(opt, |
|
|
|
@ -443,7 +447,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
est = confluxExecutor.getEstimateData(cfx, new Address(owner), |
|
|
|
|
new Address(contract), AddressUtil.getHexAddress(owner), tokenIds, tokenURIs); |
|
|
|
|
//判断所需要的费用
|
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed())<0){ |
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed()) < 0) { |
|
|
|
|
return AjaxResult.error("代付余额不足"); |
|
|
|
|
} |
|
|
|
|
log.info("[--------------------->mintNft][GasUsed]{}", est.getGasUsed()); |
|
|
|
@ -465,7 +469,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
est = confluxExecutor.getEstimateTransferFrom(cfx, new Address(owner), |
|
|
|
|
new Address(contract), AddressUtil.getHexAddress(owner), AddressUtil.getHexAddress(checkArgs.getToUser()), nftCollection.getNftId()); |
|
|
|
|
//判断所需要的费用
|
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed())<0){ |
|
|
|
|
if (sponsoredBalanceForCollateral.compareTo(est.getGasUsed()) < 0) { |
|
|
|
|
return AjaxResult.error("代付余额不足"); |
|
|
|
|
} |
|
|
|
|
log.info("[--------------------->mintNft][GasUsed]{}", est.getGasUsed()); |
|
|
|
@ -527,7 +531,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
* @param contract |
|
|
|
|
* @param unitName |
|
|
|
|
*/ |
|
|
|
|
public void doPushData(String contract, String unitName) { |
|
|
|
|
public void doPushData(String contract, String unitName) { |
|
|
|
|
boolean isFalg = true; |
|
|
|
|
CollectConfig collect = (CollectConfig) redisUtils.get(contract); |
|
|
|
|
if (null == collect) { |
|
|
|
@ -540,7 +544,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.info("[dispatchHandlerEorre]{}",e); |
|
|
|
|
log.info("[dispatchHandlerEorre]{}", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//=======检查数据=======
|
|
|
|
@ -561,7 +565,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
cfx = Cfx.create(collect.getNode(), 3, 1000); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.info("[Create Cfx Exception}] {}",e); |
|
|
|
|
log.info("[Create Cfx Exception}] {}", e); |
|
|
|
|
} |
|
|
|
|
while (isFalg) { |
|
|
|
|
try { |
|
|
|
@ -569,7 +573,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
if (executeMakeUp(collect, contract,eventParams,gson,cfx)) { |
|
|
|
|
if (executeMakeUp(collect, contract, eventParams, gson, cfx)) { |
|
|
|
|
isFalg = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -582,7 +586,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
* @param eventParams |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean executeMakeUp(CollectConfig collect, String contract, List<EventParam> eventParams,Gson gson,Cfx cfx) { |
|
|
|
|
public synchronized boolean executeMakeUp(CollectConfig collect, String contract, List<EventParam> eventParams, Gson gson, Cfx cfx) { |
|
|
|
|
// log.info("[dispatchHandler]{}", "开始监听数据");
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(eventParams)) { |
|
|
|
@ -591,14 +595,14 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
} |
|
|
|
|
FilterMapVO vo = getFilter(eventParams); |
|
|
|
|
//获取数据高度
|
|
|
|
|
String keyNumber =nftConfig.getEnvironment()+ contract + "number"; |
|
|
|
|
String keyNumber = nftConfig.getEnvironment() + contract + "number"; |
|
|
|
|
long from = 0L; |
|
|
|
|
if (null == redisUtils.get(keyNumber)) { |
|
|
|
|
from = collect.getEpochNumber(); |
|
|
|
|
redisUtils.set(keyNumber,from); |
|
|
|
|
}else { |
|
|
|
|
redisUtils.set(keyNumber, from); |
|
|
|
|
} else { |
|
|
|
|
Object number = redisUtils.get(keyNumber); |
|
|
|
|
from= Long.valueOf(String.valueOf(number)); |
|
|
|
|
from = Long.valueOf(String.valueOf(number)); |
|
|
|
|
} |
|
|
|
|
// Invoke cfx method
|
|
|
|
|
BigInteger epoch = cfx.getEpochNumber().sendAndGet(); |
|
|
|
@ -626,10 +630,14 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
//log.info("[executeMakeUp][此区间暂无日志]:from:{} to:{}", from, to);
|
|
|
|
|
isSuccess = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (logList.size() > 0) { |
|
|
|
|
log.info("需要确认上链的数据:{}", logList.toArray()); |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
|
List<Integer> intList = new ArrayList<>(); |
|
|
|
|
String typeEvAddress=null; |
|
|
|
|
for (Log l : logList) { |
|
|
|
|
log.info("需要确认上链的gson数据:{}", gson.toJson(l)); |
|
|
|
|
// log.info("需要确认上链的gson数据:{}", gson.toJson(l));
|
|
|
|
|
//处理高度信息
|
|
|
|
|
String evAddress = l.getTopics().get(0); |
|
|
|
|
String tokenAddress = l.getAddress().getAddress(); |
|
|
|
@ -642,23 +650,41 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
log.info("[dispatchHandler][暂无符合条件的数据]"); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
boolean res; |
|
|
|
|
if (type == 20000) { |
|
|
|
|
typeEvAddress=evAddress; |
|
|
|
|
} |
|
|
|
|
//boolean res;
|
|
|
|
|
try { |
|
|
|
|
res = iHandlerStrategy.relayHandler(cfx, gson.toJson(l), type, contract); |
|
|
|
|
list.add(gson.toJson(l)); |
|
|
|
|
intList.add(type); |
|
|
|
|
//res = iHandlerStrategy.relayHandler(cfx, gson.toJson(l), type, contract);
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
isSuccess = false; |
|
|
|
|
log.info("[dispatchHandler][数据错误未分配]{}", l.getData()); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// if (res) {
|
|
|
|
|
// log.info("[dispatchHandler][分配成功]{}", evAddress);
|
|
|
|
|
// isSuccess = true;
|
|
|
|
|
// } else {
|
|
|
|
|
// log.info("[dispatchHandler][数据错误未分配]{}", l.getData());
|
|
|
|
|
// isSuccess = false;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
// map.put("cfx",cfx);
|
|
|
|
|
map.put("list", list); |
|
|
|
|
map.put("type", intList); |
|
|
|
|
map.put("contract", contract); |
|
|
|
|
boolean res = iHandlerStrategy.relayHandler(map); |
|
|
|
|
if (res) { |
|
|
|
|
log.info("[dispatchHandler][分配成功]{}", evAddress); |
|
|
|
|
log.info("[dispatchHandler][分配成功]{}", typeEvAddress); |
|
|
|
|
isSuccess = true; |
|
|
|
|
} else { |
|
|
|
|
log.info("[dispatchHandler][数据错误未分配]{}", l.getData()); |
|
|
|
|
isSuccess = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("更新确认链上数据失败:", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//分析数据拉取成功
|
|
|
|
@ -719,7 +745,7 @@ public class ConfluxServiceImpl implements ConfluxService {
|
|
|
|
|
*/ |
|
|
|
|
private synchronized List<BigInteger> autoincrement(String contract, List<String> list) { |
|
|
|
|
long totalNum = 0L; |
|
|
|
|
String key=nftConfig.getEnvironment()+contract+"autoinc"; |
|
|
|
|
String key = nftConfig.getEnvironment() + contract + "autoinc"; |
|
|
|
|
if (null == redisUtils.get(key)) { |
|
|
|
|
totalNum = nftCollectionService.queryTotalNum(contract); |
|
|
|
|
} else { |
|
|
|
|