use of io.nuls.kernel.model.Result in project nuls by nuls-io.
the class TransactionServiceImpl method commitTx.
/**
* 确认交易时调用的方法,对交易相关的业务进行提交操作
* Identify the method that is invoked during the transaction and submit the transaction related business.
*
* @param tx 操作的交易/The transaction of the operation
* @param secondaryData 辅助数据(可以为空)/Secondary data (available for null)
* @return 操作结果/operating results
*/
@Override
public Result commitTx(Transaction tx, Object secondaryData) {
List<TransactionProcessor> processorList = TransactionManager.getProcessorList(tx.getClass());
List<TransactionProcessor> commitedProcessorList = new ArrayList<>();
for (TransactionProcessor processor : processorList) {
Result result = processor.onCommit(tx, secondaryData);
if (result.isSuccess()) {
commitedProcessorList.add(processor);
} else {
for (int i = commitedProcessorList.size() - 1; i >= 0; i--) {
TransactionProcessor processor1 = commitedProcessorList.get(i);
processor1.onRollback(tx, secondaryData);
}
return result;
}
}
return Result.getSuccess();
}
use of io.nuls.kernel.model.Result in project nuls by nuls-io.
the class TransactionServiceImpl method rollbackTx.
/**
* 回滚交易时调用的方法,对交易相关的业务进行回退操作
* The method invoked when the transaction is rolled back and the transaction related business is returned.
*
* @param tx 操作的交易/The transaction of the operation
* @param secondaryData 辅助数据(可以为空)/Secondary data (available for null)
* @return 操作结果/operating results
*/
@Override
public Result rollbackTx(Transaction tx, Object secondaryData) {
if (null == tx) {
return Result.getSuccess();
}
List<TransactionProcessor> processorList = TransactionManager.getProcessorList(tx.getClass());
List<TransactionProcessor> rollbackedList = new ArrayList<>();
for (TransactionProcessor processor : processorList) {
Result result = processor.onRollback(tx, secondaryData);
if (result.isSuccess()) {
rollbackedList.add(processor);
} else {
for (int i = rollbackedList.size() - 1; i >= 0; i--) {
TransactionProcessor processor1 = rollbackedList.get(i);
processor1.onCommit(tx, secondaryData);
}
return result;
}
}
try {
ledgerService.rollbackTx(tx);
} catch (NulsException e) {
Log.error(e);
return Result.getFailed(e.getErrorCode());
}
return Result.getSuccess();
}
use of io.nuls.kernel.model.Result in project nuls by nuls-io.
the class BlockHeaderStorageServiceImpl method afterPropertiesSet.
/**
* 创建存储表,创建失败时如果是因为已存在则正常,否则抛出异常
* Create a storage table, or throw an exception if it is normal if it is already existing.
*/
@Override
public void afterPropertiesSet() {
Result result = this.dbService.createArea(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER_INDEX);
if (result.isFailed() && !DBErrorCode.DB_AREA_EXIST.equals(result.getErrorCode())) {
throw new NulsRuntimeException(result.getErrorCode());
}
result = this.dbService.createArea(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER);
if (result.isFailed() && !DBErrorCode.DB_AREA_EXIST.equals(result.getErrorCode())) {
throw new NulsRuntimeException(result.getErrorCode());
}
try {
bestBlockKey = NulsDigestData.calcDigestData(ProtocolStorageConstant.BEST_BLOCK_HASH_INDEX.getBytes()).serialize();
} catch (IOException e) {
throw new NulsRuntimeException(e.getCause());
}
}
use of io.nuls.kernel.model.Result in project nuls by nuls-io.
the class BlockHeaderStorageServiceImplTest method saveBlockHeader.
public void saveBlockHeader() {
Result result = service.saveBlockHeader(entity);
assertTrue(result.isSuccess());
}
use of io.nuls.kernel.model.Result in project nuls by nuls-io.
the class AccountBaseServiceTest method getPrivateKeyTest.
@Test
public void getPrivateKeyTest() {
List<Account> accounts = this.accountService.createAccount(1, "nuls123456").getData();
Account account = accounts.get(0);
Result result = accountBaseService.getPrivateKey(account.getAddress().toString(), "nuls123456");
assertTrue(result.isSuccess());
try {
account.unlock("nuls123456");
} catch (NulsException e) {
e.printStackTrace();
}
assertArrayEquals(Hex.decode((String) result.getData()), account.getPriKey());
List<Account> accounts2 = this.accountService.createAccount(1, "").getData();
Account account2 = accounts2.get(0);
Result result2 = accountBaseService.getPrivateKey(account2.getAddress().toString(), "");
assertTrue(result2.isSuccess());
assertArrayEquals(Hex.decode((String) result2.getData()), account2.getPriKey());
}
Aggregations