use of io.nuls.ledger.entity.tx.AbstractCoinTransaction in project nuls by nuls-io.
the class PocConsensusServiceImpl method stopConsensus.
@Override
public Transaction stopConsensus(String address, String password, Map<String, Object> paramsMap) throws NulsException, IOException {
AbstractCoinTransaction joinTx = null;
if (null != paramsMap && StringUtils.isNotBlank((String) paramsMap.get("txHash"))) {
PocJoinConsensusTransaction tx = (PocJoinConsensusTransaction) ledgerService.getTx(NulsDigestData.fromDigestHex((String) paramsMap.get("txHash")));
joinTx = tx;
} else {
try {
List<Transaction> txlist = this.ledgerService.getTxList(address, TransactionConstant.TX_TYPE_REGISTER_AGENT);
if (null != txlist || !txlist.isEmpty()) {
joinTx = (AbstractCoinTransaction) txlist.get(0);
}
} catch (Exception e) {
Log.error(e);
}
}
if (null == joinTx) {
throw new NulsRuntimeException(ErrorCode.FAILED, "The related transaction is not exist!");
}
Account account = this.accountService.getAccount(address);
if (null == account) {
throw new NulsRuntimeException(ErrorCode.ACCOUNT_NOT_EXIST, "address:" + address.toString());
}
if (!account.validatePassword(password)) {
throw new NulsRuntimeException(ErrorCode.PASSWORD_IS_WRONG);
}
TransactionEvent event = new TransactionEvent();
CoinTransferData coinTransferData = new CoinTransferData(OperationType.UNLOCK, this.ledgerService.getTxFee(TransactionConstant.TX_TYPE_EXIT_CONSENSUS));
coinTransferData.setTotalNa(Na.ZERO);
PocExitConsensusTransaction tx = new PocExitConsensusTransaction(coinTransferData, password);
tx.setTxData(joinTx.getHash());
try {
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
} catch (IOException e) {
Log.error(e);
throw new NulsRuntimeException(ErrorCode.HASH_ERROR, e);
}
tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
event.setEventBody(tx);
eventBroadcaster.broadcastHashAndCache(event, true);
return tx;
}
use of io.nuls.ledger.entity.tx.AbstractCoinTransaction in project nuls by nuls-io.
the class UtxoTransferTool method transferCoinData.
private static void transferCoinData(Transaction tx, List<UtxoInputPo> inputPoList, List<UtxoOutputPo> outputPoList) {
if (tx instanceof AbstractCoinTransaction) {
AbstractCoinTransaction coinTx = (AbstractCoinTransaction) tx;
UtxoData utxoData = new UtxoData();
Set<String> addressSet = new HashSet<>();
for (UtxoInputPo inputPo : inputPoList) {
utxoData.getInputs().add(toInput(inputPo));
addressSet.add(inputPo.getFromOutPut().getAddress());
}
for (int i = 0; i < outputPoList.size(); i++) {
UtxoOutputPo outputPo = outputPoList.get(i);
utxoData.getOutputs().add(toOutput(outputPo));
}
coinTx.setCoinData(utxoData);
}
}
Aggregations