Search in sources :

Example 1 with ConsensusDepositImpl

use of io.nuls.consensus.entity.ConsensusDepositImpl in project nuls by nuls-io.

the class PocConsensusServiceImpl method joinTheConsensus.

private Transaction joinTheConsensus(Account account, String password, long amount, String agentHash) throws IOException, NulsException {
    AssertUtil.canNotEmpty(account);
    AssertUtil.canNotEmpty(password);
    if (amount < PocConsensusConstant.ENTRUSTER_DEPOSIT_LOWER_LIMIT.getValue()) {
        throw new NulsRuntimeException(ErrorCode.NULL_PARAMETER);
    }
    AssertUtil.canNotEmpty(agentHash);
    TransactionEvent event = new TransactionEvent();
    Consensus<Deposit> ca = new ConsensusDepositImpl();
    ca.setAddress(account.getAddress().toString());
    Deposit deposit = new Deposit();
    deposit.setAgentHash(agentHash);
    deposit.setDeposit(Na.valueOf(amount));
    deposit.setStartTime(TimeService.currentTimeMillis());
    ca.setExtend(deposit);
    CoinTransferData data = new CoinTransferData(OperationType.LOCK, this.ledgerService.getTxFee(TransactionConstant.TX_TYPE_JOIN_CONSENSUS));
    data.setTotalNa(deposit.getDeposit());
    data.addFrom(account.getAddress().toString());
    Coin coin = new Coin();
    coin.setUnlockHeight(0);
    coin.setUnlockTime(0);
    coin.setNa(deposit.getDeposit());
    data.addTo(account.getAddress().toString(), coin);
    PocJoinConsensusTransaction tx = null;
    try {
        tx = new PocJoinConsensusTransaction(data, password);
    } catch (NulsException e) {
        throw new NulsRuntimeException(e);
    }
    tx.setTime(TimeService.currentTimeMillis());
    tx.setTxData(ca);
    tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
    tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
    tx.verifyWithException();
    event.setEventBody(tx);
    List<String> nodeList = eventBroadcaster.broadcastAndCache(event, true);
    if (null == nodeList || nodeList.isEmpty()) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "broadcast transaction failed!");
    }
    return tx;
}
Also used : Deposit(io.nuls.consensus.entity.member.Deposit) Coin(io.nuls.ledger.entity.params.Coin) TransactionEvent(io.nuls.ledger.event.TransactionEvent) CoinTransferData(io.nuls.ledger.entity.params.CoinTransferData) NulsException(io.nuls.core.exception.NulsException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) PocJoinConsensusTransaction(io.nuls.consensus.entity.tx.PocJoinConsensusTransaction) ConsensusDepositImpl(io.nuls.consensus.entity.ConsensusDepositImpl)

Example 2 with ConsensusDepositImpl

use of io.nuls.consensus.entity.ConsensusDepositImpl in project nuls by nuls-io.

the class ConsensusTool method fromPojo.

public static Consensus<Deposit> fromPojo(DepositPo po) {
    if (null == po) {
        return null;
    }
    Consensus<Deposit> ca = new ConsensusDepositImpl();
    ca.setAddress(po.getAddress());
    Deposit deposit = new Deposit();
    deposit.setAgentHash(po.getAgentHash());
    deposit.setDeposit(Na.valueOf(po.getDeposit()));
    deposit.setStartTime(po.getTime());
    deposit.setTxHash(po.getTxHash());
    ca.setHash(NulsDigestData.fromDigestHex(po.getId()));
    ca.setExtend(deposit);
    return ca;
}
Also used : Deposit(io.nuls.consensus.entity.member.Deposit) ConsensusDepositImpl(io.nuls.consensus.entity.ConsensusDepositImpl)

Aggregations

ConsensusDepositImpl (io.nuls.consensus.entity.ConsensusDepositImpl)2 Deposit (io.nuls.consensus.entity.member.Deposit)2 PocJoinConsensusTransaction (io.nuls.consensus.entity.tx.PocJoinConsensusTransaction)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