org.web3j.protocol.core.methods.request.EthFilter Java Examples

The following examples show how to use org.web3j.protocol.core.methods.request.EthFilter. 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: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<AddrChangedEventResponse> addrChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("AddrChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, AddrChangedEventResponse>() {
        @Override
        public AddrChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            AddrChangedEventResponse typedResponse = new AddrChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.a = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #2
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 #3
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<PubkeyChangedEventResponse> pubkeyChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("PubkeyChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Bytes32>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, PubkeyChangedEventResponse>() {
        @Override
        public PubkeyChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            PubkeyChangedEventResponse typedResponse = new PubkeyChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.x = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.y = (byte[]) eventValues.getNonIndexedValues().get(1).getValue();
            return typedResponse;
        }
    });
}
 
Example #4
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<TextChangedEventResponse> textChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("TextChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Utf8String>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, TextChangedEventResponse>() {
        @Override
        public TextChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            TextChangedEventResponse typedResponse = new TextChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.indexedKey = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.key = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #5
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<NewOwnerEventResponse> newOwnerEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("NewOwner", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NewOwnerEventResponse>() {
        @Override
        public NewOwnerEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NewOwnerEventResponse typedResponse = new NewOwnerEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.label = (byte[]) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.owner = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #6
Source File: TokenERC20.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 6 votes vote down vote up
public Observable<TransferEventResponse> transferEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("Transfer", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, TransferEventResponse>() {
        @Override
        public TransferEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            TransferEventResponse typedResponse = new TransferEventResponse();
            typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #7
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<NewResolverEventResponse> newResolverEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("NewResolver", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NewResolverEventResponse>() {
        @Override
        public NewResolverEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NewResolverEventResponse typedResponse = new NewResolverEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.resolver = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #8
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<NewTTLEventResponse> newTTLEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("NewTTL", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint64>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NewTTLEventResponse>() {
        @Override
        public NewTTLEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NewTTLEventResponse typedResponse = new NewTTLEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.ttl = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #9
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Observable<ContentChangedEventResponse> contentChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("ContentChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, ContentChangedEventResponse>() {
        @Override
        public ContentChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            ContentChangedEventResponse typedResponse = new ContentChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.hash = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #10
Source File: EventEmitterAcceptanceTest.java    From besu with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDeployContractAndAllowLookupOfValuesAndEmittingEvents() throws Exception {
  final EventEmitter eventEmitter =
      node.execute(contractTransactions.createSmartContract(EventEmitter.class));

  final Flowable<StoredEventResponse> storedEventResponseObservable =
      eventEmitter.storedEventFlowable(new EthFilter());

  final AtomicBoolean subscriptionReceived = new AtomicBoolean(false);

  final Disposable subscription =
      storedEventResponseObservable.subscribe(
          storedEventResponse -> {
            subscriptionReceived.set(true);
            assertThat(storedEventResponse._amount).isEqualTo(BigInteger.valueOf(12));
          });

  assertThat(subscription.isDisposed()).isFalse();

  final TransactionReceipt receipt = eventEmitter.store(BigInteger.valueOf(12)).send();

  assertThat(receipt).isNotNull();
  assertThat(eventEmitter.value().send()).isEqualTo(BigInteger.valueOf(12));
  assertThat(subscriptionReceived.get()).isTrue();
}
 
Example #11
Source File: DefaultOnChainPrivacyGroupManagementContract.java    From besu with Apache License 2.0 6 votes vote down vote up
public Flowable<ParticipantAddedEventResponse> participantAddedEventFlowable(EthFilter filter) {
  return web3j
      .ethLogFlowable(filter)
      .map(
          new Function<Log, ParticipantAddedEventResponse>() {
            @Override
            public ParticipantAddedEventResponse apply(Log log) {
              Contract.EventValuesWithLog eventValues =
                  extractEventParametersWithLog(PARTICIPANTADDED_EVENT, log);
              ParticipantAddedEventResponse typedResponse = new ParticipantAddedEventResponse();
              typedResponse.log = log;
              typedResponse.adminAdded =
                  (Boolean) eventValues.getNonIndexedValues().get(0).getValue();
              typedResponse.account =
                  (byte[]) eventValues.getNonIndexedValues().get(1).getValue();
              typedResponse.message =
                  (String) eventValues.getNonIndexedValues().get(2).getValue();
              return typedResponse;
            }
          });
}
 
Example #12
Source File: CrossContractReader.java    From besu with Apache License 2.0 6 votes vote down vote up
public Flowable<NewEventEmitterEventResponse> newEventEmitterEventFlowable(
    final EthFilter filter) {
  return web3j
      .ethLogFlowable(filter)
      .map(
          new io.reactivex.functions.Function<Log, NewEventEmitterEventResponse>() {
            @Override
            public NewEventEmitterEventResponse apply(final Log log) {
              Contract.EventValuesWithLog eventValues =
                  extractEventParametersWithLog(NEWEVENTEMITTER_EVENT, log);
              NewEventEmitterEventResponse typedResponse = new NewEventEmitterEventResponse();
              typedResponse.log = log;
              typedResponse.contractAddress =
                  (String) eventValues.getNonIndexedValues().get(0).getValue();
              return typedResponse;
            }
          });
}
 
Example #13
Source File: EventEmitter.java    From eventeum with Apache License 2.0 6 votes vote down vote up
public Flowable<DummyEventEventResponse> dummyEventEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, DummyEventEventResponse>() {
        @Override
        public DummyEventEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(DUMMYEVENT_EVENT, log);
            DummyEventEventResponse typedResponse = new DummyEventEventResponse();
            typedResponse.log = log;
            typedResponse.indexedBytes = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.indexedAddress = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.uintValue = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.stringValue = (String) eventValues.getNonIndexedValues().get(1).getValue();
            typedResponse.enumValue = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
            return typedResponse;
        }
    });
}
 
Example #14
Source File: EventEmitter.java    From besu with Apache License 2.0 6 votes vote down vote up
public Flowable<StoredEventResponse> storedEventFlowable(final EthFilter filter) {
  return web3j
      .ethLogFlowable(filter)
      .map(
          new io.reactivex.functions.Function<Log, StoredEventResponse>() {
            @Override
            public StoredEventResponse apply(final Log log) {
              Contract.EventValuesWithLog eventValues =
                  extractEventParametersWithLog(STORED_EVENT, log);
              StoredEventResponse typedResponse = new StoredEventResponse();
              typedResponse.log = log;
              typedResponse._to = (String) eventValues.getNonIndexedValues().get(0).getValue();
              typedResponse._amount =
                  (BigInteger) eventValues.getNonIndexedValues().get(1).getValue();
              return typedResponse;
            }
          });
}
 
Example #15
Source File: ComplexStorage.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<AccessEventResponse> accessEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new Function<Log, AccessEventResponse>() {
        @Override
        public AccessEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(ACCESS_EVENT, log);
            AccessEventResponse typedResponse = new AccessEventResponse();
            typedResponse.log = log;
            typedResponse._address = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse._foo = (Foo) eventValues.getNonIndexedValues().get(0);
            typedResponse._bar = (Bar) eventValues.getNonIndexedValues().get(1);
            return typedResponse;
        }
    });
}
 
Example #16
Source File: ERC721.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<ApprovalEventResponse> approvalEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ApprovalEventResponse>() {
        @Override
        public ApprovalEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(APPROVAL_EVENT, log);
            ApprovalEventResponse typedResponse = new ApprovalEventResponse();
            typedResponse.log = log;
            typedResponse._owner = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse._approved = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse._tokenId = (BigInteger) eventValues.getIndexedValues().get(2).getValue();
            return typedResponse;
        }
    });
}
 
Example #17
Source File: ERC721.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<ApprovalForAllEventResponse> approvalForAllEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ApprovalForAllEventResponse>() {
        @Override
        public ApprovalForAllEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(APPROVALFORALL_EVENT, log);
            ApprovalForAllEventResponse typedResponse = new ApprovalForAllEventResponse();
            typedResponse.log = log;
            typedResponse._owner = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse._operator = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse._approved = (Boolean) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #18
Source File: RequestTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testEthGetLogsWithNumericBlockRange() throws Exception {
    web3j.ethGetLogs(
                    new EthFilter(
                            DefaultBlockParameter.valueOf(Numeric.toBigInt("0xe8")),
                            DefaultBlockParameter.valueOf("latest"),
                            ""))
            .send();

    verifyResult(
            "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\","
                    + "\"params\":[{\"topics\":[],\"fromBlock\":\"0xe8\","
                    + "\"toBlock\":\"latest\",\"address\":[\"\"]}],\"id\":1}");
}
 
Example #19
Source File: JsonRpc2_0Besu.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, org.web3j.protocol.core.methods.response.EthFilter> privNewFilter(
        String privacyGroupId, org.web3j.protocol.core.methods.request.EthFilter ethFilter) {
    return new Request<>(
            "priv_newFilter",
            Arrays.asList(privacyGroupId, ethFilter),
            web3jService,
            org.web3j.protocol.core.methods.response.EthFilter.class);
}
 
Example #20
Source File: PublicResolver.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<ContentChangedEventResponse> contentChangedEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ContentChangedEventResponse>() {
        @Override
        public ContentChangedEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(CONTENTCHANGED_EVENT, log);
            ContentChangedEventResponse typedResponse = new ContentChangedEventResponse();
            typedResponse.log = log;
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.hash = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #21
Source File: HumanStandardToken.java    From web3j-quorum with Apache License 2.0 5 votes vote down vote up
public Flowable<ApprovalEventResponse> approvalEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ApprovalEventResponse>() {
        @Override
        public ApprovalEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(APPROVAL_EVENT, log);
            ApprovalEventResponse typedResponse = new ApprovalEventResponse();
            typedResponse.log = log;
            typedResponse._owner = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse._spender = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #22
Source File: PublicResolver.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<ABIChangedEventResponse> aBIChangedEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ABIChangedEventResponse>() {
        @Override
        public ABIChangedEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(ABICHANGED_EVENT, log);
            ABIChangedEventResponse typedResponse = new ABIChangedEventResponse();
            typedResponse.log = log;
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.contentType = (BigInteger) eventValues.getIndexedValues().get(1).getValue();
            return typedResponse;
        }
    });
}
 
Example #23
Source File: ERC20.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<TransferEventResponse> transferEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, TransferEventResponse>() {
        @Override
        public TransferEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(TRANSFER_EVENT, log);
            TransferEventResponse typedResponse = new TransferEventResponse();
            typedResponse.log = log;
            typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #24
Source File: Fibonacci.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<NotifyEventResponse> notifyEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, NotifyEventResponse>() {
        @Override
        public NotifyEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(NOTIFY_EVENT, log);
            NotifyEventResponse typedResponse = new NotifyEventResponse();
            typedResponse.log = log;
            typedResponse.input = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.result = (BigInteger) eventValues.getNonIndexedValues().get(1).getValue();
            return typedResponse;
        }
    });
}
 
Example #25
Source File: LogFilterTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogFilter() throws Exception {

    EthLog ethLog =
            objectMapper.readValue(
                    "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":[{\"address\":\"0x2a98c5f40bfa3dee83431103c535f6fae9a8ad38\",\"blockHash\":\"0xd263df878c66b8a08c8509a8f33d6758bc3a1ee3c5ab3c9a765ea981ae9d72e3\",\"blockNumber\":\"0x2865a\",\"data\":\"0x45544855534400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"logIndex\":\"0x0\",\"removed\":false,\"topics\":[\"0x5a690ecd0cb15c1c1fd6b6f8a32df0d4f56cb41a54fea7e94020f013595de796\",\"0x0000000000000000000000000000000000000000000000000000000000000002\",\"0x0000000000000000000000003f37a1c95bbc0aa6bf62e99b30b147e68dee7b43\",\"0x0000000000000000000000000000000000000000000000000000000000000000\"],\"transactionHash\":\"0x9d8a4410204140a8fa7f191b0b1d9526822a87d212ade0b6a3cbd20a6e2ed2e9\",\"transactionIndex\":\"0x0\"},{\"address\":\"0x2a98c5f40bfa3dee83431103c535f6fae9a8ad38\",\"blockHash\":\"0xd263df878c66b8a08c8509a8f33d6758bc3a1ee3c5ab3c9a765ea981ae9d72e3\",\"blockNumber\":\"0x2865a\",\"data\":\"0x0000000000000000000000000000000000000000000000006c93a67534ce4000\",\"logIndex\":\"0x1\",\"removed\":false,\"topics\":[\"0xa9c6cbc4bd352a6940479f6d802a1001550581858b310d7f68f7bea51218cda6\",\"0x4554485553440000000000000000000000000000000000000000000000000000\"],\"transactionHash\":\"0x9d8a4410204140a8fa7f191b0b1d9526822a87d212ade0b6a3cbd20a6e2ed2e9\",\"transactionIndex\":\"0x0\"},{\"address\":\"0x3f37a1c95bbc0aa6bf62e99b30b147e68dee7b43\",\"blockHash\":\"0xd263df878c66b8a08c8509a8f33d6758bc3a1ee3c5ab3c9a765ea981ae9d72e3\",\"blockNumber\":\"0x2865a\",\"data\":\"0x0000000000000000000000000000000000000000000000006c93a67534ce4000\",\"logIndex\":\"0x2\",\"removed\":false,\"topics\":[\"0xa609f6bd4ad0b4f419ddad4ac9f0d02c2b9295c5e6891469055cf73c2b568fff\",\"0x0000000000000000000000003f37a1c95bbc0aa6bf62e99b30b147e68dee7b43\"],\"transactionHash\":\"0x9d8a4410204140a8fa7f191b0b1d9526822a87d212ade0b6a3cbd20a6e2ed2e9\",\"transactionIndex\":\"0x0\"},{\"address\":\"0x870283380c7da544d2b16d3434709874e3ed77cb\",\"blockHash\":\"0xd263df878c66b8a08c8509a8f33d6758bc3a1ee3c5ab3c9a765ea981ae9d72e3\",\"blockNumber\":\"0x2865a\",\"data\":\"0x000000000000000000000000000000000000000000000000000000005853a9f4000000000000000000000000000000000000000000000000000000000000004e\",\"logIndex\":\"0x3\",\"removed\":false,\"topics\":[\"0x9de614b5c45179d41912c87ca7f7af67525f50c10b6b9cea79dc2c12b8d693a3\"],\"transactionHash\":\"0xccf367f7c845de706ccf985a187ea168f9df241d4878780f996aa08a303ad910\",\"transactionIndex\":\"0x1\"},{\"address\":\"0x870283380c7da544d2b16d3434709874e3ed77cb\",\"blockHash\":\"0xd263df878c66b8a08c8509a8f33d6758bc3a1ee3c5ab3c9a765ea981ae9d72e3\",\"blockNumber\":\"0x2865a\",\"data\":\"0x000000000000000000000000000000000000000000000000000000005853aa04000000000000000000000000000000000000000000000000000000000000004e\",\"logIndex\":\"0x4\",\"removed\":false,\"topics\":[\"0x9de614b5c45179d41912c87ca7f7af67525f50c10b6b9cea79dc2c12b8d693a3\"],\"transactionHash\":\"0x83d38a70d55279be43cfb6da97256e438b6f72337be1a0919b349244fe633daa\",\"transactionIndex\":\"0x2\"}]}",
                    EthLog.class);

    runTest(ethLog, web3j.ethLogFlowable(new EthFilter().addSingleTopic("test")));
}
 
Example #26
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 #27
Source File: DepositContract.java    From teku with Apache License 2.0 5 votes vote down vote up
public SafeFuture<List<DepositEventEventResponse>> depositEventInRange(
    DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
  final EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
  filter.addSingleTopic(EventEncoder.encode(DEPOSITEVENT_EVENT));
  return SafeFuture.of(
      web3j
          .ethGetLogs(filter)
          .sendAsync()
          .thenApply(
              logs ->
                  logs.getLogs().stream()
                      .map(log -> (Log) log.get())
                      .map(this::convertLogToDepositEventEventResponse)
                      .collect(Collectors.toList())));
}
 
Example #28
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 #29
Source File: SimpleAuction.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<HighestBidIncreasedEventResponse> highestBidIncreasedEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, HighestBidIncreasedEventResponse>() {
        @Override
        public HighestBidIncreasedEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(HIGHESTBIDINCREASED_EVENT, log);
            HighestBidIncreasedEventResponse typedResponse = new HighestBidIncreasedEventResponse();
            typedResponse.log = log;
            typedResponse.bidder = (String) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(1).getValue();
            return typedResponse;
        }
    });
}
 
Example #30
Source File: EventEmitter.java    From eventeum with Apache License 2.0 5 votes vote down vote up
public Flowable<DummyEventBytes16EventResponse> dummyEventBytes16EventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, DummyEventBytes16EventResponse>() {
        @Override
        public DummyEventBytes16EventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(DUMMYEVENTBYTES16_EVENT, log);
            DummyEventBytes16EventResponse typedResponse = new DummyEventBytes16EventResponse();
            typedResponse.log = log;
            typedResponse.indexedBytes16 = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.bytes16Value = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}