use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class BlockManager method appravalBlock.
private void appravalBlock(Block block) {
for (int i = 0; i < block.getHeader().getTxCount(); i++) {
Transaction tx = block.getTxs().get(i);
tx.setBlockHeight(block.getHeader().getHeight());
tx.setIndex(i);
tx.setIndex(i);
if (tx.getStatus() == null || tx.getStatus() == TxStatusEnum.CACHED) {
try {
this.ledgerService.approvalTx(tx);
confirmingTxCacheManager.putTx(tx);
} catch (NulsException e) {
rollbackTxList(block.getTxs(), 0, i);
Log.error(e);
throw new NulsRuntimeException(e);
}
}
}
txCacheManager.removeTx(block.getTxHashList());
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class GetTxGroupHandler method getTxList.
private List<Transaction> getTxList(Block block, List<NulsDigestData> txHashList) {
List<Transaction> txList = new ArrayList<>();
Map<String, Integer> allTxMap = new HashMap<>();
for (int i = 0; i < block.getHeader().getTxCount(); i++) {
Transaction tx = block.getTxs().get(i);
allTxMap.put(tx.getHash().getDigestHex(), i);
}
for (NulsDigestData hash : txHashList) {
txList.add(block.getTxs().get(allTxMap.get(hash.getDigestHex())));
}
if (txList.size() != txHashList.size()) {
throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
}
return txList;
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class UtxoTransactionTool method createTransferTx.
public TransferTransaction createTransferTx(CoinTransferData transferData, String password, String remark) throws Exception {
if (transferData.getFrom().isEmpty()) {
throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
}
TransferTransaction tx = new TransferTransaction(transferData, password);
if (StringUtils.isNotBlank(remark)) {
tx.setRemark(remark.getBytes(NulsContext.DEFAULT_ENCODING));
}
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
AccountService accountService = getAccountService();
Account account = accountService.getAccount(transferData.getFrom().get(0));
tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
return tx;
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class UtxoTransactionTool method createLockNulsTx.
public LockNulsTransaction createLockNulsTx(CoinTransferData transferData, String password, String remark) throws Exception {
LockNulsTransaction tx = new LockNulsTransaction(transferData, password);
if (StringUtils.isNotBlank(remark)) {
tx.setRemark(remark.getBytes(NulsContext.DEFAULT_ENCODING));
}
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
AccountService accountService = getAccountService();
if (transferData.getFrom().isEmpty()) {
throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
}
Account account = accountService.getAccount(transferData.getFrom().get(0));
tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
return tx;
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class TransactionResource method forwardTransaction.
@POST
@Produces(MediaType.APPLICATION_JSON)
public RpcResult forwardTransaction(TxForm form) {
Transaction tx = null;
try {
tx = form.getTx();
} catch (Exception e) {
Log.error(e);
}
if (tx == null) {
throw new NulsRuntimeException(ErrorCode.NULL_PARAMETER);
}
ValidateResult result = tx.verify();
if (result.isFailed() && ErrorCode.ORPHAN_TX != result.getErrorCode()) {
return RpcResult.getFailed(ErrorCode.DATA_ERROR);
}
TransactionEvent event = new TransactionEvent();
event.setEventBody(tx);
List<String> list = eventBroadcaster.broadcastAndCache(event, true);
return RpcResult.getSuccess().setData(list);
}
Aggregations