Search in sources :

Example 51 with Result

use of io.nuls.kernel.model.Result in project nuls by nuls-io.

the class UtxoResource method getUtxoByAddressAndLimit.

@GET
@Path("/limit/{address}/{limit}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "根据address和limit查询UTXO")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = AccountUtxoDto.class) })
public RpcClientResult getUtxoByAddressAndLimit(@ApiParam(name = "address", value = "地址", required = true) @PathParam("address") String address, @ApiParam(name = "limit", value = "数量", required = true) @PathParam("limit") Integer limit) {
    if (StringUtils.isBlank(address) || limit == null) {
        return Result.getFailed(LedgerErrorCode.NULL_PARAMETER).toRpcClientResult();
    }
    if (!AddressTool.validAddress(address)) {
        return Result.getFailed(LedgerErrorCode.PARAMETER_ERROR).toRpcClientResult();
    }
    Result result = null;
    try {
        List<Coin> coinList = getAllUtxoByAddress(address);
        int limitValue = limit.intValue();
        boolean isLoadAll = (limitValue == 0);
        AccountUtxoDto accountUtxoDto = new AccountUtxoDto();
        List<UtxoDto> list = new LinkedList<>();
        int i = 0;
        for (Coin coin : coinList) {
            if (!coin.usable()) {
                continue;
            }
            if (coin.getNa().equals(Na.ZERO)) {
                continue;
            }
            if (!isLoadAll) {
                if (i >= limitValue) {
                    break;
                }
                i++;
            }
            list.add(new UtxoDto(coin));
        }
        accountUtxoDto.setUtxoDtoList(list);
        result = Result.getSuccess().setData(accountUtxoDto);
        return result.toRpcClientResult();
    } catch (Exception e) {
        Log.error(e);
        result = Result.getFailed(LedgerErrorCode.SYS_UNKOWN_EXCEPTION);
        return result.toRpcClientResult();
    }
}
Also used : Coin(io.nuls.kernel.model.Coin) NulsException(io.nuls.kernel.exception.NulsException) RpcClientResult(io.nuls.kernel.model.RpcClientResult) Result(io.nuls.kernel.model.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 52 with Result

use of io.nuls.kernel.model.Result in project nuls by nuls-io.

the class TxProcessTask method processTx.

private boolean processTx(Transaction tx, boolean isOrphanTx) {
    try {
        Result result = tx.verify();
        if (result.isFailed()) {
            return false;
        }
        Transaction tempTx = ledgerService.getTx(tx.getHash());
        if (tempTx != null) {
            return isOrphanTx;
        }
        ValidateResult validateResult = ledgerService.verifyCoinData(tx, temporaryToMap, temporaryFromSet);
        if (validateResult.isSuccess()) {
            pool.add(tx, false);
            List<Coin> fromCoins = tx.getCoinData().getFrom();
            for (Coin coin : fromCoins) {
                String key = LedgerUtil.asString(coin.getOwner());
                temporaryFromSet.remove(key);
                temporaryToMap.remove(key);
            }
            // count++;
            transactionCacheStorageService.putTx(tx);
            transactionService.forwardTx(tx, null);
            return true;
        } else if (validateResult.getErrorCode().equals(TransactionErrorCode.ORPHAN_TX) && !isOrphanTx) {
            processOrphanTx(tx);
        } else if (isOrphanTx) {
            return tx.getTime() < (TimeService.currentTimeMillis() - 3600000L);
        }
    } catch (Exception e) {
        Log.error(e);
    }
    return false;
}
Also used : Coin(io.nuls.kernel.model.Coin) Transaction(io.nuls.kernel.model.Transaction) ValidateResult(io.nuls.kernel.validate.ValidateResult) NulsException(io.nuls.kernel.exception.NulsException) ValidateResult(io.nuls.kernel.validate.ValidateResult) Result(io.nuls.kernel.model.Result)

Example 53 with Result

use of io.nuls.kernel.model.Result in project nuls by nuls-io.

the class CreateAgentTxProcessor method onCommit.

@Override
public Result onCommit(CreateAgentTransaction tx, Object secondaryData) {
    Agent agent = tx.getTxData();
    BlockHeader header = (BlockHeader) secondaryData;
    agent.setTxHash(tx.getHash());
    agent.setBlockHeight(header.getHeight());
    agent.setTime(tx.getTime());
    AgentPo agentPo = PoConvertUtil.agentToPo(agent);
    boolean success = agentStorageService.save(agentPo);
    return new Result(success, null);
}
Also used : Agent(io.nuls.consensus.poc.protocol.entity.Agent) BlockHeader(io.nuls.kernel.model.BlockHeader) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo) ValidateResult(io.nuls.kernel.validate.ValidateResult) Result(io.nuls.kernel.model.Result)

Example 54 with Result

use of io.nuls.kernel.model.Result in project nuls by nuls-io.

the class CreateAgentTxProcessor method onRollback.

@Override
public Result onRollback(CreateAgentTransaction tx, Object secondaryData) {
    Agent agent = tx.getTxData();
    agent.setTxHash(tx.getHash());
    boolean success = agentStorageService.delete(agent.getTxHash());
    return new Result(success, null);
}
Also used : Agent(io.nuls.consensus.poc.protocol.entity.Agent) ValidateResult(io.nuls.kernel.validate.ValidateResult) Result(io.nuls.kernel.model.Result)

Example 55 with Result

use of io.nuls.kernel.model.Result in project nuls by nuls-io.

the class ConsensusBlockServiceImpl method getBlock.

@Override
public Result<Block> getBlock(NulsDigestData hash) {
    Result result = new Result(true, null);
    Block block = new Block();
    BlockHeader blockHeader = new BlockHeader();
    blockHeader.setHash(hash);
    block.setHeader(blockHeader);
    block.setTxs(new ArrayList<>());
    result.setData(block);
    return result;
}
Also used : Block(io.nuls.kernel.model.Block) SmallBlock(io.nuls.protocol.model.SmallBlock) BlockHeader(io.nuls.kernel.model.BlockHeader) Result(io.nuls.kernel.model.Result)

Aggregations

Result (io.nuls.kernel.model.Result)70 NulsException (io.nuls.kernel.exception.NulsException)16 IOException (java.io.IOException)15 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)12 ValidateResult (io.nuls.kernel.validate.ValidateResult)11 AccountPo (io.nuls.account.storage.po.AccountPo)7 RpcClientResult (io.nuls.kernel.model.RpcClientResult)7 ArrayList (java.util.ArrayList)7 Account (io.nuls.account.model.Account)6 NulsDigestData (io.nuls.kernel.model.NulsDigestData)5 Test (org.junit.Test)5 CryptoException (io.nuls.core.tools.crypto.Exception.CryptoException)4 BatchOperation (io.nuls.db.service.BatchOperation)4 Address (io.nuls.kernel.model.Address)4 Block (io.nuls.kernel.model.Block)4 BlockHeader (io.nuls.kernel.model.BlockHeader)4 Transaction (io.nuls.kernel.model.Transaction)4 Node (io.nuls.network.model.Node)4 NotFound (io.nuls.protocol.model.NotFound)4 ApiOperation (io.swagger.annotations.ApiOperation)4