Search in sources :

Example 21 with NulsRuntimeException

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());
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) NulsException(io.nuls.core.exception.NulsException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 22 with NulsRuntimeException

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;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 23 with NulsRuntimeException

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;
}
Also used : Account(io.nuls.account.entity.Account) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AccountService(io.nuls.account.service.intf.AccountService)

Example 24 with NulsRuntimeException

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;
}
Also used : LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) Account(io.nuls.account.entity.Account) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) AccountService(io.nuls.account.service.intf.AccountService)

Example 25 with NulsRuntimeException

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);
}
Also used : TransactionEvent(io.nuls.ledger.event.TransactionEvent) Transaction(io.nuls.core.chain.entity.Transaction) ValidateResult(io.nuls.core.validate.ValidateResult) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Aggregations

NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)64 NulsException (io.nuls.core.exception.NulsException)26 IOException (java.io.IOException)11 Transaction (io.nuls.core.chain.entity.Transaction)10 ArrayList (java.util.ArrayList)9 Account (io.nuls.account.entity.Account)7 AbstractNulsQueue (io.nuls.core.utils.queue.intf.AbstractNulsQueue)7 DbSession (io.nuls.db.transactional.annotation.DbSession)6 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)5 ValidateResult (io.nuls.core.validate.ValidateResult)4 Coin (io.nuls.ledger.entity.params.Coin)4 TransactionEvent (io.nuls.ledger.event.TransactionEvent)4 AccountService (io.nuls.account.service.intf.AccountService)3 Block (io.nuls.core.chain.entity.Block)3 AccountPo (io.nuls.db.entity.AccountPo)3 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)3 BlockHashResponse (io.nuls.consensus.entity.BlockHashResponse)2 RedPunishData (io.nuls.consensus.entity.RedPunishData)2 BestCorrectBlock (io.nuls.consensus.entity.block.BestCorrectBlock)2 Agent (io.nuls.consensus.entity.member.Agent)2