Search in sources :

Example 16 with ValidateResult

use of io.nuls.core.validate.ValidateResult in project nuls by nuls-io.

the class HeaderFieldValidator method validate.

@Override
public ValidateResult validate(BlockHeader data) {
    ValidateResult result = ValidateResult.getSuccessResult();
    boolean failed = false;
    do {
        if (data.getHash() == null) {
            failed = true;
            break;
        }
        if (data.getHeight() < 0) {
            failed = true;
            break;
        }
        if (data.getMerkleHash() == null) {
            failed = true;
            break;
        }
        if (StringUtils.isBlank(data.getPackingAddress())) {
            failed = true;
            break;
        }
    } while (false);
    if (failed) {
        result = ValidateResult.getFailedResult(ERROR_MESSAGE);
    }
    return result;
}
Also used : ValidateResult(io.nuls.core.validate.ValidateResult)

Example 17 with ValidateResult

use of io.nuls.core.validate.ValidateResult in project nuls by nuls-io.

the class AgentCountValidator method validate.

@Override
public ValidateResult validate(RegisterAgentTransaction tx) {
    ValidateResult result = ValidateResult.getSuccessResult();
    Agent agent = tx.getTxData().getExtend();
    String agentName = agent.getAgentName();
    List<Consensus<Agent>> caList = consensusCacheManager.getCachedAgentList();
    if (caList != null) {
        for (Consensus<Agent> ca : caList) {
            if (ca.getHexHash().equals(tx.getTxData().getHexHash())) {
                continue;
            }
            if (ca.getAddress().equals(tx.getTxData().getAddress())) {
                return ValidateResult.getFailedResult("An address can only create one agent");
            }
            if (ca.getAddress().equals(agent.getPackingAddress())) {
                return ValidateResult.getFailedResult("The address can only create one agent");
            }
            if (agent.getPackingAddress().equals(ca.getAddress())) {
                return ValidateResult.getFailedResult("The packingAddress is an agentAddress");
            }
            if (agent.getPackingAddress().equals(ca.getExtend().getPackingAddress())) {
                return ValidateResult.getFailedResult("The packingAddress is busy!");
            }
            if (agentName.equals(ca.getExtend().getAgentName())) {
                return ValidateResult.getFailedResult("AgentName repetition!");
            }
        }
    }
    return result;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) ValidateResult(io.nuls.core.validate.ValidateResult) Consensus(io.nuls.consensus.entity.Consensus)

Example 18 with ValidateResult

use of io.nuls.core.validate.ValidateResult in project nuls by nuls-io.

the class UtxoLedgerServiceImpl method transfer.

private Result transfer(CoinTransferData coinData, String password, String remark) {
    TransferTransaction tx = null;
    try {
        tx = UtxoTransactionTool.getInstance().createTransferTx(coinData, password, remark);
        ValidateResult result = tx.verify();
        if (result.isFailed()) {
            throw new NulsException(result.getErrorCode());
        }
        byte[] txbytes = tx.serialize();
        TransferTransaction new_tx = new NulsByteBuffer(txbytes).readNulsData(new TransferTransaction());
        result = new_tx.verify();
        if (result.isFailed()) {
            throw new NulsException(result.getErrorCode());
        }
        TransactionEvent event = new TransactionEvent();
        event.setEventBody(tx);
        eventBroadcaster.broadcastAndCacheAysn(event, true);
    } catch (Exception e) {
        Log.error(e);
        return new Result(false, e.getMessage());
    }
    return new Result(true, "OK", tx.getHash().getDigestHex());
}
Also used : TransactionEvent(io.nuls.ledger.event.TransactionEvent) NulsException(io.nuls.core.exception.NulsException) ValidateResult(io.nuls.core.validate.ValidateResult) TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer) ValidateResult(io.nuls.core.validate.ValidateResult)

Aggregations

ValidateResult (io.nuls.core.validate.ValidateResult)18 NulsException (io.nuls.core.exception.NulsException)8 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)7 Transaction (io.nuls.core.chain.entity.Transaction)6 IOException (java.io.IOException)5 Block (io.nuls.core.chain.entity.Block)4 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)4 BlockRoundData (io.nuls.consensus.entity.block.BlockRoundData)3 CoinBaseTransaction (io.nuls.ledger.entity.tx.CoinBaseTransaction)3 TransactionEvent (io.nuls.ledger.event.TransactionEvent)3 Agent (io.nuls.consensus.entity.member.Agent)2 RedPunishTransaction (io.nuls.consensus.entity.tx.RedPunishTransaction)2 YellowPunishTransaction (io.nuls.consensus.entity.tx.YellowPunishTransaction)2 BlockHeader (io.nuls.core.chain.entity.BlockHeader)2 Result (io.nuls.core.chain.entity.Result)2 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)2 Account (io.nuls.account.entity.Account)1 Alias (io.nuls.account.entity.Alias)1 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)1 Consensus (io.nuls.consensus.entity.Consensus)1