Skip to content

Commit

Permalink
Merge pull request #7 from adridadou/develop
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
Penait1 authored Oct 7, 2019
2 parents 97ad364 + 77234a3 commit 130cd1a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.adridadou.ethereum.propeller;

import org.adridadou.ethereum.propeller.converters.future.FutureConverter;
import org.adridadou.ethereum.propeller.event.BlockInfo;
import org.adridadou.ethereum.propeller.event.EthereumEventHandler;
import org.adridadou.ethereum.propeller.exception.EthereumApiException;
import org.adridadou.ethereum.propeller.service.CryptoProvider;
Expand Down Expand Up @@ -251,7 +252,6 @@ public EthereumEventHandler events() {
return ethereumProxy.events();
}

/**
/**
* Returns the current best block number
* @return The best block number
Expand All @@ -260,6 +260,26 @@ public long getCurrentBlockNumber() {
return ethereumProxy.getCurrentBlockNumber();
}

/**
* Returns block for provided blocknumber
*
* @param blockNumber The block number
* @return The block if found
*/
public Optional<BlockInfo> getBlock(long blockNumber) {
return ethereumProxy.getBlock(blockNumber);
}

/*
* Returns block for provided blockhash
*
* @param blockHash The block number
* @return The block if found
*/
public Optional<BlockInfo> getBlock(EthHash blockHash) {
return ethereumProxy.getBlock(blockHash);
}

/**
* Sends ether
* @param fromAccount The account that sends ether
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ EthValue getBalance(final EthAddress address) {
return ethereum.getBalance(address);
}

Optional<BlockInfo> getBlock(long blockNumber) {
return this.ethereum.getBlock(blockNumber);
}

Optional<BlockInfo> getBlock(EthHash blockHash) {
return this.ethereum.getBlock(blockHash);
}

private void increasePendingTransactionCounter(EthAddress address, EthHash hash) {
Set<EthHash> hashes = pendingTransactions.computeIfAbsent(address, (key) -> Collections.synchronizedSet(new HashSet<>()));
hashes.add(hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import org.adridadou.ethereum.propeller.values.TransactionReceipt;

import java.math.BigInteger;
import java.util.List;

public class BlockInfo {
public final long blockNumber;
public final long timestamp;
public final List<TransactionReceipt> receipts;

public BlockInfo(long blockNumber, List<TransactionReceipt> receipts) {
public BlockInfo(long blockNumber, long timestamp, List<TransactionReceipt> receipts) {
this.blockNumber = blockNumber;
this.timestamp = timestamp;
this.receipts = receipts;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.adridadou.ethereum.propeller.rpc;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -166,12 +167,12 @@ BlockInfo toBlockInfo(EthBlock ethBlock) {
List<TransactionReceipt> receiptList = receipts.entrySet().stream()
.map(entry -> toReceipt(txObjects.get(entry.getKey()), entry.getValue())).collect(Collectors.toList());

return new BlockInfo(block.getNumber().longValue(), receiptList);
return new BlockInfo(block.getNumber().longValue(), block.getTimestamp().longValue(), receiptList);
} catch (Throwable ex) {
logger.error("error while converting to block info", ex);
return new BlockInfo(block.getNumber().longValue(), Collections.emptyList());
return new BlockInfo(block.getNumber().longValue(), block.getTimestamp().longValue(), Collections.emptyList());
}
}).orElseGet(() -> new BlockInfo(-1, new ArrayList<>()));
}).orElseGet(() -> new BlockInfo(-1, 0, new ArrayList<>()));
}

private TransactionReceipt toReceipt(Transaction tx, org.web3j.protocol.core.methods.response.TransactionReceipt receipt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static org.adridadou.ethereum.propeller.values.TransactionReceipt toReceipt(Tran
@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
EthHash blockHash = EthHash.of(block.getHash());
eventHandler.onBlock(new BlockInfo(block.getNumber(), receipts.stream()
eventHandler.onBlock(new BlockInfo(block.getNumber(), block.getTimestamp(), receipts.stream()
.map(tx -> EthJEventListener.toReceipt(tx, blockHash))
.collect(Collectors.toList())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private ECKey getKey(CryptoProvider cryptoProvider) {
}

BlockInfo toBlockInfo(Block block) {
return new BlockInfo(block.getNumber(), block.getTransactionsList().stream()
return new BlockInfo(block.getNumber(), block.getTimestamp(), block.getTransactionsList().stream()
.map(tx -> this.toReceipt(tx, EthHash.of(block.getHash()))).collect(Collectors.toList()));
}

Expand Down

0 comments on commit 130cd1a

Please sign in to comment.