Java Code Examples for org.web3j.abi.datatypes.Address
The following examples show how to use
org.web3j.abi.datatypes.Address.
These examples are extracted from open source projects.
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 Project: BitcoinWallet Author: terryjiao File: TransactionManager.java License: MIT License | 6 votes |
public String signContractTransaction(String contractAddress, String to, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, BigDecimal amount, BigDecimal decimal, WalletFile walletfile, String password) throws Exception { BigDecimal realValue = amount.multiply(decimal); Function function = new Function("transfer", Arrays.asList(new Address(to), new Uint256(realValue.toBigInteger())), Collections.emptyList()); String data = FunctionEncoder.encode(function); RawTransaction rawTransaction = RawTransaction.createTransaction( nonce, gasPrice, gasLimit, contractAddress, data); return signData(rawTransaction, walletfile, password); }
Example #2
Source Project: besu Author: hyperledger File: OnChainPrivacyGroupManagementProxy.java License: Apache License 2.0 | 6 votes |
public static RemoteCall<OnChainPrivacyGroupManagementProxy> deploy( Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String _implementation) { String encodedConstructor = FunctionEncoder.encodeConstructor( Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, _implementation))); return deployRemoteCall( OnChainPrivacyGroupManagementProxy.class, web3j, transactionManager, contractGasProvider, BINARY, encodedConstructor); }
Example #3
Source Project: web3j-gradle-plugin Author: web3j File: Web3jExtension.java License: Apache License 2.0 | 6 votes |
public Web3jExtension(final Project project) { generatedFilesBaseDir = project.getBuildDir().getAbsolutePath() + "/generated/source/" + NAME; // Use the project's group name in generated package final String projectGroup = project.getGroup().toString(); if (!projectGroup.isEmpty()) { generatedPackageName = projectGroup + "." + NAME; } else { generatedPackageName = DEFAULT_GENERATED_PACKAGE; } useNativeJavaTypes = true; excludedContracts = new ArrayList<>(); includedContracts = new ArrayList<>(); addressBitLength = Address.DEFAULT_LENGTH / Byte.SIZE; }
Example #4
Source Project: Android-Wallet-Token-ERC20 Author: EasyToken File: TokenERC20.java License: Apache License 2.0 | 6 votes |
public Observable<BurnEventResponse> burnEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { final Event event = new Event("Burn", Arrays.<TypeReference<?>>asList(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, BurnEventResponse>() { @Override public BurnEventResponse call(Log log) { EventValues eventValues = extractEventParameters(event, log); BurnEventResponse typedResponse = new BurnEventResponse(); typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue(); typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); return typedResponse; } }); }
Example #5
Source Project: client-sdk-java Author: PlatONnetwork File: Contract.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected <T extends Type, R> R executeCallSingleValueReturn( Function function, Class<R> returnType) throws IOException { T result = executeCallSingleValueReturn(function); if (result == null) { throw new ContractCallException("Empty value (0x) returned from contract"); } Object value = result.getValue(); if (returnType.isAssignableFrom(value.getClass())) { return (R) value; } else if (result.getClass().equals(Address.class) && returnType.equals(String.class)) { return (R) result.toString(); // cast isn't necessary } else { throw new ContractCallException( "Unable to convert response: " + value + " to expected type: " + returnType.getSimpleName()); } }
Example #6
Source Project: guarda-android-wallets Author: guardaco File: SendingTokensActivity.java License: GNU General Public License v3.0 | 6 votes |
private String getContractTransfer() { int tokenDecimals = tokensManager.getTokenByCode(tokenCode).getDecimal(); BigInteger tokenValue = Converter.toDecimals(new BigDecimal(amountToSend), tokenDecimals).toBigInteger(); List<Type> inputParams = new ArrayList<>(); Type address = new Address(walletNumber); inputParams.add(address); Type value = new Uint(tokenValue); inputParams.add(value); Function function = new Function( "transfer", inputParams, Collections.<TypeReference<?>>emptyList()); return FunctionEncoder.encode(function); }
Example #7
Source Project: guarda-android-wallets Author: guardaco File: SendingTokensActivity.java License: GNU General Public License v3.0 | 6 votes |
private String getContractTransfer() { int tokenDecimals = tokensManager.getTokenByCode(tokenCode).getDecimal(); BigInteger tokenValue = Converter.toDecimals(new BigDecimal(amountToSend), tokenDecimals).toBigInteger(); List<Type> inputParams = new ArrayList<>(); Type address = new Address(walletNumber); inputParams.add(address); Type value = new Uint(tokenValue); inputParams.add(value); Function function = new Function( "transfer", inputParams, Collections.<TypeReference<?>>emptyList()); return FunctionEncoder.encode(function); }
Example #8
Source Project: client-sdk-java Author: PlatONnetwork File: PayWages.java License: Apache License 2.0 | 6 votes |
public RemoteCall<Tuple4<BigInteger, BigInteger, String, String>> getEmployee(String _account) { final Function function = new Function(FUNC_GETEMPLOYEE, Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_account)), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() { }, new TypeReference<Uint8>() { }, new TypeReference<Utf8String>() { }, new TypeReference<Address>() { })); return new RemoteCall<Tuple4<BigInteger, BigInteger, String, String>>(new Callable<Tuple4<BigInteger, BigInteger, String, String>>() { @Override public Tuple4<BigInteger, BigInteger, String, String> call() throws Exception { List<Type> results = executeCallMultipleValueReturn(function); return new Tuple4<BigInteger, BigInteger, String, String>((BigInteger) results.get(0).getValue(), (BigInteger) results.get(1).getValue(), (String) results.get(2).getValue(), (String) results.get(3).getValue()); } }); }
Example #9
Source Project: etherscan-explorer Author: bing-chou File: PublicResolver.java License: GNU General Public License v3.0 | 6 votes |
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 #10
Source Project: alpha-wallet-android Author: AlphaWallet File: TokenRepository.java License: MIT License | 6 votes |
public static byte[] createDropCurrency(MagicLinkData order, int v, byte[] r, byte[] s, String recipient) { Function function = new Function( "dropCurrency", Arrays.asList(new org.web3j.abi.datatypes.generated.Uint32(order.nonce), new org.web3j.abi.datatypes.generated.Uint32(order.amount), new org.web3j.abi.datatypes.generated.Uint32(order.expiry), new org.web3j.abi.datatypes.generated.Uint8(v), new org.web3j.abi.datatypes.generated.Bytes32(r), new org.web3j.abi.datatypes.generated.Bytes32(s), new org.web3j.abi.datatypes.Address(recipient)), Collections.emptyList()); String encodedFunction = FunctionEncoder.encode(function); return Numeric.hexStringToByteArray(Numeric.cleanHexPrefix(encodedFunction)); }
Example #11
Source Project: etherscan-explorer Author: bing-chou File: TypeDecoder.java License: GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") static <T extends Type> T decode(String input, int offset, Class<T> type) { if (NumericType.class.isAssignableFrom(type)) { return (T) decodeNumeric(input.substring(offset), (Class<NumericType>) type); } else if (Address.class.isAssignableFrom(type)) { return (T) decodeAddress(input.substring(offset)); } else if (Bool.class.isAssignableFrom(type)) { return (T) decodeBool(input, offset); } else if (Bytes.class.isAssignableFrom(type)) { return (T) decodeBytes(input, offset, (Class<Bytes>) type); } else if (DynamicBytes.class.isAssignableFrom(type)) { return (T) decodeDynamicBytes(input, offset); } else if (Utf8String.class.isAssignableFrom(type)) { return (T) decodeUtf8String(input, offset); } else if (Array.class.isAssignableFrom(type)) { throw new UnsupportedOperationException( "Array types must be wrapped in a TypeReference"); } else { throw new UnsupportedOperationException( "Type cannot be encoded: " + type.getClass()); } }
Example #12
Source Project: etherscan-explorer Author: bing-chou File: AbiTypesMapperGenerator.java License: GNU General Public License v3.0 | 6 votes |
private MethodSpec.Builder addTypes(MethodSpec.Builder builder, String packageName) { builder = addStatement(builder, packageName, Address.TYPE_NAME, Address.class.getSimpleName()); builder = addStatement(builder, packageName, Bool.TYPE_NAME, Bool.class.getSimpleName()); builder = addStatement(builder, packageName, Utf8String.TYPE_NAME, Utf8String.class.getSimpleName()); builder = addStatement(builder, packageName, DynamicBytes.TYPE_NAME, DynamicBytes.class.getSimpleName()); // TODO: Fixed array & dynamic array support return builder; }
Example #13
Source Project: web3j Author: web3j File: BlindAuction.java License: Apache License 2.0 | 6 votes |
public RemoteCall<Tuple2<byte[], BigInteger>> bids(String param0, BigInteger param1) { final Function function = new Function(FUNC_BIDS, Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(param0), new org.web3j.abi.datatypes.generated.Uint256(param1)), Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Uint256>() {})); return new RemoteCall<Tuple2<byte[], BigInteger>>( new Callable<Tuple2<byte[], BigInteger>>() { @Override public Tuple2<byte[], BigInteger> call() throws Exception { List<Type> results = executeCallMultipleValueReturn(function); return new Tuple2<byte[], BigInteger>( (byte[]) results.get(0).getValue(), (BigInteger) results.get(1).getValue()); } }); }
Example #14
Source Project: web3j Author: web3j File: ENS.java License: Apache License 2.0 | 5 votes |
public RemoteCall<TransactionReceipt> setOwner(byte[] node, String owner) { final Function function = new Function( FUNC_SETOWNER, Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(node), new org.web3j.abi.datatypes.Address(owner)), Collections.<TypeReference<?>>emptyList()); return executeRemoteCallTransaction(function); }
Example #15
Source Project: besu Author: hyperledger File: EventEmitter.java License: Apache License 2.0 | 5 votes |
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 #16
Source Project: besu Author: hyperledger File: CrossContractReader.java License: Apache License 2.0 | 5 votes |
public RemoteFunctionCall<TransactionReceipt> remoteDestroy(final String crossAddress) { final Function function = new Function( FUNC_REMOTEDESTROY, Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, crossAddress)), Collections.<TypeReference<?>>emptyList()); return executeRemoteCallTransaction(function); }
Example #17
Source Project: web3j Author: web3j File: ContractTest.java License: Apache License 2.0 | 5 votes |
public List<EventValues> processEvent(TransactionReceipt transactionReceipt) { Event event = new Event( "Event", Arrays.asList( new TypeReference<Address>(true) {}, new TypeReference<Uint256>() {})); return extractEventParameters(event, transactionReceipt); }
Example #18
Source Project: besu Author: hyperledger File: CrossContractReader.java License: Apache License 2.0 | 5 votes |
public RemoteFunctionCall<BigInteger> read(final String emitter_address) { final Function function = new Function( FUNC_READ, Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, emitter_address)), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); return executeRemoteCallSingleValueReturn(function, BigInteger.class); }
Example #19
Source Project: etherscan-explorer Author: bing-chou File: ENS.java License: GNU General Public License v3.0 | 5 votes |
public RemoteCall<TransactionReceipt> setSubnodeOwner(byte[] node, byte[] label, String owner) { Function function = new Function( "setSubnodeOwner", Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(node), new org.web3j.abi.datatypes.generated.Bytes32(label), new org.web3j.abi.datatypes.Address(owner)), Collections.<TypeReference<?>>emptyList()); return executeRemoteCallTransaction(function); }
Example #20
Source Project: etherscan-explorer Author: bing-chou File: ENS.java License: GNU General Public License v3.0 | 5 votes |
public RemoteCall<TransactionReceipt> setResolver(byte[] node, String resolver) { Function function = new Function( "setResolver", Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(node), new org.web3j.abi.datatypes.Address(resolver)), Collections.<TypeReference<?>>emptyList()); return executeRemoteCallTransaction(function); }
Example #21
Source Project: alpha-wallet-android Author: AlphaWallet File: TokenRepository.java License: MIT License | 5 votes |
public static byte[] createTokenTransferData(String to, BigInteger tokenAmount) { List<Type> params = Arrays.asList(new Address(to), new Uint256(tokenAmount)); List<TypeReference<?>> returnTypes = Collections.singletonList(new TypeReference<Bool>() {}); Function function = new Function("transfer", params, returnTypes); String encodedFunction = FunctionEncoder.encode(function); return Numeric.hexStringToByteArray(Numeric.cleanHexPrefix(encodedFunction)); }
Example #22
Source Project: client-sdk-java Author: PlatONnetwork File: TypeEncoderTest.java License: Apache License 2.0 | 5 votes |
@Test public void testAddress() { Address address = new Address("0xbe5422d15f39373eb0a97ff8c10fbd0e40e29338"); assertThat(address.getTypeAsString(), is("address")); assertThat(TypeEncoder.encodeAddress(address), is("000000000000000000000000be5422d15f39373eb0a97ff8c10fbd0e40e29338")); }
Example #23
Source Project: client-sdk-java Author: PlatONnetwork File: SolidityFunctionWrapper.java License: Apache License 2.0 | 5 votes |
static TypeName getNativeType(TypeName typeName) { if (typeName instanceof ParameterizedTypeName) { return getNativeType((ParameterizedTypeName) typeName); } String simpleName = ((ClassName) typeName).simpleName(); if (simpleName.equals(Address.class.getSimpleName())) { return TypeName.get(String.class); } else if (simpleName.startsWith("Uint")) { return TypeName.get(BigInteger.class); } else if (simpleName.startsWith("Int")) { return TypeName.get(BigInteger.class); } else if (simpleName.equals(Utf8String.class.getSimpleName())) { return TypeName.get(String.class); } else if (simpleName.startsWith("Bytes")) { return TypeName.get(byte[].class); } else if (simpleName.equals(DynamicBytes.class.getSimpleName())) { return TypeName.get(byte[].class); } else if (simpleName.equals(Bool.class.getSimpleName())) { return TypeName.get(Boolean.class); // boolean cannot be a parameterized type } else { throw new UnsupportedOperationException( "Unsupported type: " + typeName + ", no native type mapping exists."); } }
Example #24
Source Project: client-sdk-java Author: PlatONnetwork File: SolidityFunctionWrapperTest.java License: Apache License 2.0 | 5 votes |
@Test public void testGetNativeTypeParameterized() { assertThat(getNativeType( ParameterizedTypeName.get( ClassName.get(DynamicArray.class), TypeName.get(Address.class))), equalTo(ParameterizedTypeName.get( ClassName.get(List.class), TypeName.get(String.class)))); }
Example #25
Source Project: client-sdk-java Author: PlatONnetwork File: SolidityFunctionWrapperTest.java License: Apache License 2.0 | 5 votes |
@Test public void testGetEventNativeTypeParameterized() { assertThat(getEventNativeType( ParameterizedTypeName.get( ClassName.get(DynamicArray.class), TypeName.get(Address.class))), equalTo(TypeName.get(byte[].class))); }
Example #26
Source Project: client-sdk-java Author: PlatONnetwork File: ContractTest.java License: Apache License 2.0 | 5 votes |
public RemoteCall<TransactionReceipt> performTransaction( Address address, Uint256 amount) { Function function = new Function("approve", Arrays.<Type>asList(address, amount), Collections.<TypeReference<?>>emptyList()); return executeRemoteCallTransaction(function); }
Example #27
Source Project: web3j Author: web3j File: BlindAuction.java License: Apache License 2.0 | 5 votes |
@Deprecated public static RemoteCall<BlindAuction> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, BigInteger _biddingTime, BigInteger _revealTime, String _beneficiary) { String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(_biddingTime), new org.web3j.abi.datatypes.generated.Uint256(_revealTime), new org.web3j.abi.datatypes.Address(_beneficiary))); return deployRemoteCall(BlindAuction.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, encodedConstructor); }
Example #28
Source Project: web3j Author: web3j File: HumanStandardToken.java License: Apache License 2.0 | 5 votes |
public RemoteCall<TransactionReceipt> approveAndCall(String _spender, BigInteger _value, byte[] _extraData) { final Function function = new Function( FUNC_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 #29
Source Project: web3j Author: web3j File: HumanStandardTokenIT.java License: Apache License 2.0 | 5 votes |
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 #30
Source Project: Android-Wallet-Token-ERC20 Author: EasyToken File: TokenERC20.java License: Apache License 2.0 | 5 votes |
public RemoteCall<TransactionReceipt> transferFrom(String _from, String _to, BigInteger _value) { Function function = new Function( "transferFrom", Arrays.<Type>asList(new Address(_from), new Address(_to), new Uint256(_value)), Collections.<TypeReference<?>>emptyList()); return executeRemoteCallTransaction(function); }