use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockHeaderStorageServiceImpl method getBlockHeaderPo.
/**
* 根据区块hash查询区块头数据
* Query block header data according to block hash.
*
* @param hashBytes 区块头摘要/block hash
* @return BlockHeaderPo 区块头数据
*/
private BlockHeaderPo getBlockHeaderPo(byte[] hashBytes) {
byte[] bytes = dbService.get(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER, hashBytes);
if (null == bytes) {
return null;
}
BlockHeaderPo po = new BlockHeaderPo();
try {
po.parse(bytes, 0);
} catch (NulsException e) {
Log.error(e);
}
NulsDigestData hash = new NulsDigestData();
try {
hash.parse(hashBytes, 0);
} catch (NulsException e) {
Log.error(e);
}
po.setHash(hash);
return po;
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockHeaderStorageServiceImplTest method removeBlockHerader.
public void removeBlockHerader() {
service.removeBlockHerader(entity);
BlockHeaderPo po = this.service.getBlockHeaderPo(entity.getHash());
assertNull(po);
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockHeaderStorageServiceImplTest method getBlockPo1.
public void getBlockPo1() {
BlockHeaderPo po = this.service.getBlockHeaderPo(entity.getHash());
this.testEquals(po, entity);
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockHeaderStorageServiceImplTest method init.
@Before
public void init() {
MicroKernelBootstrap mk = MicroKernelBootstrap.getInstance();
mk.init();
mk.start();
LevelDbModuleBootstrap bootstrap = new LevelDbModuleBootstrap();
bootstrap.init();
bootstrap.start();
service = NulsContext.getServiceBean(BlockHeaderStorageService.class);
BlockHeaderPo po = new BlockHeaderPo();
po.setHash(NulsDigestData.calcDigestData("hashhash".getBytes()));
po.setHeight(1286L);
po.setExtend("extends".getBytes());
po.setMerkleHash(NulsDigestData.calcDigestData("merkleHash".getBytes()));
po.setPreHash(NulsDigestData.calcDigestData("prehash".getBytes()));
try {
po.setPackingAddress("address".getBytes());
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
po.setScriptSign(new BlockSignature());
po.setTime(12345678901L);
po.setTxCount(3);
List<NulsDigestData> txHashList = new ArrayList<>();
txHashList.add(NulsDigestData.calcDigestData("first-tx-hash".getBytes()));
txHashList.add(NulsDigestData.calcDigestData("second-tx-hash".getBytes()));
txHashList.add(NulsDigestData.calcDigestData("third-tx-hash".getBytes()));
po.setTxHashList(txHashList);
this.entity = po;
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockServiceImpl method rollbackBlock.
/**
* 回滚区块
* roll back the block to the store.
*
* @param block 完整区块/whole block
* @return 操作结果/operating result
* @throws NulsException 回滚区块有可能出现异常,请捕获后谨慎处理/There may be exceptions to the roll back block, please handle it carefully after capture.
*/
@Override
public Result rollbackBlock(Block block) throws NulsException {
if (null == block) {
return Result.getFailed(ProtocolErroeCode.BLOCK_IS_NULL);
}
boolean txsResult = this.rollbackTxList(block.getTxs(), block.getHeader(), true);
if (!txsResult) {
return Result.getFailed();
}
BlockHeaderPo po = new BlockHeaderPo();
po.setHash(block.getHeader().getHash());
po.setHeight(block.getHeader().getHeight());
po.setPreHash(block.getHeader().getPreHash());
Result result = this.blockHeaderStorageService.removeBlockHerader(po);
if (result.isFailed()) {
return result;
}
try {
accountLedgerService.rollbackTransactions(block.getTxs());
// 回滚合约相关交易
contractService.rollbackTransactionList(block.getTxs());
} catch (Exception e) {
Log.warn("rollbackTransaction local tx failed", e);
}
return result;
}
Aggregations