use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class AccountResource method alias.
@POST
@Path("/alias")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult alias(AccountParamForm form) {
if (!Address.validAddress(form.getAddress())) {
return RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
}
Result result = accountService.setAlias(form.getAddress(), form.getPassword(), form.getAlias());
RpcResult rpcResult = new RpcResult(result);
return rpcResult;
}
use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class AccountResource method lock.
@POST
@Path("/lock")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult lock(@QueryParam("address") String address, @QueryParam("password") String password, @QueryParam("amount") long amount, @QueryParam("remark") String remark, @QueryParam("unlockTime") Long unlockTime) {
Result lockResult = ledgerService.lock(address, password, Na.parseNuls(amount), unlockTime, remark);
RpcResult result;
if (lockResult.isSuccess()) {
result = RpcResult.getSuccess();
} else {
result = RpcResult.getFailed(lockResult.getMessage());
}
result.setData(lockResult.getObject());
return result;
}
use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class WalletResouce method transfer.
@POST
@Path("/transfer")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult transfer(TransferForm form) {
AssertUtil.canNotEmpty(form.getToAddress());
AssertUtil.canNotEmpty(form.getAmount());
Result result = this.ledgerService.transfer(form.getAddress(), form.getPassword(), form.getToAddress(), Na.valueOf(form.getAmount()), form.getRemark());
return new RpcResult(result);
}
use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class BlockBatchDownloadUtils method verify.
private synchronized void verify() {
boolean done = true;
if (nodeStatusMap.isEmpty()) {
working = false;
return;
}
for (NodeDownloadingStatus status : nodeStatusMap.values()) {
if (!done) {
break;
}
done = status.finished();
if (!done && status.getUpdateTime() < (TimeService.currentTimeMillis() - DOWNLOAD_IDLE_TIME_OUT)) {
nodeStatusMap.remove(status.getNodeId());
try {
failedExecute(status);
} catch (InterruptedException e) {
Log.error(e);
}
}
}
if (!done) {
return;
}
Result result;
try {
result = checkHash();
} catch (InterruptedException e) {
Log.error(e);
return;
}
if (null == result || result.isFailed()) {
return;
}
for (long i = currentRound.getStart(); i <= currentRound.getEnd(); i++) {
Block block = blockMap.get(i);
if (null == block) {
// todo
Log.error("cache block is null");
break;
}
ValidateResult result1 = block.verify();
if (result1.isFailed() && result1.getErrorCode() != ErrorCode.ORPHAN_TX) {
if (null != result1.getMessage()) {
Log.info(result1.getMessage());
}
try {
failedExecute(block.getHeader().getHeight());
} catch (InterruptedException e) {
Log.error(e);
}
return;
}
blockManager.addBlock(block, false, null);
receivedTxCacheManager.removeTx(block.getTxHashList());
confirmingTxCacheManager.putTxList(block.getTxs());
}
finished();
}
use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class AccountServiceImpl method exportAccounts.
private Result exportAccounts(List<Account> accounts, File backupFile) {
FileOutputStream fos = null;
List<TransactionPo> txList;
TransactionPo tx;
try {
fos = new FileOutputStream(backupFile);
// account length
fos.write(new VarInt(accounts.size()).encode());
} catch (Exception e) {
Log.error(e);
return new Result(false, "export failed");
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
return new Result(true, "OK");
}
Aggregations