Java Code Examples for org.web3j.protocol.core.DefaultBlockParameterName#LATEST

The following examples show how to use org.web3j.protocol.core.DefaultBlockParameterName#LATEST . 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: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
public static void observeContractEvent(Web3j web3j,
                                        String contractEventName,
                                        String contractAddress,
                                        List<TypeReference<?>> indexedParameters,
                                        List<TypeReference<?>> nonIndexedParameters,
                                        String eventReturnType,
                                        rx.functions.Action1 action1) {

    Event event = new Event(contractEventName,
                            indexedParameters,
                            nonIndexedParameters);

    EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST,
                                     DefaultBlockParameterName.LATEST,
                                     contractAddress);

    filter.addSingleTopic(EventEncoder.encode(event));

    Class<Type> type = (Class<Type>) AbiTypes.getType(eventReturnType);
    TypeReference<Type> typeRef = TypeReference.create(type);

    web3j.ethLogObservable(filter).subscribe(action1);
}
 
Example 2
Source File: EventFilterIT.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private List<EthLog.LogResult> createFilterForEvent(
        String encodedEventSignature, String contractAddress) throws Exception {
    EthFilter ethFilter = new EthFilter(
            DefaultBlockParameterName.EARLIEST,
            DefaultBlockParameterName.LATEST,
            contractAddress
    );

    ethFilter.addSingleTopic(encodedEventSignature);

    EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
    return ethLog.getLogs();
}
 
Example 3
Source File: RequestTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testParityListAccountsWithAccountOffsetWithBlockTag() throws Exception {
    BigInteger maxQuantityReturned = BigInteger.valueOf(100);
    DefaultBlockParameter blockParameter = DefaultBlockParameterName.LATEST;
    web3j.parityListAccounts(maxQuantityReturned,
            "0x407d73d8a49eeb85d32cf465507dd71d507100c1", blockParameter).send();

    //CHECKSTYLE:OFF
    verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
            + "\"params\":[100,\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"latest\"],\"id\":1}");
    //CHECKSTYLE:ON
}
 
Example 4
Source File: Web3jService.java    From eventeum with Apache License 2.0 5 votes vote down vote up
/**
 * {inheritDoc}
 */
@Override
public FilterSubscription registerEventListener(
        ContractEventFilter eventFilter, ContractEventListener eventListener) {
    log.debug("Registering event filter for event: {}", eventFilter.getId());
    final ContractEventSpecification eventSpec = eventFilter.getEventSpecification();

    final BigInteger startBlock = getStartBlockForEventFilter(eventFilter);

    EthFilter ethFilter = new EthFilter(
            new DefaultBlockParameterNumber(startBlock),
            DefaultBlockParameterName.LATEST, eventFilter.getContractAddress());

    if (eventFilter.getEventSpecification() != null) {
        ethFilter = ethFilter.addSingleTopic(Web3jUtil.getSignature(eventSpec));
    }

    final Flowable<Log> flowable = web3j.ethLogFlowable(ethFilter);

    final Disposable sub = flowable.subscribe(theLog -> {
        asyncTaskService.execute(ExecutorNameFactory.build(EVENT_EXECUTOR_NAME, eventFilter.getNode()), () -> {
            log.debug("Dispatching log: {}", theLog);
            eventListener.onEvent(
                    eventDetailsFactory.createEventDetails(eventFilter, theLog));
        });
    });

    if (sub.isDisposed()) {
        //There was an error subscribing
        throw new BlockchainException(String.format(
                "Failed to subcribe for filter %s.  The subscription is disposed.", eventFilter.getId()));
    }

    return new FilterSubscription(eventFilter, sub, startBlock);
}
 
Example 5
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void getBalance(final String address, final Callback<BigDecimal> callback) {
    if (web3jConnection != null && connectionAvailable) {
        BalanceRequestTask task = new BalanceRequestTask(address, DefaultBlockParameterName.LATEST, callback);
        task.execute();
    } else {
        provideConnection(new ConnectionCallback() {
            @Override
            public void onFinish() {
                getBalance(address, callback);
            }
        });
    }
}
 
Example 6
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void getBalance(final String address, final Callback<BigDecimal> callback) {
    if (web3jConnection != null && connectionAvailable) {
        BalanceRequestTask task = new BalanceRequestTask(address, DefaultBlockParameterName.LATEST, callback);
        task.execute();
    } else {
        provideConnection(new ConnectionCallback() {
            @Override
            public void onFinish() {
                getBalance(address, callback);
            }
        });
    }
}
 
Example 7
Source File: EthereumNetworkManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void getBalance(final String address, final Callback<BigDecimal> callback) {
    if (web3jConnection != null && connectionAvailable) {
        BalanceRequestTask task = new BalanceRequestTask(address, DefaultBlockParameterName.LATEST, callback);
        task.execute();
    } else {
        provideConnection(new ConnectionCallback() {
            @Override
            public void onFinish() {
                getBalance(address, callback);
            }
        });
    }
}
 
Example 8
Source File: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
public static void observeContractEvent(Web3j web3j,
                                        String contractEventName,
                                        String contractAddress,
                                        List<TypeReference<?>> indexedParameters,
                                        List<TypeReference<?>> nonIndexedParameters,
                                        String eventReturnType,
                                        KieSession kieSession,
                                        String signalName,
                                        boolean doAbortOnUpdate,
                                        WorkItemManager workItemManager,
                                        WorkItem workItem) {

    Event event = new Event(contractEventName,
                            indexedParameters,
                            nonIndexedParameters);

    EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST,
                                     DefaultBlockParameterName.LATEST,
                                     contractAddress);

    filter.addSingleTopic(EventEncoder.encode(event));

    Class<Type> type = (Class<Type>) AbiTypes.getType(eventReturnType);
    TypeReference<Type> typeRef = TypeReference.create(type);

    web3j.ethLogObservable(filter).subscribe(
            eventTrigger -> {
                kieSession.signalEvent(signalName,
                                       FunctionReturnDecoder.decode(
                                               eventTrigger.getData(),
                                               Arrays.asList(typeRef)).get(0).getValue());
                if (doAbortOnUpdate) {
                    workItemManager.completeWorkItem(workItem.getId(),
                                                     null);
                }
            }
    );
}
 
Example 9
Source File: EventFilterIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
private List<EthLog.LogResult> createFilterForEvent(
        String encodedEventSignature, String contractAddress) throws Exception {
    EthFilter ethFilter =
            new EthFilter(
                    DefaultBlockParameterName.EARLIEST,
                    DefaultBlockParameterName.LATEST,
                    contractAddress);

    ethFilter.addSingleTopic(encodedEventSignature);

    EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
    return ethLog.getLogs();
}
 
Example 10
Source File: RequestTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testParityListAccountsWithAccountOffsetWithBlockTag() throws Exception {
    BigInteger maxQuantityReturned = BigInteger.valueOf(100);
    DefaultBlockParameter blockParameter = DefaultBlockParameterName.LATEST;
    web3j.parityListAccounts(
                    maxQuantityReturned,
                    "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
                    blockParameter)
            .send();

    verifyResult(
            "{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
                    + "\"params\":[100,\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"latest\"],\"id\":1}");
}
 
Example 11
Source File: Web3jEth1Provider.java    From teku with Apache License 2.0 4 votes vote down vote up
@Override
public SafeFuture<EthBlock.Block> getLatestEth1Block() {
  DefaultBlockParameter blockParameter = DefaultBlockParameterName.LATEST;
  return getEth1Block(blockParameter);
}