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