use of io.nuls.consensus.entity.ConsensusAgentImpl in project nuls by nuls-io.
the class ConsensusMeetingRunner method getDefaultSeedList.
private List<Consensus<Agent>> getDefaultSeedList() throws IOException {
List<Consensus<Agent>> seedList = new ArrayList<>();
if (consensusManager.getSeedNodeList() == null) {
return seedList;
}
for (String address : consensusManager.getSeedNodeList()) {
Consensus<Agent> member = new ConsensusAgentImpl();
member.setAddress(address);
Agent agent = new Agent();
agent.setPackingAddress(address);
agent.setStartTime(0);
agent.setIntroduction("seed");
agent.setCommissionRate(0);
agent.setStatus(ConsensusStatusEnum.IN.getCode());
agent.setSeed(true);
agent.setDeposit(Na.ZERO);
member.setExtend(agent);
seedList.add(member);
}
return seedList;
}
use of io.nuls.consensus.entity.ConsensusAgentImpl in project nuls by nuls-io.
the class ConsensusTool method fromPojo.
public static Consensus<Agent> fromPojo(AgentPo po) {
if (null == po) {
return null;
}
Agent agent = new Agent();
agent.setStatus(ConsensusStatusEnum.WAITING.getCode());
agent.setDeposit(Na.valueOf(po.getDeposit()));
agent.setCommissionRate(po.getCommissionRate());
agent.setPackingAddress(po.getPackingAddress());
agent.setIntroduction(po.getRemark());
agent.setStartTime(po.getStartTime());
agent.setStatus(po.getStatus());
agent.setAgentName(po.getAgentName());
Consensus<Agent> ca = new ConsensusAgentImpl();
ca.setAddress(po.getAgentAddress());
ca.setHash(NulsDigestData.fromDigestHex(po.getId()));
ca.setExtend(agent);
return ca;
}
use of io.nuls.consensus.entity.ConsensusAgentImpl in project nuls by nuls-io.
the class PocConsensusServiceImpl method registerAgent.
private Transaction registerAgent(Agent agent, Account account, String password) throws IOException, NulsException {
TransactionEvent event = new TransactionEvent();
CoinTransferData data = new CoinTransferData(OperationType.LOCK, this.ledgerService.getTxFee(TransactionConstant.TX_TYPE_REGISTER_AGENT));
data.setTotalNa(agent.getDeposit());
data.addFrom(account.getAddress().toString());
Coin coin = new Coin();
coin.setUnlockHeight(0);
coin.setUnlockTime(0);
coin.setNa(agent.getDeposit());
data.addTo(account.getAddress().toString(), coin);
RegisterAgentTransaction tx = null;
try {
tx = new RegisterAgentTransaction(data, password);
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
Consensus<Agent> con = new ConsensusAgentImpl();
con.setAddress(account.getAddress().toString());
agent.setStartTime(TimeService.currentTimeMillis());
con.setExtend(agent);
tx.setTxData(con);
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
tx.verifyWithException();
event.setEventBody(tx);
List<String> nodeList = eventBroadcaster.broadcastHashAndCache(event, true);
if (null == nodeList || nodeList.isEmpty()) {
throw new NulsRuntimeException(ErrorCode.FAILED, "broadcast transaction failed!");
}
return tx;
}
Aggregations