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();
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations