org.web3j.abi.TypeReference Java Examples

The following examples show how to use org.web3j.abi.TypeReference. 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: 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 #2
Source File: EventTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreation() {

    List<TypeReference<?>> parameters =
            Arrays.<TypeReference<?>>asList(
                    new TypeReference<Address>() {}, new TypeReference<Uint256>() {});
    Event event = new Event("testName", parameters);

    assertEquals(event.getName(), "testName");

    Iterator<TypeReference<?>> expectedParameter = parameters.iterator();
    for (TypeReference<?> actualParameter : event.getParameters()) {
        assertEquals(expectedParameter.next(), actualParameter);
    }

    assertEquals(0, event.getIndexedParameters().size());

    for (TypeReference<?> nonIndexedParameter : event.getNonIndexedParameters()) {
        assertEquals(false, nonIndexedParameter.isIndexed());
    }
}
 
Example #3
Source File: ShipIt.java    From web3j with Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple8<String, String, BigInteger, BigInteger, BigInteger, BigInteger, String, byte[]>> shipments(String param0) {
    final Function function = new Function(FUNC_SHIPMENTS, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(param0)), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint8>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Bytes32>() {}));
    return new RemoteCall<Tuple8<String, String, BigInteger, BigInteger, BigInteger, BigInteger, String, byte[]>>(
            new Callable<Tuple8<String, String, BigInteger, BigInteger, BigInteger, BigInteger, String, byte[]>>() {
                @Override
                public Tuple8<String, String, BigInteger, BigInteger, BigInteger, BigInteger, String, byte[]> call() throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple8<String, String, BigInteger, BigInteger, BigInteger, BigInteger, String, byte[]>(
                            (String) results.get(0).getValue(), 
                            (String) results.get(1).getValue(), 
                            (BigInteger) results.get(2).getValue(), 
                            (BigInteger) results.get(3).getValue(), 
                            (BigInteger) results.get(4).getValue(), 
                            (BigInteger) results.get(5).getValue(), 
                            (String) results.get(6).getValue(), 
                            (byte[]) results.get(7).getValue());
                }
            });
}
 
Example #4
Source File: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
public static Object queryExistingContract(Credentials credentials,
                                           Web3j web3j,
                                           String contractAddress,
                                           String contractMethodName,
                                           List<Type> contractMethodInputTypes,
                                           List<TypeReference<?>> contractMethodOutputTypes
) throws Exception {

    Function function = getFunction(contractMethodName,
                                    contractMethodInputTypes,
                                    contractMethodOutputTypes);

    Transaction transaction = Transaction.createEthCallTransaction(credentials.getAddress(),
                                                                   contractAddress,
                                                                   getEncodedFunction(function));

    EthCall response = web3j.ethCall(
            transaction,
            DefaultBlockParameterName.LATEST).sendAsync().get();

    List<Type> responseTypeList = FunctionReturnDecoder.decode(
            response.getValue(),
            function.getOutputParameters());

    if (responseTypeList != null && responseTypeList.size() > 0) {
        return responseTypeList.get(0).getValue();
    } else {
        return null;
    }
}
 
Example #5
Source File: ERC721.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> transferFrom(String _from, String _to, BigInteger _tokenId, BigInteger weiValue) {
    final Function function = new Function(
            FUNC_TRANSFERFROM, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_from), 
            new org.web3j.abi.datatypes.Address(_to), 
            new org.web3j.abi.datatypes.generated.Uint256(_tokenId)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function, weiValue);
}
 
Example #6
Source File: Arrays.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> dynamicReverse(List<BigInteger> input) {
    final Function function = new Function(
            "dynamicReverse", 
            java.util.Arrays.<Type>asList(new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Uint256>(
                    org.web3j.abi.Utils.typeMap(input, org.web3j.abi.datatypes.generated.Uint256.class))), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #7
Source File: HumanStandardToken.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public RemoteCall<BigInteger> allowance(String _owner, String _spender) {
	final Function function = new Function(FUNC_ALLOWANCE,
			Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_owner), new org.web3j.abi.datatypes.Address(_spender)),
			Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
			}));
	return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
 
Example #8
Source File: Ballot.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> delegate(String to) {
    final Function function = new Function(
            FUNC_DELEGATE, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(to)),
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #9
Source File: DefaultOnChainPrivacyGroupManagementContract.java    From besu with Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<byte[]> getVersion() {
  final org.web3j.abi.datatypes.Function function =
      new org.web3j.abi.datatypes.Function(
          FUNC_GETVERSION,
          Arrays.<Type>asList(),
          Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}));
  return executeRemoteCallSingleValueReturn(function, byte[].class);
}
 
Example #10
Source File: PayWages.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> addEmployee(BigInteger _id, BigInteger _status, String _name, String _account) {
	final Function function = new Function(FUNC_ADDEMPLOYEE,
			Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(_id), new org.web3j.abi.datatypes.generated.Uint8(_status),
					new org.web3j.abi.datatypes.Utf8String(_name), new org.web3j.abi.datatypes.Address(_account)),
			Collections.<TypeReference<?>>emptyList());
	return executeRemoteCallTransaction(function);
}
 
Example #11
Source File: HumanStandardToken.java    From web3j-quorum with Apache License 2.0 5 votes vote down vote up
public RemoteCall<BigInteger> allowance(String _owner, String _spender) {
    final Function function = new Function(FUNC_ALLOWANCE,
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_owner),
                    new org.web3j.abi.datatypes.Address(_spender)),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
 
Example #12
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public List<ContentChangedEventResponse> getContentChangedEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("ContentChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<ContentChangedEventResponse> responses = new ArrayList<ContentChangedEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        ContentChangedEventResponse typedResponse = new ContentChangedEventResponse();
        typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.hash = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example #13
Source File: EventEmitter.java    From besu with Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<String> sender() {
  final Function function =
      new Function(
          FUNC_SENDER,
          Arrays.<Type>asList(),
          Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
  return executeRemoteCallSingleValueReturn(function, String.class);
}
 
Example #14
Source File: Greeter.java    From web3j-quorum with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> kill() {
    final Function function = new Function(
            FUNC_KILL,
            Arrays.<Type>asList(),
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #15
Source File: SimpleStorage.java    From besu with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> set(final BigInteger value) {
  final Function function =
      new Function(
          FUNC_SET,
          Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(value)),
          Collections.<TypeReference<?>>emptyList());
  return executeRemoteCallTransaction(function);
}
 
Example #16
Source File: Arrays.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<List> returnArray() {
    final Function function = new Function(FUNC_RETURNARRAY, 
            java.util.Arrays.<Type>asList(), 
            java.util.Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Address>>() {}));
    return new RemoteFunctionCall<List>(function,
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example #17
Source File: EventEmitter.java    From eventeum with Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<TransactionReceipt> emitEventBytes16(byte[] bytes16Value) {
    final Function function = new Function(
            FUNC_EMITEVENTBYTES16, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes16(bytes16Value)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #18
Source File: Ballot.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> giveRightToVote(String voter) {
    final Function function = new Function(
            FUNC_GIVERIGHTTOVOTE, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(voter)),
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #19
Source File: TestnetConfig.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public String encodedEvent() {
    Event event =
            new Event(
                    "Notify",
                    Arrays.asList(
                            new TypeReference<Uint>(true) {}, new TypeReference<Uint>() {}));

    return EventEncoder.encode(event);
}
 
Example #20
Source File: Ballot.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> vote(BigInteger proposal) {
    final Function function = new Function(
            FUNC_VOTE, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(proposal)),
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #21
Source File: HumanStandardToken.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> transfer(String _to, BigInteger _value) {
    final Function function = new Function(
            FUNC_TRANSFER, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_to), 
            new org.web3j.abi.datatypes.generated.Uint256(_value)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #22
Source File: ERC20.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> approve(String _spender, BigInteger _value) {
    final Function function = new Function(
            FUNC_APPROVE, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_spender), 
            new org.web3j.abi.datatypes.generated.Uint256(_value)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #23
Source File: PublicResolver.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public List<NameChangedEventResponse> getNameChangedEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("NameChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<NameChangedEventResponse> responses = new ArrayList<NameChangedEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        NameChangedEventResponse typedResponse = new NameChangedEventResponse();
        typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.name = (String) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example #24
Source File: ERC20.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<BigInteger> allowance(String _owner, String _spender) {
    final Function function = new Function(FUNC_ALLOWANCE, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_owner), 
            new org.web3j.abi.datatypes.Address(_spender)), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
 
Example #25
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 5 votes vote down vote up
private static CodeBlock buildVariableLengthEventInitializer(
        String eventName, List<NamedTypeName> parameterTypes) {

    List<Object> objects = new ArrayList<>();
    objects.add(Event.class);
    objects.add(eventName);

    objects.add(Arrays.class);
    objects.add(TypeReference.class);
    for (NamedTypeName parameterType : parameterTypes) {
        objects.add(TypeReference.class);
        objects.add(parameterType.getTypeName());
    }

    String asListParams =
            parameterTypes.stream()
                    .map(
                            type -> {
                                if (type.isIndexed()) {
                                    return "new $T<$T>(true) {}";
                                } else {
                                    return "new $T<$T>() {}";
                                }
                            })
                    .collect(Collectors.joining(", "));

    return CodeBlock.builder()
            .addStatement(
                    "new $T($S, \n" + "$T.<$T<?>>asList(" + asListParams + "))",
                    objects.toArray())
            .build();
}
 
Example #26
Source File: HumanStandardToken.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> approveAndCall(String _spender, BigInteger _value, byte[] _extraData) {
    final Function function = new Function(
            "approveAndCall", 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_spender), 
            new org.web3j.abi.datatypes.generated.Uint256(_value), 
            new org.web3j.abi.datatypes.DynamicBytes(_extraData)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #27
Source File: HumanStandardToken.java    From web3j-quorum with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> transfer(String _to, BigInteger _value) {
    final Function function = new Function(
            FUNC_TRANSFER,
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_to),
                    new org.web3j.abi.datatypes.generated.Uint256(_value)),
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #28
Source File: Greeter.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> kill() {
    final Function function = new Function(
            "kill", 
            Arrays.<Type>asList(), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #29
Source File: PublicResolver.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<String> text(byte[] node, String key) {
    final Function function = new Function(FUNC_TEXT, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(node), 
            new org.web3j.abi.datatypes.Utf8String(key)), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    return executeRemoteCallSingleValueReturn(function, String.class);
}
 
Example #30
Source File: SolidityFunctionWrapper.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private static void buildVariableLengthReturnFunctionConstructor(
        MethodSpec.Builder methodBuilder, String functionName, String inputParameters,
        List<TypeName> outputParameterTypes) throws ClassNotFoundException {

    List<Object> objects = new ArrayList<>();
    objects.add(Function.class);
    objects.add(Function.class);
    objects.add(funcNameToConst(functionName));

    objects.add(Arrays.class);
    objects.add(Type.class);
    objects.add(inputParameters);

    objects.add(Arrays.class);
    objects.add(TypeReference.class);
    for (TypeName outputParameterType : outputParameterTypes) {
        objects.add(TypeReference.class);
        objects.add(outputParameterType);
    }

    String asListParams = Collection.join(
            outputParameterTypes,
            ", ",
            typeName -> "new $T<$T>() {}");

    methodBuilder.addStatement("final $T function = new $T($N, \n$T.<$T>asList($L), \n$T"
            + ".<$T<?>>asList("
            + asListParams + "))", objects.toArray());
}