Search in sources :

Example 26 with LedgerBlock

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();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) UserAccountSet(com.jd.blockchain.ledger.core.UserAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with LedgerBlock

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;
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock)

Example 28 with LedgerBlock

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;
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock)

Example 29 with LedgerBlock

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;
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) Block(com.jd.blockchain.consensus.raft.consensus.Block)

Example 30 with LedgerBlock

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;
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock)

Aggregations

LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)53 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)36 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)36 QueryArgs (utils.query.QueryArgs)10 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)9 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)9 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)9 Test (org.junit.Test)9 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)8 TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)8 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)8 HashDigest (com.jd.blockchain.crypto.HashDigest)7 LedgerManager (com.jd.blockchain.ledger.core.LedgerManager)7 TransactionSet (com.jd.blockchain.ledger.core.TransactionSet)7 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)7 ContractAccountSet (com.jd.blockchain.ledger.core.ContractAccountSet)6 DataAccount (com.jd.blockchain.ledger.core.DataAccount)6 UserAccount (com.jd.blockchain.ledger.core.UserAccount)6 TransactionResponse (com.jd.blockchain.ledger.TransactionResponse)5 DefaultOperationHandleRegisteration (com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration)5