10 files modified
1 files added
| | |
| | | |
| | | @Override |
| | | public String transferBaseToken(String address, BigDecimal amount) { |
| | | // String gas = getGas(); |
| | | String gas ="5"; |
| | | String gas = getGas(); |
| | | // String gas ="5"; |
| | | try { |
| | | Credentials credentials = Credentials.create(privateKey); |
| | | |
| | |
| | | DappFundFlowEntity selectInfoById(@Param("id")Long id); |
| | | |
| | | int updateStatusById(@Param("status")int status, @Param("id")Long id); |
| | | |
| | | DappFundFlowEntity selectByStateAndVersionAndFromHashLimitOne(@Param("status")int withdrawStatusAgree, @Param("version")int withdrawStatusAgree1); |
| | | } |
| | |
| | | void bnbTransfer(Long id); |
| | | //代理升级 |
| | | void agentUp(Long id); |
| | | |
| | | void bnbTransferTest(Long id); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void bnbTransferTest(Long id) { |
| | | DappFundFlowEntity dappFundFlow = dappFundFlowDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlow)){ |
| | | return; |
| | | } |
| | | //金额 |
| | | BigDecimal amount = dappFundFlow.getAmount(); |
| | | //目标地址 |
| | | String address = dappFundFlow.getAddress(); |
| | | String hash = ChainService.getInstance(ChainEnum.BNB.name()).transferBaseToken(address, amount); |
| | | if(StrUtil.isEmpty(hash)){ |
| | | return; |
| | | } |
| | | log.info("{},{}",id,hash); |
| | | dappFundFlow.setFromHash(hash); |
| | | dappFundFlowDao.updateById(dappFundFlow); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String refererIds = "1,2,3,4,5," + |
| | | "6,7,8,9,10," + |
| New file |
| | |
| | | package cc.mrbird.febs.job; |
| | | |
| | | import cc.mrbird.febs.dapp.entity.DappFundFlowEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "system", name = "online-transfer", havingValue = "true") |
| | | public class BnbTransferJob{ |
| | | /** |
| | | * 搜索还未发生转账操作,但是记录已经更新没有产生HASH值的流水记录,并发起转账操作 |
| | | */ |
| | | @Autowired |
| | | private DappFundFlowDao dappFundFlowDao; |
| | | @Autowired |
| | | private ChainProducer chainProducer; |
| | | |
| | | @Scheduled(cron = "0/3 * * * * ? ") |
| | | public void BnbTransferAgain() { |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectByStateAndVersionAndFromHashLimitOne(2,2); |
| | | if(ObjectUtil.isNotEmpty(dappFundFlowEntity)){ |
| | | chainProducer.sendBnbTransferTestMsg(dappFundFlowEntity.getId()); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | **/ |
| | | public class QueueConstants { |
| | | |
| | | public static final String QUEUE_BNB_TRANSFER_TEST = "queue_bnb_agent_up_test"; |
| | | public static final String QUEUE_BNB_AGENT_UP = "queue_bnb_agent_up"; |
| | | public static final String QUEUE_BNB_TRANSFER = "queue_bnb_transfer"; |
| | | public static final String QUEUE_MEMBER_OUT = "queue_bnb_member_out"; |
| | |
| | | @Getter |
| | | public enum QueueEnum { |
| | | //代理升级 |
| | | BNB_TRANSFER_TEST("exchange_bnb_agent_up_test", "route_key_bnb_agent_up_test", "queue_bnb_agent_up_test"), |
| | | //代理升级 |
| | | BNB_AGENT_UP("exchange_bnb_agent_up", "route_key_bnb_agent_up", "queue_bnb_agent_up"), |
| | | //转账拨币 |
| | | BNB_TRANSFER("exchange_bnb_transfer", "route_key_bnb_transfer", "queue_bnb_transfer"), |
| | |
| | | return BindingBuilder.bind(agentUpQueue()).to(agentUpExchange()).with(QueueEnum.BNB_AGENT_UP.getRoute()); |
| | | } |
| | | // === 代理升级 end === |
| | | |
| | | |
| | | |
| | | // === 消息测试 start === |
| | | @Bean |
| | | public DirectExchange bnbTransferTestExchange() { |
| | | return new DirectExchange(QueueEnum.BNB_TRANSFER_TEST.getExchange()); |
| | | } |
| | | |
| | | @Bean |
| | | public Queue bnbTransferTestQueue() { |
| | | return new Queue(QueueEnum.BNB_TRANSFER_TEST.getQueue()); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding bnbTransferTestBind() { |
| | | return BindingBuilder.bind(bnbTransferTestQueue()).to(bnbTransferTestExchange()).with(QueueEnum.BNB_TRANSFER_TEST.getRoute()); |
| | | } |
| | | // === 消息测试 end === |
| | | } |
| | |
| | | dappSystemService.bnbTransfer(id); |
| | | } |
| | | |
| | | /**转账拨币 |
| | | * @param id |
| | | */ |
| | | @RabbitListener(queues = QueueConstants.QUEUE_BNB_TRANSFER_TEST) |
| | | public void bnbTransferTest(Long id) { |
| | | log.info("消费转账拨币:{}", id); |
| | | dappSystemService.bnbTransferTest(id); |
| | | } |
| | | |
| | | /**代理升级 |
| | | * @param id |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 转账拨币 |
| | | */ |
| | | public void sendBnbTransferTestMsg(Long id) { |
| | | log.info("转账拨币:{}", id); |
| | | CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); |
| | | rabbitTemplate.convertAndSend(QueueEnum.BNB_TRANSFER_TEST.getExchange(), QueueEnum.BNB_TRANSFER_TEST.getRoute(), id, correlationData); |
| | | } |
| | | |
| | | /** |
| | | * 代理升级 |
| | | */ |
| | | public void sendAgentUpMsg(Long id) { |
| | |
| | | and version = 1 |
| | | and status = 1 |
| | | </update> |
| | | |
| | | <select id="selectByStateAndVersionAndFromHashLimitOne" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity"> |
| | | select * from dapp_fund_flow |
| | | where status = #{status} |
| | | and version = #{version} |
| | | and from_hash is null |
| | | ORDER BY |
| | | id ASC |
| | | LIMIT 1 |
| | | </select> |
| | | </mapper> |