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;
}
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;
}
Aggregations