org.web3j.rlp.RlpEncoder Java Examples
The following examples show how to use
org.web3j.rlp.RlpEncoder.
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: TransferTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
public String sendTransaction(String privateKey, String toAddress, BigDecimal amount, long gasPrice, long gasLimit) { BigInteger GAS_PRICE = BigInteger.valueOf(gasPrice); BigInteger GAS_LIMIT = BigInteger.valueOf(gasLimit); Credentials credentials = Credentials.create(privateKey); try { List<RlpType> result = new ArrayList<>(); result.add(RlpString.create(Numeric.hexStringToByteArray(PlatOnTypeEncoder.encode(new Int64(0))))); String txType = Hex.toHexString(RlpEncoder.encode(new RlpList(result))); RawTransaction rawTransaction = RawTransaction.createTransaction(getNonce(), GAS_PRICE, GAS_LIMIT, toAddress, amount.toBigInteger(), txType); byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, new Byte("100"), credentials); String hexValue = Numeric.toHexString(signedMessage); PlatonSendTransaction transaction = web3j.platonSendRawTransaction(hexValue).send(); return transaction.getTransactionHash(); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #2
Source File: ContractUtils.java From web3j with Apache License 2.0 | 5 votes |
/** * Generate a smart contract address. This enables you to identify what address a smart contract * will be deployed to on the network. * * @param address of sender * @param nonce of transaction * @return the generated smart contract address */ public static byte[] generateContractAddress(byte[] address, BigInteger nonce) { List<RlpType> values = new ArrayList<>(); values.add(RlpString.create(address)); values.add(RlpString.create(nonce)); RlpList rlpList = new RlpList(values); byte[] encoded = RlpEncoder.encode(rlpList); byte[] hashed = Hash.sha3(encoded); return Arrays.copyOfRange(hashed, 12, hashed.length); }
Example #3
Source File: PrivacyGroupUtils.java From web3j with Apache License 2.0 | 5 votes |
public static Base64String generateLegacyGroup( final Base64String privateFrom, final List<Base64String> privateFor) { final List<byte[]> stringList = new ArrayList<>(); stringList.add(Base64.getDecoder().decode(privateFrom.toString())); privateFor.forEach(item -> stringList.add(item.raw())); final List<RlpType> rlpList = stringList.stream() .distinct() .sorted(Comparator.comparing(Arrays::hashCode)) .map(RlpString::create) .collect(Collectors.toList()); return Base64String.wrap(Hash.sha3(RlpEncoder.encode(new RlpList(rlpList)))); }
Example #4
Source File: ContractUtils.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
/** * Generate a smart contract address. This enables you to identify what address a * smart contract will be deployed to on the network. * * @param address of sender * @param nonce of transaction * @return the generated smart contract address */ public static byte[] generateContractAddress(byte[] address, BigInteger nonce) { List<RlpType> values = new ArrayList<>(); values.add(RlpString.create(address)); values.add(RlpString.create(nonce)); RlpList rlpList = new RlpList(values); byte[] encoded = RlpEncoder.encode(rlpList); byte[] hashed = Hash.sha3(encoded); return Arrays.copyOfRange(hashed, 12, hashed.length); }
Example #5
Source File: PrivateTransaction.java From ethsigner with Apache License 2.0 | 5 votes |
@Override public byte[] rlpEncode(final SignatureData signatureData) { final RawPrivateTransaction rawTransaction = createTransaction(); final List<RlpType> values = PrivateTransactionEncoder.asRlpValues(rawTransaction, signatureData); final RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #6
Source File: CustomStaticArray.java From client-sdk-java with Apache License 2.0 | 5 votes |
public RlpType getRlpEncodeData() { if (list != null ) { List<RlpType> rlpListList = new ArrayList<>(); for (T t : list) { rlpListList.add(t.getRlpEncodeData()); } return RlpString.create(RlpEncoder.encode(new RlpList(rlpListList))); } throw new RuntimeException("unsupported types"); }
Example #7
Source File: EncoderUtils.java From client-sdk-java with Apache License 2.0 | 5 votes |
public static String functionEncoder(Function function){ List<RlpType> result = new ArrayList<>(); result.add(RlpString.create(RlpEncoder.encode(RlpString.create(function.getType())))); List<Type> parameters = function.getInputParameters(); if (parameters != null && parameters.size() > 0) { for (Type parameter : parameters) { if (parameter instanceof IntType) { result.add(RlpString.create(RlpEncoder.encode(RlpString.create(((IntType) parameter).getValue())))); } else if (parameter instanceof BytesType) { result.add(RlpString.create(RlpEncoder.encode(RlpString.create(((BytesType) parameter).getValue())))); } else if (parameter instanceof Utf8String) { result.add(RlpString.create(RlpEncoder.encode(RlpString.create(((Utf8String) parameter).getValue())))); } else if (parameter instanceof CustomStaticArray) { result.add(((CustomStaticArray) parameter).getRlpEncodeData()); } else if (parameter instanceof CustomType) { result.add(((CustomType) parameter).getRlpEncodeData()); } } } String data = Hex.toHexString(RlpEncoder.encode(new RlpList(result))); return data; }
Example #8
Source File: ContractUtils.java From client-sdk-java with Apache License 2.0 | 5 votes |
/** * Generate a smart contract address. This enables you to identify what address a * smart contract will be deployed to on the network. * * @param address of sender * @param nonce of transaction * @return the generated smart contract address */ public static byte[] generateContractAddress(byte[] address, BigInteger nonce) { List<RlpType> values = new ArrayList<>(); values.add(RlpString.create(address)); values.add(RlpString.create(nonce)); RlpList rlpList = new RlpList(values); byte[] encoded = RlpEncoder.encode(rlpList); byte[] hashed = Hash.sha3(encoded); return Arrays.copyOfRange(hashed, 12, hashed.length); }
Example #9
Source File: CreateTransactionInteract.java From Upchain-wallet with GNU Affero General Public License v3.0 | 5 votes |
public Single<byte[]> getSignature(ETHWallet wallet, byte[] message, String password) { return Single.fromCallable(() -> { Credentials credentials = WalletUtils.loadCredentials(password, wallet.getKeystorePath()); Sign.SignatureData signatureData = Sign.signMessage( message, credentials.getEcKeyPair()); List<RlpType> result = new ArrayList<>(); result.add(RlpString.create(message)); if (signatureData != null) { result.add(RlpString.create(signatureData.getV())); result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getR()))); result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getS()))); } RlpList rlpList = new RlpList(result); return RlpEncoder.encode(rlpList); }); }
Example #10
Source File: EthTransaction.java From ethsigner with Apache License 2.0 | 5 votes |
@Override public byte[] rlpEncode(final SignatureData signatureData) { final RawTransaction rawTransaction = createTransaction(); final List<RlpType> values = TransactionEncoder.asRlpValues(rawTransaction, signatureData); final RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #11
Source File: NodeIdTool.java From client-sdk-java with Apache License 2.0 | 4 votes |
private static byte[] encode(PlatonBlock.Block block) { List<RlpType> values = asRlpValues(block); RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #12
Source File: TransactionEncoder.java From etherscan-explorer with GNU General Public License v3.0 | 4 votes |
private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) { List<RlpType> values = asRlpValues(rawTransaction, signatureData); RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #13
Source File: TransactionEncoder.java From client-sdk-java with Apache License 2.0 | 4 votes |
private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) { List<RlpType> values = asRlpValues(rawTransaction, signatureData); RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #14
Source File: KeystoreAccountService.java From alpha-wallet-android with MIT License | 4 votes |
private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) { List<RlpType> values = TransactionEncoder.asRlpValues(rawTransaction, signatureData); RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #15
Source File: PrivateTransactionEncoder.java From web3j with Apache License 2.0 | 4 votes |
private static byte[] encode( final RawPrivateTransaction rawTransaction, final Sign.SignatureData signatureData) { final List<RlpType> values = asRlpValues(rawTransaction, signatureData); final RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #16
Source File: TransactionEncoder.java From web3j with Apache License 2.0 | 4 votes |
private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) { List<RlpType> values = asRlpValues(rawTransaction, signatureData); RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }
Example #17
Source File: TransactionRepository.java From alpha-wallet-android with MIT License | 2 votes |
/** * From Web3j to encode a constructor * @param rawTransaction * @param signatureData * @return */ private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) { List<RlpType> values = TransactionEncoder.asRlpValues(rawTransaction, signatureData); RlpList rlpList = new RlpList(values); return RlpEncoder.encode(rlpList); }