Package org.ethereum.core

Examples of org.ethereum.core.Block


  public MinerThread(String name,  MineSwarm mineSwarm, byte[] coinbase) {
        this.name = name;
        this.mineSwarm = mineSwarm;
        this.coinbase = coinbase;

        Block genesis = Genesis.getInstance();
        mainChain.add(genesis);

  }
View Full Code Here


        mineSwarm.announceBlock(block);
    }

  private void doRun() {

        Block genesis = mainChain.getLast();
        tmpBlock = createBlock(genesis, coinbase);
        while (!done){

            this.announcedBlock = null;
            logger.info("{}: before mining: chain.size: [{}], chain.TD: [{}]", name,
View Full Code Here

//           System.out.println("increase");
//           BigInteger diff = (new BigInteger(1, lastBlock.getDifficulty()).add(new BigInteger("FFF", 16)));
//           difficulty = diff.toByteArray();
//       }

        Block newBlock = new Block(lastBlock.getHash(), lastBlock.getUnclesHash(), coinbase, lastBlock.getLogBloom(),
                difficulty , lastBlock.getNumber() + 1, lastBlock.getMinGasPrice(),
                lastBlock.getGasLimit(), lastBlock.getGasUsed(), System.currentTimeMillis() / 1000,
                null, null,  null, null);

        return newBlock;
View Full Code Here

    public void mineOnBlock(){

        byte[] blockRaw = Hex.decode("f90139f90134a077702830ce2f66cdbf82cabd600ddb760a68b73c93739bdd439309989b22f93ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794907a0f5f767664ac77c8e431b99e74abc9288a40a0a2deb803ea8704997ae17efd0adf038df2833505da8776f095e32174dcb8e4aba056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b840000000000000000000000000000000000000000000002000000000004000000000000020000000000000000000000000000000000000000000000000000000008301f2363c8609184e72a000830e63bb80845461623980a05643fd40385c6520e3320109adc71917fdbbcdffe61f0b476ccb3b34111af194c0c0");
        byte[] coinbase = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");

        Block block = new Block(blockRaw);
        Block newBlock = MinerThread.createBlock(block, coinbase);
        newBlock.setStateRoot(Hex.decode("43bb67bea1931eca8f9e06f9cca66a9f9914cc3e3d4e9ceb2e08e58ab9f92bab"));

        Miner miner = new Miner();
        miner.mine(newBlock, newBlock.getDifficulty());

        System.out.println(newBlock);

        //f8f9f8f5a0a02852f3f5e7d06936bd5f39e7cc65a9f11e37656255f92c7eb32cb878a70213a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794cd2a3d9f938e13cd947ec05abc7fe734df8dd826a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421808301ef4e518609184e72a000830e1c69808601499c9bf5dd80a0000000000000000000000000000000000000000000000000000000000000f599c0c0
View Full Code Here

   
        // Invocation by the wire tx
    public ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository) {

        // https://ethereum.etherpad.mozilla.org/26
        Block lastBlock = blockchain.getBestBlock();

        /***         ADDRESS op       ***/
        // YP: Get address of currently executing account.
        byte[] address  =  tx.isContractCreation() ? tx.getContractAddress(): tx.getReceiveAddress();

        /***         ORIGIN op       ***/
        // YP: This is the sender of original transaction; it is never a contract.
        byte[] origin  = tx.getSender();

        /***         CALLER op       ***/
        // YP: This is the address of the account that is directly responsible for this execution.
        byte[] caller = tx.getSender();

        /***         BALANCE op       ***/
        byte[] balance = repository.getBalance(address).toByteArray();

        /***         GASPRICE op       ***/
        byte[] gasPrice = tx.getGasPrice();

        /*** GAS op ***/
        byte[] gas = tx.getGasLimit();

        /***        CALLVALUE op      ***/
        byte[] callValue = tx.getValue() == null ? new byte[]{0} : tx.getValue();

        /***     CALLDATALOAD  op   ***/
        /***     CALLDATACOPY  op   ***/
        /***     CALLDATASIZE  op   ***/
        byte[] data = tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData();

        /***    PREVHASH  op  ***/
        byte[] lastHash = lastBlock.getHash();

        /***   COINBASE  op ***/
        byte[] coinbase = block.getCoinbase();

        /*** TIMESTAMP  op  ***/
 
View Full Code Here

    @Test /* got from go guy */
    public void testGenesisFromRLP() {
      // from RLP encoding
      byte[] genesisBytes = Hex.decode(PoC7_GENESIS_HEX_RLP_ENCODED);
      Block genesisFromRLP = new Block(genesisBytes);
      Block genesis = Genesis.getInstance();
      assertEquals(Hex.toHexString(genesis.getHash()), Hex.toHexString(genesisFromRLP.getHash()));
      assertEquals(Hex.toHexString(genesis.getParentHash()), Hex.toHexString(genesisFromRLP.getParentHash()));
      assertEquals(Hex.toHexString(genesis.getStateRoot()), Hex.toHexString(genesisFromRLP.getStateRoot()));
    }
View Full Code Here

                    setParameter("number", blockNumber).list();

        if (result.size() == 0) return null;
        BlockVO vo = (BlockVO)result.get(0);

        return new Block(vo.rlp);
    }
View Full Code Here

                setParameter("hash", hash).list();

        if (result.size() == 0) return null;
        BlockVO vo = (BlockVO)result.get(0);

        return new Block(vo.rlp);
    }
View Full Code Here

    @Ignore
  public void testMine() {
    boolean miningTestEnabled = false;
   
    if(miningTestEnabled) {
      Block block = createBlock(null);
      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);
     
      // expectedHash is the actual hash from block#32 in PoC5 chain based on nonce below
      String expectedHash = "ce7201f6cc5eb1a6f35c7dda8acda111647a0f8a5bf0518e46579b03e29fe14b";
      assertEquals(expectedHash, Hex.toHexString(block.getHash()));

      // expectedNonce is the actual nonce from block#32 in Poc5 chain
      String expectedNonce = "0000000000000000000000000000000000000000000000001f52ebb192c4ea97"; // from Poc5 chain
      // Actual is "000000000000000000000000000000000000000000000000000000000098cc15"
      // but that might also be a valid nonce in compliance with PoW(H!n, n) < (2^256 / difficulty)
      assertEquals(expectedNonce, Hex.toHexString(block.getNonce()));
    }
  }
View Full Code Here

     * Processing NEW_BLOCK announce message
     * @param newBlockMessage - new block message
     */
    public void procesNewBlock(NewBlockMessage newBlockMessage){

        Block newBlock = newBlockMessage.getBlock();

        // If the hashes still being downloaded ignore the NEW_BLOCKs
        // that block hash will be retrieved by the others and letter the block itself
        if (syncStatus == SyncSatus.INIT || syncStatus == SyncSatus.HASH_RETRIEVING) {
            logger.debug("Sync status INIT or HASH_RETREIVING ignore new block.index: [{}]", newBlock.getNumber());
            return;
        }

        // If the GET_BLOCKs stage started add hash to the end of the hash list
        // then the block will be retrieved in it's turn;
        if (syncStatus == SyncSatus.BLOCK_RETRIEVING){
            logger.debug("Sync status BLOCK_RETREIVING add to the end of hash list: block.index: [{}]",
                    newBlock.getNumber());
            blockchain.getQueue().addNewBlockHash(newBlock.getHash());
            return;
        }

        // here is post sync process
        logger.info("New block received: block.index [{}]", newBlock.getNumber());

/*
        if (blockchain.hasParentOnTheChain(newBlock) && gap <=0){
            //todo: here we create an alternative chain.
            return;
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.