use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getUserTotalCount.
@RequestMapping(method = RequestMethod.GET, path = GET_TOTAL_USER_COUNT)
@Override
public long getUserTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
UserAccountSet userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getTotal();
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerRepositoryImpl method retrieveLatestState.
/**
* 重新检索加载最新的状态;
*
* @return
*/
private LedgerState retrieveLatestState() {
LedgerBlock latestBlock = innerGetBlock(innerGetLatestBlockHeight());
LedgerDataSet ledgerDataset;
TransactionSet txSet;
LedgerEventSet ledgerEventset;
ledgerDataset = innerGetLedgerDataset(latestBlock);
txSet = loadTransactionSet(latestBlock.getHeight(), latestBlock.getTransactionSetHash(), ((LedgerAdminDataSetEditor) (ledgerDataset.getAdminDataset())).getSettings().getCryptoSetting(), keyPrefix, exPolicyStorage, versioningStorage, dataStructure, true);
ledgerEventset = innerGetLedgerEventSet(latestBlock);
this.ledgerStructureVersion = ((LedgerAdminDataSetEditor) (ledgerDataset.getAdminDataset())).getMetadata().getLedgerStructureVersion();
this.latestState = new LedgerState(latestBlock, ledgerDataset, txSet, ledgerEventset);
return latestState;
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerRepositoryImpl method createNextBlock.
@Override
public synchronized LedgerEditor createNextBlock() {
LedgerEditor editor;
if (closed) {
throw new RuntimeException("Ledger repository has been closed!");
}
if (this.nextBlockEditor != null) {
throw new RuntimeException("A new block is in process, cann't create another one until it finish by committing or canceling.");
}
LedgerBlock previousBlock = getLatestBlock();
editor = LedgerTransactionalEditor.createEditor(previousBlock, getLatestSettings(), keyPrefix, exPolicyStorage, versioningStorage, dataStructure);
NewBlockCommittingMonitor committingMonitor = new NewBlockCommittingMonitor(editor, this);
this.nextBlockEditor = committingMonitor;
return committingMonitor;
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class BlockProposerService method proposeBlock.
@Override
public Block proposeBlock(List<byte[]> txs) {
lock.lock();
Block proposeBlock = new Block();
try {
proposeBlock.setProposalTimestamp(System.currentTimeMillis());
proposeBlock.setTxs(txs);
// todo: 使用latestProposalBlock减少账本查询
if (proposalBlockMap.isEmpty()) {
LedgerBlock latestBlock = ledgerRepository.retrieveLatestBlock();
proposeBlock.setPreBlockHash(latestBlock.getHash());
proposeBlock.setHeight(latestBlock.getHeight() + 1);
} else {
proposeBlock.setHeight(latestProposalBlock.getHeight() + +1);
}
proposalBlockMap.put(proposeBlock.getHeight(), proposeBlock);
latestProposalBlock = proposeBlock;
LoggerUtils.debugIfEnabled(LOGGER, "proposal cache size: {}, latest proposal height: {}", proposalBlockMap.size(), latestProposalBlock.getHeight());
} finally {
lock.unlock();
}
return proposeBlock;
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerRepositoryImpl method getSecurityManager.
@Override
public LedgerSecurityManager getSecurityManager() {
LedgerBlock ledgerBlock = getLatestBlock();
LedgerDataSet ledgerDataQuery = getLedgerDataSet(ledgerBlock);
LedgerAdminDataSet previousAdminDataset = ledgerDataQuery.getAdminDataset();
LedgerSecurityManager securityManager = new LedgerSecurityManagerImpl(previousAdminDataset.getAdminSettings().getRolePrivileges(), previousAdminDataset.getAdminSettings().getAuthorizations(), previousAdminDataset.getParticipantDataset(), ledgerDataQuery.getUserAccountSet());
return securityManager;
}
Aggregations