public void saveBlocks ( BigInteger startBlockNumber , BigInteger endBlockNumber ) { if ( endBlockNumber . compareTo ( startBlockNumber ) < 1 ) { LOGGER . error ( "startBlockNumber must be smaller than endBlockNumer" ) ; throw new KunderaException ( "startBlockNumber must be smaller than endBlockNumer" ) ; } if ( startBlockNumber . compareTo ( getFirstBlockNumber ( ) ) < 0 ) { LOGGER . error ( "start block number can't be smaller than EARLIEST block" ) ; throw new KunderaException ( "starting block number can't be smaller than EARLIEST block" ) ; } if ( endBlockNumber . compareTo ( getLatestBlockNumber ( ) ) > 0 ) { LOGGER . error ( "end block number can't be larger than LATEST block" ) ; throw new KunderaException ( "end block number can't be larger than LATEST block" ) ; } long diff = endBlockNumber . subtract ( startBlockNumber ) . longValue ( ) ; for ( long i = 0 ; i <= diff ; i ++ ) { EthBlock block = null ; BigInteger currentBlockNum = null ; try { currentBlockNum = startBlockNumber . add ( BigInteger . valueOf ( i ) ) ; block = web3j . ethGetBlockByNumber ( DefaultBlockParameter . valueOf ( currentBlockNum ) , true ) . send ( ) ; } catch ( IOException ex ) { LOGGER . error ( "Not able to find block" + currentBlockNum + ". " , ex ) ; throw new KunderaException ( "Not able to find block" + currentBlockNum + ". " , ex ) ; } persistBlocksAndTransactions ( block ) ; } }
Gets the blocks .