use of io.nuls.db.entity.AgentPo in project nuls by nuls-io.
the class RegisterAgentTxService method onCommit.
@Override
public void onCommit(RegisterAgentTransaction tx) throws NulsException {
manager.changeAgentStatusByHash(tx.getTxData().getHexHash(), ConsensusStatusEnum.WAITING);
Consensus<Agent> ca = tx.getTxData();
ca.getExtend().setStatus(ConsensusStatusEnum.WAITING.getCode());
AgentPo po = ConsensusTool.agentToPojo(ca);
delegateAccountService.save(po);
RegisterAgentNotice notice = new RegisterAgentNotice();
notice.setEventBody(tx);
NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
}
use of io.nuls.db.entity.AgentPo in project nuls by nuls-io.
the class ConsensusTool method agentToPojo.
public static AgentPo agentToPojo(Consensus<Agent> bean) {
if (null == bean) {
return null;
}
AgentPo po = new AgentPo();
po.setAgentAddress(bean.getAddress());
po.setId(bean.getHexHash());
po.setDeposit(bean.getExtend().getDeposit().getValue());
po.setStartTime(bean.getExtend().getStartTime());
po.setRemark(bean.getExtend().getIntroduction());
po.setPackingAddress(bean.getExtend().getPackingAddress());
po.setStatus(bean.getExtend().getStatus());
po.setAgentName(bean.getExtend().getAgentName());
po.setCommissionRate(bean.getExtend().getCommissionRate());
return po;
}
use of io.nuls.db.entity.AgentPo in project nuls by nuls-io.
the class PocConsensusResource method getAllAgentStatusList.
@GET
@Path("/agent/status")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getAllAgentStatusList() {
RpcResult rpcResult = RpcResult.getSuccess();
List<AgentPo> polist = agentDataService.getList();
if (null == polist || polist.isEmpty()) {
return rpcResult;
}
Map<String, Integer> statusMap = new HashMap<>();
for (AgentPo po : polist) {
statusMap.put(po.getAgentAddress(), po.getStatus());
}
return rpcResult.setData(statusMap);
}
use of io.nuls.db.entity.AgentPo in project nuls by nuls-io.
the class ExitConsensusTxService method onRollback.
@Override
public void onRollback(PocExitConsensusTransaction tx) throws NulsException {
Transaction joinTx = ledgerService.getTx(tx.getTxData());
if (joinTx.getType() == TransactionConstant.TX_TYPE_REGISTER_AGENT) {
RegisterAgentTransaction raTx = (RegisterAgentTransaction) joinTx;
Consensus<Agent> ca = raTx.getTxData();
ca.getExtend().setStatus(ConsensusStatusEnum.IN.getCode());
manager.cacheAgent(ca);
AgentPo agentPo = new AgentPo();
agentPo.setId(raTx.getTxData().getHexHash());
agentPo.setStatus(ConsensusStatusEnum.IN.getCode());
this.agentDataService.updateSelective(agentPo);
DepositPo dpo = new DepositPo();
dpo.setId(raTx.getTxData().getHexHash());
dpo.setStatus(ConsensusStatusEnum.IN.getCode());
this.depositDataService.updateSelectiveByAgentHash(dpo);
CancelConsensusNotice notice = new CancelConsensusNotice();
notice.setEventBody(tx);
NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
// cache delegates
Map<String, Object> params = new HashMap<>();
params.put("agentHash", raTx.getTxData().getHexHash());
List<DepositPo> polist = this.depositDataService.getList(params);
if (null == polist || polist.isEmpty()) {
return;
}
for (DepositPo po : polist) {
Consensus<Deposit> cd = ConsensusTool.fromPojo(po);
this.manager.cacheDeposit(cd);
}
this.ledgerService.unlockTxRollback(tx.getTxData().getDigestHex());
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("agentHash", ca.getHexHash());
List<DepositPo> poList = depositDataService.getList(paramsMap);
for (DepositPo po : poList) {
this.ledgerService.unlockTxRollback(po.getTxHash());
}
return;
}
PocJoinConsensusTransaction pjcTx = (PocJoinConsensusTransaction) joinTx;
Consensus<Deposit> cd = pjcTx.getTxData();
cd.getExtend().setStatus(ConsensusStatusEnum.IN.getCode());
manager.cacheDeposit(cd);
DepositPo dPo = this.depositDataService.get(cd.getHexHash());
if (dPo == null) {
dPo = ConsensusTool.depositToPojo(cd, tx.getHash().getDigestHex());
this.depositDataService.save(dPo);
}
StopConsensusNotice notice = new StopConsensusNotice();
notice.setEventBody(tx);
NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
this.ledgerService.unlockTxRollback(tx.getTxData().getDigestHex());
}
use of io.nuls.db.entity.AgentPo in project nuls by nuls-io.
the class JoinConsensusTxService method onCommit.
@Override
public void onCommit(PocJoinConsensusTransaction tx) throws NulsException {
manager.changeDepositStatus(tx.getTxData().getHexHash(), ConsensusStatusEnum.WAITING);
Consensus<Deposit> cd = tx.getTxData();
cd.getExtend().setTxHash(tx.getHash().getDigestHex());
cd.getExtend().setStatus(ConsensusStatusEnum.WAITING.getCode());
DepositPo po = ConsensusTool.depositToPojo(cd, tx.getHash().getDigestHex());
po.setBlockHeight(tx.getBlockHeight());
po.setTime(tx.getTime());
depositDataService.save(po);
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("agentHash", cd.getExtend().getAgentHash());
List<DepositPo> poList = depositDataService.getList(paramsMap);
long sum = 0L;
for (DepositPo depositPo : poList) {
sum += depositPo.getDeposit();
}
if (sum >= PocConsensusConstant.SUM_OF_DEPOSIT_OF_AGENT_LOWER_LIMIT.getValue()) {
manager.changeAgentStatusByHash(tx.getTxData().getExtend().getAgentHash(), ConsensusStatusEnum.IN);
manager.changeDepositStatusByAgentHash(tx.getTxData().getExtend().getAgentHash(), ConsensusStatusEnum.IN);
AgentPo daPo = this.accountDataService.get(cd.getExtend().getAgentHash());
if (null == daPo) {
throw new NulsRuntimeException(ErrorCode.DATA_ERROR, "the agent cannot find,agent hash:" + cd.getExtend().getAgentHash());
}
daPo.setStatus(ConsensusStatusEnum.IN.getCode());
this.accountDataService.updateSelective(daPo);
}
EntrustConsensusNotice notice = new EntrustConsensusNotice();
notice.setEventBody(tx);
NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
}
Aggregations