Search in sources :

Example 1 with ConsensusAgentImpl

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;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) ConsensusAgentImpl(io.nuls.consensus.entity.ConsensusAgentImpl) Consensus(io.nuls.consensus.entity.Consensus)

Example 2 with ConsensusAgentImpl

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;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) ConsensusAgentImpl(io.nuls.consensus.entity.ConsensusAgentImpl)

Example 3 with ConsensusAgentImpl

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;
}
Also used : Coin(io.nuls.ledger.entity.params.Coin) Agent(io.nuls.consensus.entity.member.Agent) TransactionEvent(io.nuls.ledger.event.TransactionEvent) RegisterAgentTransaction(io.nuls.consensus.entity.tx.RegisterAgentTransaction) CoinTransferData(io.nuls.ledger.entity.params.CoinTransferData) ConsensusAgentImpl(io.nuls.consensus.entity.ConsensusAgentImpl) NulsException(io.nuls.core.exception.NulsException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Aggregations

ConsensusAgentImpl (io.nuls.consensus.entity.ConsensusAgentImpl)3 Agent (io.nuls.consensus.entity.member.Agent)3 Consensus (io.nuls.consensus.entity.Consensus)1 RegisterAgentTransaction (io.nuls.consensus.entity.tx.RegisterAgentTransaction)1 NulsException (io.nuls.core.exception.NulsException)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 Coin (io.nuls.ledger.entity.params.Coin)1 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)1 TransactionEvent (io.nuls.ledger.event.TransactionEvent)1