Java Code Examples for org.web3j.protocol.core.methods.response.EthBlock#Block
The following examples show how to use
org.web3j.protocol.core.methods.response.EthBlock#Block .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Eth1DepositManager.java From teku with Apache License 2.0 | 6 votes |
private SafeFuture<Void> headAfterMinGenesisMode( final EthBlock.Block headBlock, final ReplayDepositsResult replayDepositsResult) { LOG.debug("Eth1DepositsManager initiating head after genesis mode"); if (replayDepositsResult.isPastMinGenesisBlock()) { depositProcessingController.startSubscription( replayDepositsResult.getFirstUnprocessedBlockNumber()); return SafeFuture.COMPLETE; } return minimumGenesisTimeBlockFinder .findMinGenesisTimeBlockInHistory(headBlock.getNumber()) .thenCompose(block -> sendDepositsUpToMinGenesis(block, replayDepositsResult)) .thenAccept( minGenesisTimeBlock -> { notifyMinGenesisTimeBlockReached(eth1EventsChannel, minGenesisTimeBlock); // Start the subscription from the block after min genesis as we've already processed // the min genesis block depositProcessingController.startSubscription( minGenesisTimeBlock.getNumber().add(BigInteger.ONE)); }); }
Example 2
Source File: Web3jBlock.java From eventeum with Apache License 2.0 | 6 votes |
public Web3jBlock(EthBlock.Block web3jBlock, String nodeName) { final ModelMapper modelMapper = ModelMapperFactory.getInstance().createModelMapper(); modelMapper.typeMap( EthBlock.Block.class, Web3jBlock.class) .addMappings(mapper -> { mapper.skip(Web3jBlock::setTransactions); //Nonce can be null which throws exception in web3j when //calling getNonce (because of attempted hex conversion) if (web3jBlock.getNonceRaw() == null) { mapper.skip(Web3jBlock::setNonce); } }); modelMapper.map(web3jBlock, this); transactions = convertTransactions(web3jBlock.getTransactions()); this.nodeName = nodeName; }
Example 3
Source File: Eth1DepositManager.java From teku with Apache License 2.0 | 5 votes |
private SafeFuture<EthBlock.Block> sendDepositsUpToMinGenesis( final EthBlock.Block minGenesisTimeBlock, final ReplayDepositsResult replayDepositsResult) { return depositProcessingController .fetchDepositsInRange( replayDepositsResult.getFirstUnprocessedBlockNumber(), minGenesisTimeBlock.getNumber()) .thenApply(__ -> minGenesisTimeBlock); }
Example 4
Source File: MinimumGenesisTimeBlockFinder.java From teku with Apache License 2.0 | 5 votes |
static void notifyMinGenesisTimeBlockReached( Eth1EventsChannel eth1EventsChannel, EthBlock.Block block) { MinGenesisTimeBlockEvent event = new MinGenesisTimeBlockEvent( UnsignedLong.valueOf(block.getTimestamp()), UnsignedLong.valueOf(block.getNumber()), Bytes32.fromHexString(block.getHash())); eth1EventsChannel.onMinGenesisTimeBlock(event); LOG.debug("Notifying BeaconChainService of MinGenesisTimeBlock: {}", event); }
Example 5
Source File: DepositFetcher.java From teku with Apache License 2.0 | 5 votes |
private SafeFuture<Void> postDepositEvents( List<SafeFuture<EthBlock.Block>> blockRequests, Map<BlockNumberAndHash, List<DepositContract.DepositEventEventResponse>> depositEventsByBlock, BigInteger fromBlock, BigInteger toBlock) { BigInteger from = fromBlock; // First process completed requests using iteration. // Avoid StackOverflowException when there is a long string of requests already completed. while (!blockRequests.isEmpty() && blockRequests.get(0).isDone()) { final EthBlock.Block block = blockRequests.remove(0).join(); // Fetch any empty blocks between this deposit block and the previous one (or start of range) final BigInteger to = block.getNumber().subtract(BigInteger.ONE); eth1BlockFetcher.fetch(from, to); from = block.getNumber().add(BigInteger.ONE); postEventsForBlock(block, depositEventsByBlock); } // All requests have completed and been processed. if (blockRequests.isEmpty()) { // Fetch any empty blocks between the last deposit and end of the range eth1BlockFetcher.fetch(from, toBlock); return SafeFuture.COMPLETE; } BigInteger remainingRangeStart = from; // Reached a block request that isn't complete so wait for it and recurse back into this method. return blockRequests .get(0) .thenCompose( block -> postDepositEvents( blockRequests, depositEventsByBlock, remainingRangeStart, toBlock)); }
Example 6
Source File: Eth1DepositManager.java From teku with Apache License 2.0 | 5 votes |
private SafeFuture<Void> headBeforeMinGenesisMode( final EthBlock.Block headBlock, final BigInteger startBlockNumber) { LOG.debug("Eth1DepositsManager initiating head before genesis mode"); BigInteger headBlockNumber = headBlock.getNumber(); // Ensure we have processed all blocks up to and including headBlock // preGenesisSubscription will then pick up from the block after headBlock if (startBlockNumber.compareTo(headBlockNumber) <= 0) { return depositProcessingController .fetchDepositsInRange(startBlockNumber, headBlockNumber) .thenRun(() -> preGenesisSubscription(headBlockNumber)); } preGenesisSubscription(headBlockNumber); return SafeFuture.COMPLETE; }
Example 7
Source File: JsonRpc2_0RxTest.java From web3j with Apache License 2.0 | 5 votes |
private EthBlock createBlock(int number) { EthBlock ethBlock = new EthBlock(); EthBlock.Block block = new EthBlock.Block(); block.setNumber(Numeric.encodeQuantity(BigInteger.valueOf(number))); ethBlock.setResult(block); return ethBlock; }
Example 8
Source File: EnsResolverTest.java From web3j with Apache License 2.0 | 5 votes |
private void configureLatestBlock(long timestamp) throws IOException { EthBlock.Block block = new EthBlock.Block(); block.setTimestamp(Numeric.encodeQuantity(BigInteger.valueOf(timestamp))); EthBlock ethBlock = new EthBlock(); ethBlock.setResult(block); when(web3jService.send(any(Request.class), eq(EthBlock.class))).thenReturn(ethBlock); }
Example 9
Source File: CoreIT.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Test public void testEthGetBlockByNumber() throws Exception { EthBlock ethBlock = web3j.ethGetBlockByNumber( DefaultBlockParameter.valueOf(BigInteger.valueOf(2391)), true).send(); EthBlock.Block block = ethBlock.getBlock(); assertNotNull(ethBlock.getBlock()); for (TransactionResult tx : block.getTransactions()) { System.out.println(((TransactionObject) tx).getCreates()); EthTransaction ethTransaction = web3j.ethGetTransactionByHash(((TransactionObject) tx).getHash()).send(); System.out.println(ethTransaction.getTransaction().get().getCreates()); } System.out.println(new ObjectMapper().writeValueAsString(block)); }
Example 10
Source File: DepositFetcher.java From teku with Apache License 2.0 | 5 votes |
private DepositsFromBlockEvent createDepositFromBlockEvent( final EthBlock.Block block, final List<DepositContract.DepositEventEventResponse> groupedDepositEventResponse) { return new DepositsFromBlockEvent( UnsignedLong.valueOf(block.getNumber()), Bytes32.fromHexString(block.getHash()), UnsignedLong.valueOf(block.getTimestamp()), groupedDepositEventResponse.stream() .map(Deposit::new) .sorted(Comparator.comparing(Deposit::getMerkle_tree_index)) .collect(toList())); }
Example 11
Source File: DepositFetcher.java From teku with Apache License 2.0 | 5 votes |
private List<SafeFuture<EthBlock.Block>> getListOfEthBlockFutures( Set<BlockNumberAndHash> neededBlockHashes) { return neededBlockHashes.stream() .map(BlockNumberAndHash::getHash) .map(eth1Provider::getGuaranteedEth1Block) .collect(toList()); }
Example 12
Source File: SyncToDatabaseTask.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Scheduled(fixedRate = 5000) public void run() throws Exception { Long latest = blockMapper.latestNumber(); long ethLatest = web3j.ethBlockNumber().send().getBlockNumber().longValue(); if (null == latest) { latest = 0L; } for (long i = latest + 1; i < ethLatest + 1; i++) { EthBlock.Block blk = web3j.ethGetBlockByNumber( DefaultBlockParameter.valueOf(BigInteger.valueOf(i)), true) .send().getBlock(); Block block = ConverterFunctionUtil.toDbBlock.apply(blk); List<Transaction> transactions = ConverterFunctionUtil.toTransactions.apply(blk); List<Account> accounts = ConverterFunctionUtil.toAccounts.apply(blk); Map<String, TransactionReceipt> transactionReceiptMap = updateTransactions(transactions); List<Account> allAccounts = getAllAddresses(accounts, transactionReceiptMap); updateAccounts(allAccounts); if (!allAccounts.isEmpty()) { accountMapper.update(allAccounts); } if (!transactions.isEmpty()) { transactionMapper.insert(transactions); } blockMapper.insert(block); log.info("block {} sync succeeded", i); } }
Example 13
Source File: DepositsFetcherTest.java From teku with Apache License 2.0 | 5 votes |
private void mockBlockForEth1Provider(String blockHash, long blockNumber, long timestamp) { EthBlock.Block block = mock(EthBlock.Block.class); when(block.getTimestamp()).thenReturn(BigInteger.valueOf(timestamp)); when(block.getNumber()).thenReturn(BigInteger.valueOf(blockNumber)); when(block.getHash()).thenReturn(blockHash); when(eth1Provider.getGuaranteedEth1Block(blockHash)) .thenReturn(SafeFuture.completedFuture(block)); }
Example 14
Source File: CoreIT.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Test public void testEthGetBlockByNumberReturnHashObjects() throws Exception { EthBlock ethBlock = web3j.ethGetBlockByNumber( DefaultBlockParameter.valueOf(config.validBlock()), false).send(); EthBlock.Block block = ethBlock.getBlock(); assertNotNull(ethBlock.getBlock()); assertThat(block.getNumber(), equalTo(config.validBlock())); assertThat(block.getTransactions().size(), equalTo(config.validBlockTransactionCount().intValue())); }
Example 15
Source File: CoreIT.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Test public void testEthGetBlockByHashReturnFullTransactionObjects() throws Exception { EthBlock ethBlock = web3j.ethGetBlockByHash(config.validBlockHash(), true) .send(); EthBlock.Block block = ethBlock.getBlock(); assertNotNull(ethBlock.getBlock()); assertThat(block.getNumber(), equalTo(config.validBlock())); assertThat(block.getTransactions().size(), equalTo(config.validBlockTransactionCount().intValue())); }
Example 16
Source File: DepositFetcher.java From teku with Apache License 2.0 | 5 votes |
private synchronized void postEventsForBlock( final EthBlock.Block block, final Map<BlockNumberAndHash, List<DepositContract.DepositEventEventResponse>> depositEventsByBlock) { final BigInteger blockNumber = block.getNumber(); final List<DepositContract.DepositEventEventResponse> deposits = depositEventsByBlock.get(new BlockNumberAndHash(blockNumber, block.getHash())); checkNotNull(deposits, "Did not find any deposits for block {}", blockNumber); LOG.trace("Successfully fetched deposit events for block: {} ", blockNumber); postDeposits(createDepositFromBlockEvent(block, deposits)); }
Example 17
Source File: MinimumGenesisTimeBlockFinder.java From teku with Apache License 2.0 | 4 votes |
static Boolean isBlockAfterMinGenesis(EthBlock.Block block) { int comparison = compareBlockTimestampToMinGenesisTime(block); // If block timestamp is greater than min genesis time, // min genesis block must be in the future return comparison > 0; }
Example 18
Source File: ErrorTrackingEth1Provider.java From teku with Apache License 2.0 | 4 votes |
@Override public SafeFuture<EthBlock.Block> getGuaranteedEth1Block(final UnsignedLong blockNumber) { return logStatus(delegate.getGuaranteedEth1Block(blockNumber)); }
Example 19
Source File: Web3jEth1Provider.java From teku with Apache License 2.0 | 4 votes |
private SafeFuture<EthBlock.Block> getEth1Block(final DefaultBlockParameter blockParameter) { return sendAsync(web3j.ethGetBlockByNumber(blockParameter, false)) .thenApply(EthBlock::getBlock); }
Example 20
Source File: ErrorTrackingEth1Provider.java From teku with Apache License 2.0 | 4 votes |
@Override public SafeFuture<EthBlock.Block> getEth1Block(final UnsignedLong blockNumber) { return logStatus(delegate.getEth1Block(blockNumber)); }