Search in sources :

Example 1 with StoredBlock

use of org.bitcoinj.core.StoredBlock in project bitcoin-wallet by bitcoin-wallet.

the class BlockchainService method getBlockchainState.

public BlockchainState getBlockchainState() {
    final StoredBlock chainHead = blockChain.getChainHead();
    final Date bestChainDate = chainHead.getHeader().getTime();
    final int bestChainHeight = chainHead.getHeight();
    final boolean replaying = chainHead.getHeight() < config.getBestChainHeightEver();
    return new BlockchainState(bestChainDate, bestChainHeight, replaying, impediments);
}
Also used : StoredBlock(org.bitcoinj.core.StoredBlock) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint)

Example 2 with StoredBlock

use of org.bitcoinj.core.StoredBlock in project bitcoin-wallet by bitcoin-wallet.

the class BlockchainService method getRecentBlocks.

public List<StoredBlock> getRecentBlocks(final int maxBlocks) {
    final List<StoredBlock> blocks = new ArrayList<StoredBlock>(maxBlocks);
    try {
        StoredBlock block = blockChain.getChainHead();
        while (block != null) {
            blocks.add(block);
            if (blocks.size() >= maxBlocks)
                break;
            block = block.getPrev(blockStore);
        }
    } catch (final BlockStoreException x) {
    // swallow
    }
    return blocks;
}
Also used : StoredBlock(org.bitcoinj.core.StoredBlock) BlockStoreException(org.bitcoinj.store.BlockStoreException) ArrayList(java.util.ArrayList)

Example 3 with StoredBlock

use of org.bitcoinj.core.StoredBlock in project bitcoin-wallet by bitcoin-wallet.

the class BlockListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final BlockViewHolder holder, final int position) {
    final StoredBlock storedBlock = getItem(position);
    final Block header = storedBlock.getHeader();
    holder.miningRewardAdjustmentView.setVisibility(isMiningRewardHalvingPoint(storedBlock) ? View.VISIBLE : View.GONE);
    holder.miningDifficultyAdjustmentView.setVisibility(isDifficultyTransitionPoint(storedBlock) ? View.VISIBLE : View.GONE);
    final int height = storedBlock.getHeight();
    holder.heightView.setText(Integer.toString(height));
    final long timeMs = header.getTimeSeconds() * DateUtils.SECOND_IN_MILLIS;
    if (timeMs < System.currentTimeMillis() - DateUtils.MINUTE_IN_MILLIS)
        holder.timeView.setText(DateUtils.getRelativeDateTimeString(context, timeMs, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
    else
        holder.timeView.setText(R.string.block_row_now);
    holder.hashView.setText(WalletUtils.formatHash(null, header.getHashAsString(), 8, 0, ' '));
    final int transactionChildCount = holder.transactionsViewGroup.getChildCount() - ROW_BASE_CHILD_COUNT;
    int iTransactionView = 0;
    final Sha256Hash blockHash = header.getHash();
    for (final Transaction tx : transactions) {
        if (tx.getAppearsInHashes().containsKey(blockHash)) {
            final View view;
            if (iTransactionView < transactionChildCount) {
                view = holder.transactionsViewGroup.getChildAt(ROW_INSERT_INDEX + iTransactionView);
            } else {
                view = inflater.inflate(R.layout.block_row_transaction, null);
                holder.transactionsViewGroup.addView(view, ROW_INSERT_INDEX + iTransactionView);
            }
            bindView(view, tx);
            iTransactionView++;
        }
    }
    final int leftoverTransactionViews = transactionChildCount - iTransactionView;
    if (leftoverTransactionViews > 0)
        holder.transactionsViewGroup.removeViews(ROW_INSERT_INDEX + iTransactionView, leftoverTransactionViews);
    if (onClickListener != null) {
        holder.menuView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(final View v) {
                onClickListener.onBlockMenuClick(v, storedBlock);
            }
        });
    }
}
Also used : StoredBlock(org.bitcoinj.core.StoredBlock) Transaction(org.bitcoinj.core.Transaction) Sha256Hash(org.bitcoinj.core.Sha256Hash) Block(org.bitcoinj.core.Block) StoredBlock(org.bitcoinj.core.StoredBlock) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

StoredBlock (org.bitcoinj.core.StoredBlock)3 SuppressLint (android.annotation.SuppressLint)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Block (org.bitcoinj.core.Block)1 Sha256Hash (org.bitcoinj.core.Sha256Hash)1 Transaction (org.bitcoinj.core.Transaction)1 BlockStoreException (org.bitcoinj.store.BlockStoreException)1