Search in sources :

Example 6 with Result

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

Example 7 with Result

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

Example 8 with 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);
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) RpcResult(io.nuls.rpc.entity.RpcResult) Result(io.nuls.core.chain.entity.Result)

Example 9 with 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();
}
Also used : NodeDownloadingStatus(io.nuls.consensus.entity.NodeDownloadingStatus) ValidateResult(io.nuls.core.validate.ValidateResult) Block(io.nuls.core.chain.entity.Block) ValidateResult(io.nuls.core.validate.ValidateResult) Result(io.nuls.core.chain.entity.Result)

Example 10 with Result

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");
}
Also used : FileOutputStream(java.io.FileOutputStream) TransactionPo(io.nuls.db.entity.TransactionPo) IOException(java.io.IOException) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) ValidateResult(io.nuls.core.validate.ValidateResult) Result(io.nuls.core.chain.entity.Result)

Aggregations

Result (io.nuls.core.chain.entity.Result)19 ValidateResult (io.nuls.core.validate.ValidateResult)12 NulsException (io.nuls.core.exception.NulsException)10 Account (io.nuls.account.entity.Account)9 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)7 IOException (java.io.IOException)7 AccountPo (io.nuls.db.entity.AccountPo)5 RpcResult (io.nuls.rpc.entity.RpcResult)4 DbSession (io.nuls.db.transactional.annotation.DbSession)3 FileOutputStream (java.io.FileOutputStream)2 Alias (io.nuls.account.entity.Alias)1 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)1 NodeDownloadingStatus (io.nuls.consensus.entity.NodeDownloadingStatus)1 Block (io.nuls.core.chain.entity.Block)1 AliasPo (io.nuls.db.entity.AliasPo)1 TransactionPo (io.nuls.db.entity.TransactionPo)1 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)1 TransactionEvent (io.nuls.ledger.event.TransactionEvent)1 List (java.util.List)1