Package org.ethereum.core

Examples of org.ethereum.core.Block


    @Ignore
    public void testMine2() {
        boolean miningTestEnabled = true;

        if(miningTestEnabled) {
            Block block = createBlock(null);

            logger.info("Minning on block: [{}] ", block.getNumber());
//            assertEquals(rlpWithoutNonce, Hex.toHexString(block.getEncodedWithoutNonce()));
//            System.out.println("Searching for nonce of following block: \n" + block.toString());

            Miner miner = new Miner();
            boolean mined = miner.mine(block, block.getDifficulty());
            assertTrue(mined);
            boolean valid = block.validateNonce();
            assertTrue(valid);
            logger.info("found nonce: [{}]", Hex.toHexString(block.getNonce()));

            while(true){

                Block newBlock = createBlock(block);
                mined = miner.mine(newBlock, newBlock.getDifficulty());
                assertTrue(mined);
                valid = newBlock.validateNonce();
                assertTrue(valid);
                block = newBlock;
                logger.info("found nonce: [{}]", Hex.toHexString(newBlock.getNonce()));
                logger.info("block.number: [{}], added to the chain", newBlock.getNumber());
            }
        }
    }
View Full Code Here


        List<byte[]> hashes = msg.getBlockHashes();

        Vector<Block> blocks = new Vector<>();
        for (byte[] hash : hashes){
            Block block =  blockchain.getBlockByHash(hash);
            blocks.add(block);
        }

        BlocksMessage bm = new BlocksMessage(blocks);
        msgQueue.sendMessage(bm);
View Full Code Here

            long gasLimit = 969216;
            long gasUsed = 0;
            long timestamp = 1401421088;
            byte[] stateRoot = Hex.decode("50188ab86bdf164ac90eb2835a04a8930aae5393c3a2ef1166fb95028f9456b8");

            Block newBlock = new Block(parentHash, unclesHash, coinbase, null,
                    difficulty, number, minGasPrice, gasLimit, gasUsed, timestamp,
                    null, nonce,  null, null);
            // Setting stateRoot manually, because don't have state available.
            return newBlock;
        } else{

            Block newBlock = new Block(lastBlock.getHash(), lastBlock.getUnclesHash(), lastBlock.getCoinbase(), null,
                    lastBlock.getDifficulty(), lastBlock.getNumber() + 1, lastBlock.getMinGasPrice(),
                    lastBlock.getGasLimit(), lastBlock.getGasUsed(), lastBlock.getTimestamp(),
                    null, null, null, null);

            return newBlock;
View Full Code Here

        }

        Transaction tx = createTransaction();
        if (tx == null) return;

        Block lastBlock = UIEthereumManager.ethereum.getBlockchain().getBestBlock();
        ProgramPlayDialog.createAndShowGUI(programCode, tx, lastBlock);
    }
View Full Code Here

            @Override
            public void actionPerformed(ActionEvent e) {

                if (UIEthereumManager.ethereum.getBlockchain().getSize() - 1 < lastFindIndex) return;

                Block block = UIEthereumManager.ethereum.getBlockchain().getBlockByNumber(lastFindIndex);
                StringSelection selection = new StringSelection(block.toString());
                Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
                system.setContents(selection, selection);
            }
        });
View Full Code Here

    }

    private long findBlock(String textToFind, long blockNum, boolean forward) {
        if (forward) {
            for (long i = blockNum + 1; i < UIEthereumManager.ethereum.getBlockchain().getSize(); i++) {
                Block block = UIEthereumManager.ethereum.getBlockchain().getBlockByNumber(i);
                if (block.toString().toLowerCase().contains(textToFind.toLowerCase())) {
                    foundBlocks.add(i);
                    lastFindIndex = foundBlocks.size() - 1;
                    break;
                }
            }
        } else {
            for (long i = blockNum - 1; i >= 0; i--) {
                Block block = UIEthereumManager.ethereum.getBlockchain().getBlockByNumber(i);
                if (block.toString().toLowerCase().contains(textToFind.toLowerCase())) {
                    foundBlocks.add(0, i);
                    lastFindIndex = 0;
                    break;
                }
            }
View Full Code Here

        Blockchain blockchain = UIEthereumManager.ethereum.getBlockchain();
        long blockNum = Long.parseLong(blockNumberText.getText());
        if (blockNum > blockchain.getSize() - 1) {
            blockNum = blockchain.getSize() - 1;
        }
        Block block = blockchain.getBlockByNumber(blockNum);
        blockN.setText("" + block.getNumber());
        highlightText(blockN);
        minGasPrice.setText("" + block.getMinGasPrice());
        highlightText(minGasPrice);
        gasLimit.setText("" + block.getGasLimit());
        highlightText(gasLimit);
        gasUsed.setText("" + block.getGasUsed());
        highlightText(gasUsed);
        timestamp.setText(Utils.longToDateTime(block.getTimestamp()));
        highlightText(timestamp);
        difficulty.setText(ByteUtil.toHexString(block.getDifficulty()));
        highlightText(difficulty);

        hash.setText(ByteUtil.toHexString(block.getHash()));
        highlightText(hash);
        parentHash.setText(ByteUtil.toHexString(block.getParentHash()));
        highlightText(parentHash);
        uncleHash.setText(ByteUtil.toHexString(block.getUnclesHash()));
        highlightText(uncleHash);
        stateRoot.setText(ByteUtil.toHexString(block.getStateRoot()));
        highlightText(stateRoot);
        trieRoot.setText(ByteUtil.toHexString(block.getTxTrieRoot()));
        highlightText(trieRoot);
        coinbase.setText(ByteUtil.toHexString(block.getCoinbase()));
        highlightText(coinbase);
        nonce.setText(ByteUtil.toHexString(block.getNonce()));
        highlightText(nonce);
        if (block.getExtraData() != null) {
            extraData.setText(ByteUtil.toHexString(block.getExtraData()));
            highlightText(extraData);
        }

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;

        transactionsPanel.removeAll();

        int row = 1;
        for (Transaction transaction : block.getTransactionsList()) {
            JPanel transactionPanel = createTransactionPanel(blockchainTable, transaction);

            c.gridx = 0;
            c.gridy = row;
            c.weighty = 1;
View Full Code Here

  private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

        RLPList blockRLP = ((RLPList) paramsList.get(1));
        block = new Block(blockRLP.getRLPData());
        difficulty =  paramsList.get(2).getRLPData();

        parsed = true;
  }
View Full Code Here

        File file = new File(massiveUpload_1.toURI());
        List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);

        for(String blockRLP : strData){
            Block block = new Block(
                    Hex.decode(blockRLP));
            logger.info("sending block.hash: {}", Hex.toHexString( block.getHash() ));
            blockchain.tryToConnect(block);
        }

        List<Chain> altChains = blockchain.getAltChains();
        List<Block> garbage   = blockchain.getGarbage();
View Full Code Here

        File file = new File(massiveUpload_1.toURI());
        List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);

        for(String blockRLP : strData){
            Block block = new Block(
                    Hex.decode(blockRLP));
            logger.info("sending block.hash: {}", Hex.toHexString( block.getHash() ));
            blockchain.tryToConnect(block);
        }

        List<Chain> altChains = blockchain.getAltChains();
        List<Block> garbage   = blockchain.getGarbage();
View Full Code Here

TOP

Related Classes of org.ethereum.core.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.