Search in sources :

Example 1 with JoinConsensusParam

use of io.nuls.consensus.entity.params.JoinConsensusParam in project nuls by nuls-io.

the class PocConsensusServiceImpl method startConsensus.

@Override
public Transaction startConsensus(String address, String password, Map<String, Object> paramsMap) throws NulsException {
    Account account = this.accountService.getAccount(address);
    if (null == account) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "The account is not exist,address:" + address);
    }
    if (paramsMap == null || paramsMap.size() < 2) {
        throw new NulsRuntimeException(ErrorCode.NULL_PARAMETER);
    }
    if (!account.validatePassword(password)) {
        throw new NulsRuntimeException(ErrorCode.PASSWORD_IS_WRONG);
    }
    JoinConsensusParam params = new JoinConsensusParam(paramsMap);
    if (StringUtils.isNotBlank(params.getIntroduction())) {
        Agent agent = new Agent();
        agent.setPackingAddress(params.getPackingAddress());
        agent.setDeposit(Na.valueOf(params.getDeposit()));
        agent.setIntroduction(params.getIntroduction());
        agent.setSeed(params.isSeed());
        agent.setCommissionRate(params.getCommissionRate());
        agent.setAgentName(params.getAgentName());
        try {
            return this.registerAgent(agent, account, password);
        } catch (IOException e) {
            throw new NulsRuntimeException(e);
        }
    }
    try {
        return this.joinTheConsensus(account, password, params.getDeposit(), params.getAgentHash());
    } catch (IOException e) {
        throw new NulsRuntimeException(e);
    }
}
Also used : Account(io.nuls.account.entity.Account) Agent(io.nuls.consensus.entity.member.Agent) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) IOException(java.io.IOException) JoinConsensusParam(io.nuls.consensus.entity.params.JoinConsensusParam)

Aggregations

Account (io.nuls.account.entity.Account)1 Agent (io.nuls.consensus.entity.member.Agent)1 JoinConsensusParam (io.nuls.consensus.entity.params.JoinConsensusParam)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 IOException (java.io.IOException)1