org.web3j.protocol.core.methods.response.Log Java Examples

The following examples show how to use org.web3j.protocol.core.methods.response.Log. 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<ABIChangedEventResponse> aBIChangedEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("ABIChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Uint256>() {}),
            Arrays.<TypeReference<?>>asList());
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, ABIChangedEventResponse>() {
        @Override
        public ABIChangedEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            ABIChangedEventResponse typedResponse = new ABIChangedEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.contentType = (BigInteger) eventValues.getIndexedValues().get(1).getValue();
            return typedResponse;
        }
    });
}
 
Example #2
Source File: DelegateContract.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 *  获得解除委托时所提取的委托收益(当减持/撤销委托成功时调用)
 *
 * @param transactionReceipt
 * @return
 * @throws TransactionException
 */
public BigInteger decodeUnDelegateLog(TransactionReceipt transactionReceipt) throws TransactionException {
    List<Log> logs = transactionReceipt.getLogs();
    if(logs==null||logs.isEmpty()){
        throw new TransactionException("TransactionReceipt logs is empty");
    }

    String logData = logs.get(0).getData();
    if(null == logData || "".equals(logData) ){
        throw new TransactionException("TransactionReceipt logs[0].data is empty");
    }

    RlpList rlp = RlpDecoder.decode(Numeric.hexStringToByteArray(logData));
    List<RlpType> rlpList = ((RlpList)(rlp.getValues().get(0))).getValues();
    String decodedStatus = new String(((RlpString)rlpList.get(0)).getBytes());
    int statusCode = Integer.parseInt(decodedStatus);

    if(statusCode != ErrorCode.SUCCESS){
        throw new TransactionException("TransactionResponse code is 0");
    }

    return  ((RlpString)((RlpList)RlpDecoder.decode(((RlpString)rlpList.get(1)).getBytes())).getValues().get(0)).asPositiveBigInteger();
}
 
Example #3
Source File: Contract.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public static EventValues staticExtractEventParameters(
        Event event, Log log) {

    List<String> topics = log.getTopics();
    String encodedEventSignature = EventEncoder.encode(event);
    if (!topics.get(0).equals(encodedEventSignature)) {
        return null;
    }

    List<Type> indexedValues = new ArrayList<>();
    List<Type> nonIndexedValues = FunctionReturnDecoder.decode(
            log.getData(), event.getNonIndexedParameters());

    List<TypeReference<Type>> indexedParameters = event.getIndexedParameters();
    for (int i = 0; i < indexedParameters.size(); i++) {
        Type value = FunctionReturnDecoder.decodeIndexedValue(
                topics.get(i + 1), indexedParameters.get(i));
        indexedValues.add(value);
    }
    return new EventValues(indexedValues, nonIndexedValues);
}
 
Example #4
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 #5
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 #6
Source File: ContractTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore
public void testProcessEvent() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    Log log = new Log();
    log.setTopics(Arrays.asList(
            // encoded function
            "0xfceb437c298f40d64702ac26411b2316e79f3c28ffa60edfc891ad4fc8ab82ca",
            // indexed value
            "0000000000000000000000003d6cb163f7c72d20b0fcd6baae5889329d138a4a"));
    // non-indexed value
    log.setData("0000000000000000000000000000000000000000000000000000000000000001");

    transactionReceipt.setLogs(Arrays.asList(log));

    EventValues eventValues = contract.processEvent(transactionReceipt).get(0);

    assertThat(eventValues.getIndexedValues(),
            equalTo(singletonList(
                    new Address("0x3d6cb163f7c72d20b0fcd6baae5889329d138a4a"))));
    assertThat(eventValues.getNonIndexedValues(),
            equalTo(singletonList(new Uint256(BigInteger.ONE))));
}
 
Example #7
Source File: ContractTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testProcessEvent() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    Log log = new Log();
    log.setTopics(Arrays.asList(
            // encoded function
            "0xfceb437c298f40d64702ac26411b2316e79f3c28ffa60edfc891ad4fc8ab82ca",
            // indexed value
            "0000000000000000000000003d6cb163f7c72d20b0fcd6baae5889329d138a4a"));
    // non-indexed value
    log.setData("0000000000000000000000000000000000000000000000000000000000000001");

    transactionReceipt.setLogs(Arrays.asList(log));

    EventValues eventValues = contract.processEvent(transactionReceipt).get(0);

    assertThat(eventValues.getIndexedValues(),
            equalTo(singletonList(
                    new Address("0x3d6cb163f7c72d20b0fcd6baae5889329d138a4a"))));
    assertThat(eventValues.getNonIndexedValues(),
            equalTo(singletonList(new Uint256(BigInteger.ONE))));
}
 
Example #8
Source File: ENS.java    From etherscan-explorer with GNU General Public License v3.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<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, TransferEventResponse>() {
        @Override
        public TransferEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            TransferEventResponse typedResponse = new TransferEventResponse();
            typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.owner = (String) eventValues.getNonIndexedValues().get(0).getValue();
            return typedResponse;
        }
    });
}
 
Example #9
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 #10
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 #11
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 #12
Source File: EventEmitter.java    From eventeum with Apache License 2.0 6 votes vote down vote up
public Flowable<DummyEventNotOrderedEventResponse> dummyEventNotOrderedEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, DummyEventNotOrderedEventResponse>() {
        @Override
        public DummyEventNotOrderedEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(DUMMYEVENTNOTORDERED_EVENT, log);
            DummyEventNotOrderedEventResponse typedResponse = new DummyEventNotOrderedEventResponse();
            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 #13
Source File: TransactionFactory.java    From asf-sdk with GNU General Public License v3.0 6 votes vote down vote up
public static Transaction fromEthGetTransactionReceipt(
    EthGetTransactionReceipt ethGetTransactionReceipt) {
  TransactionReceipt transactionReceipt = ethGetTransactionReceipt.getTransactionReceipt();

  String hash = transactionReceipt.getTransactionHash();
  String from = transactionReceipt.getFrom();
  Log log = transactionReceipt.getLogs()
      .get(0);
  String to = log.getAddress();
  String value = extractValueFromEthGetTransactionReceipt(log.getData());
  Status status = parseStatus(transactionReceipt.getStatus());
  String contractAddress = ethGetTransactionReceipt.getTransactionReceipt()
      .getTo();

  return new Transaction(hash, from, to, value, status);
}
 
Example #14
Source File: EventEmitter.java    From eventeum with Apache License 2.0 6 votes vote down vote up
public Flowable<DummyEventAdditionalTypesEventResponse> dummyEventAdditionalTypesEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, DummyEventAdditionalTypesEventResponse>() {
        @Override
        public DummyEventAdditionalTypesEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(DUMMYEVENTADDITIONALTYPES_EVENT, log);
            DummyEventAdditionalTypesEventResponse typedResponse = new DummyEventAdditionalTypesEventResponse();
            typedResponse.log = log;
            typedResponse.uint16Value = (BigInteger) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.int64Value = (BigInteger) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.addressArray = (List<String>) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.byteValue = (byte[]) eventValues.getNonIndexedValues().get(1).getValue();
            typedResponse.boolValue = (Boolean) eventValues.getNonIndexedValues().get(2).getValue();
            return typedResponse;
        }
    });
}
 
Example #15
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 #16
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 #17
Source File: AssetDefinitionService.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private void processLogs(EventDefinition ev, List<EthLog.LogResult> logs)
{
    if (logs.size() == 0) return; //early return
    int chainId = ev.contract.addresses.keySet().iterator().next();
    Web3j web3j = getWeb3jService(chainId);

    for (EthLog.LogResult ethLog : logs)
    {
        String selectVal = eventUtils.getSelectVal(ev, ethLog);
        EthBlock txBlock = eventUtils.getTransactionDetails(((Log)ethLog.get()).getBlockHash(), web3j).blockingGet();

        long blockTime = txBlock.getBlock().getTimestamp().longValue();
        if (eventCallback != null) eventCallback.receivedEvent(ev.attributeName, ev.parentAttribute.getSyntaxVal(selectVal), blockTime, chainId);
        storeEventValue(ev, ethLog, ev.parentAttribute, blockTime, selectVal);
    }
}
 
Example #18
Source File: JsonRpc2_0BesuRx.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<Log> privLogFlowable(
        String privacyGroupId,
        org.web3j.protocol.core.methods.request.EthFilter ethFilter,
        long pollingInterval) {
    return Flowable.create(
            subscriber -> {
                PrivateLogFilter logFilter =
                        new PrivateLogFilter(
                                besu, subscriber::onNext, privacyGroupId, ethFilter);

                run(logFilter, subscriber, pollingInterval);
            },
            BackpressureStrategy.BUFFER);
}
 
Example #19
Source File: EventUtils.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
public String getTopicVal(EventDefinition ev, EthLog.LogResult ethLog)
{
    String topicVal = "";
    final Event resolverEvent = generateEventFunction(ev);
    final EventValues eventValues = staticExtractEventParameters(resolverEvent, (Log)ethLog.get());
    String filterTopic = ev.getFilterTopicIndex();
    int topicIndex = ev.getTopicIndex(filterTopic);

    topicVal = getValueFromParams(eventValues.getIndexedValues(), topicIndex);

    return topicVal;
}
 
Example #20
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 #21
Source File: LogsFilter.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(List<LogResult> logResults) {
    List<Log> logs = new ArrayList<>(logResults.size());

    for (EthLog.LogResult logResult : logResults) {
        if (!(logResult instanceof EthLog.LogObject)) {
            throw new FilterException(
                    "Unexpected result type: " + logResult.get() + " required LogObject");
        }

        logs.add(((EthLog.LogObject) logResult).get());
    }

    callback.onEvent(logs);
}
 
Example #22
Source File: EqualsVerifierResponseTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLog() {
    EqualsVerifier.forClass(Log.class)
            .suppress(Warning.NONFINAL_FIELDS)
            .suppress(Warning.STRICT_INHERITANCE)
            .verify();
}
 
Example #23
Source File: ContractTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testExtractEventParametersWithLogGivenATransactionReceipt() {

    final java.util.function.Function<String, Event> eventFactory = name ->
            new Event(name, emptyList(), emptyList());

    final BiFunction<Integer, Event, Log> logFactory = (logIndex, event) ->
            new Log(false, "" + logIndex, "0", "0x0", "0x0", "0", "0x" + logIndex, "", "",
                    singletonList(EventEncoder.encode(event)));

    final Event testEvent1 = eventFactory.apply("TestEvent1");
    final Event testEvent2 = eventFactory.apply("TestEvent2");

    final List<Log> logs = Arrays.asList(
            logFactory.apply(0, testEvent1),
            logFactory.apply(1, testEvent2)
    );

    final TransactionReceipt transactionReceipt = new TransactionReceipt();
    transactionReceipt.setLogs(logs);

    final List<Contract.EventValuesWithLog> eventValuesWithLogs1 =
            contract.extractEventParametersWithLog(testEvent1, transactionReceipt);

    assertEquals(eventValuesWithLogs1.size(), 1);
    assertEquals(eventValuesWithLogs1.get(0).getLog(), logs.get(0));

    final List<Contract.EventValuesWithLog> eventValuesWithLogs2 =
            contract.extractEventParametersWithLog(testEvent2, transactionReceipt);

    assertEquals(eventValuesWithLogs2.size(), 1);
    assertEquals(eventValuesWithLogs2.get(0).getLog(), logs.get(1));
}
 
Example #24
Source File: JsonRpc2_0Rx.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public Observable<Log> ethLogObservable(
        org.web3j.protocol.core.methods.request.EthFilter ethFilter, long pollingInterval) {
    return Observable.create((Subscriber<? super Log> subscriber) -> {
        LogFilter logFilter = new LogFilter(
                web3j, subscriber::onNext, ethFilter);

        run(logFilter, subscriber, pollingInterval);
    });
}
 
Example #25
Source File: DepositContract.java    From teku with Apache License 2.0 5 votes vote down vote up
public Flowable<DepositEventEventResponse> depositEventEventFlowable(EthFilter filter) {
  return web3j
      .ethLogFlowable(filter)
      .map(
          new Function<Log, DepositEventEventResponse>() {
            @Override
            public DepositEventEventResponse apply(Log log) {
              return convertLogToDepositEventEventResponse(log);
            }
          });
}
 
Example #26
Source File: ENS.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<NewOwnerEventResponse> newOwnerEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, NewOwnerEventResponse>() {
        @Override
        public NewOwnerEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(NEWOWNER_EVENT, log);
            NewOwnerEventResponse typedResponse = new NewOwnerEventResponse();
            typedResponse.log = log;
            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 #27
Source File: HumanStandardTokenIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
private void sendApproveTransaction(
        Credentials credentials, String spender, BigInteger value, String contractAddress)
        throws Exception {
    Function function = approve(spender, value);
    String functionHash = execute(credentials, function, contractAddress);

    TransactionReceipt transferTransactionReceipt = waitForTransactionReceipt(functionHash);
    assertEquals(transferTransactionReceipt.getTransactionHash(), (functionHash));

    List<Log> logs = transferTransactionReceipt.getLogs();
    assertFalse(logs.isEmpty());
    Log log = logs.get(0);

    // verify the event was called with the function parameters
    List<String> topics = log.getTopics();
    assertEquals(topics.size(), (3));

    // event Transfer(address indexed _from, address indexed _to, uint256 _value);
    Event event = approvalEvent();

    // check function signature - we only have a single topic our event signature,
    // there are no indexed parameters in this example
    String encodedEventSignature = EventEncoder.encode(event);
    assertEquals(topics.get(0), (encodedEventSignature));
    assertEquals(new Address(topics.get(1)), (new Address(credentials.getAddress())));
    assertEquals(new Address(topics.get(2)), (new Address(spender)));

    // verify our two event parameters
    List<Type> results =
            FunctionReturnDecoder.decode(log.getData(), event.getNonIndexedParameters());
    assertEquals(results, (Collections.singletonList(new Uint256(value))));
}
 
Example #28
Source File: PrivateTransactionReceipt.java    From web3j with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public PrivateTransactionReceipt(
        @JsonProperty(value = "contractAddress") final String contractAddress,
        @JsonProperty(value = "from") final String from,
        @JsonProperty(value = "to") final String to,
        @JsonProperty(value = "output") final String output,
        @JsonProperty(value = "logs") final List<Log> logs,
        @JsonProperty(value = "commitmentHash") final String commitmentHash,
        @JsonProperty(value = "transactionHash") final String transactionHash,
        @JsonProperty(value = "privateFrom") final String privateFrom,
        @JsonProperty(value = "privateFor") final ArrayList<String> privateFor,
        @JsonProperty(value = "privacyGroupId") final String privacyGroupId,
        @JsonProperty(value = "status") final String status,
        @JsonProperty(value = "revertReason") final String revertReason) {
    this.contractAddress = contractAddress;
    this.from = from;
    this.to = to;
    this.output = output;
    this.logs = logs;
    this.commitmentHash = commitmentHash;
    this.transactionHash = transactionHash;
    this.privateFrom = privateFrom;
    this.privateFor = privateFor;
    this.privacyGroupId = privacyGroupId;
    this.status = status;
    this.revertReason = revertReason;
}
 
Example #29
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 #30
Source File: Fibonacci.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public Observable<NotifyEventResponse> notifyEventObservable(EthFilter filter) {
    return web3j.ethLogObservable(filter).map(new Func1<Log, NotifyEventResponse>() {
        @Override
        public NotifyEventResponse call(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;
        }
    });
}