Search in sources :

Example 36 with Result

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

the class UnconfiredmTransactionStorageImpl method loadAllUnconfirmedList.

@Override
public Result<List<Transaction>> loadAllUnconfirmedList() {
    Result result;
    List<UnconfirmedTxPo> tmpList = new ArrayList<>();
    List<Entry<byte[], byte[]>> txs = dbService.entryList(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_TX);
    for (Entry<byte[], byte[]> txEntry : txs) {
        try {
            UnconfirmedTxPo tmpTx = new UnconfirmedTxPo(txEntry.getValue());
            if (tmpTx != null) {
                NulsByteBuffer buffer = new NulsByteBuffer(txEntry.getKey(), 0);
                tmpTx.getTx().setHash(buffer.readHash());
                tmpList.add(tmpTx);
            }
        } catch (Exception e) {
            Log.warn("parse local tx error", e);
        }
    }
    tmpList.sort(new Comparator<UnconfirmedTxPo>() {

        @Override
        public int compare(UnconfirmedTxPo o1, UnconfirmedTxPo o2) {
            return (int) (o1.getSequence() - o2.getSequence());
        }
    });
    List<Transaction> resultList = new ArrayList<>();
    for (UnconfirmedTxPo po : tmpList) {
        resultList.add(po.getTx());
    }
    return Result.getSuccess().setData(resultList);
}
Also used : ArrayList(java.util.ArrayList) UnconfirmedTxPo(io.nuls.account.ledger.storage.po.UnconfirmedTxPo) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsException(io.nuls.kernel.exception.NulsException) Result(io.nuls.kernel.model.Result) Entry(io.nuls.db.model.Entry) Transaction(io.nuls.kernel.model.Transaction) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 37 with Result

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

the class UnconfiredmTransactionStorageImpl method saveUnconfirmedTx.

@Override
public Result saveUnconfirmedTx(NulsDigestData hash, Transaction tx) {
    Result result;
    try {
        sequence++;
        UnconfirmedTxPo po = new UnconfirmedTxPo(tx, sequence);
        result = dbService.put(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_TX, hash.serialize(), po.serialize());
    } catch (Exception e) {
        e.printStackTrace();
        return Result.getFailed();
    }
    return result;
}
Also used : UnconfirmedTxPo(io.nuls.account.ledger.storage.po.UnconfirmedTxPo) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsException(io.nuls.kernel.exception.NulsException) Result(io.nuls.kernel.model.Result)

Example 38 with Result

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

the class ConsensusDownloadServiceImpl method downloadBlock.

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

Example 39 with Result

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

the class RegisterAgentProcessTest method testOnCommit.

@Test
public void testOnCommit() {
    assertNotNull(tx);
    assertNotNull(registerAgentProcess);
    Result result = registerAgentProcess.onCommit(tx, null);
    assert (result.isSuccess());
}
Also used : ValidateResult(io.nuls.kernel.validate.ValidateResult) Result(io.nuls.kernel.model.Result) Test(org.junit.Test) BaseTest(io.nuls.consensus.poc.BaseTest)

Example 40 with Result

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

the class ClientResource method startUpdate.

@POST
@Path("/upgrade/{version}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "升级")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = Boolean.class) })
public RpcClientResult startUpdate(@PathParam("version") String version) {
    AssertUtil.canNotEmpty(version);
    SyncVersionRunner syncor = SyncVersionRunner.getInstance();
    String newestVersion = syncor.getNewestVersion();
    if (!VersionUtils.higherThan(newestVersion, NulsConfig.VERSION)) {
        Result result = Result.getFailed(KernelErrorCode.NONEWVER);
        return result.toRpcClientResult();
    }
    if (!version.equals(newestVersion)) {
        Result result = Result.getFailed(KernelErrorCode.VERSION_NOT_NEWEST);
        return result.toRpcClientResult();
    }
    URL url = ClientResource.class.getClassLoader().getResource("libs");
    if (null == url) {
        return Result.getFailed(KernelErrorCode.DATA_NOT_FOUND).toRpcClientResult();
    }
    UpgradeThread thread = UpgradeThread.getInstance();
    if (thread.isUpgrading()) {
        return Result.getFailed(KernelErrorCode.UPGRADING).toRpcClientResult();
    }
    boolean result = thread.start();
    if (result) {
        TaskManager.createAndRunThread((short) 1, "upgrade", thread);
        Map<String, Boolean> map = new HashMap<>();
        map.put("value", true);
        return Result.getSuccess().setData(map).toRpcClientResult();
    }
    return Result.getFailed(KernelErrorCode.FAILED).toRpcClientResult();
}
Also used : HashMap(java.util.HashMap) UpgradeThread(io.nuls.client.rpc.resources.thread.UpgradeThread) SyncVersionRunner(io.nuls.client.version.SyncVersionRunner) URL(java.net.URL) RpcClientResult(io.nuls.kernel.model.RpcClientResult) Result(io.nuls.kernel.model.Result) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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