org.web3j.rlp.RlpList Java Examples
The following examples show how to use
org.web3j.rlp.RlpList.
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: TransactionDecoder.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
public static RawTransaction decode(String hexTransaction) { byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); RlpList rlpList = RlpDecoder.decode(transaction); RlpList values = (RlpList) rlpList.getValues().get(0); BigInteger nonce = ((RlpString) values.getValues().get(0)).asBigInteger(); BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asBigInteger(); BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asBigInteger(); String to = ((RlpString) values.getValues().get(3)).asString(); BigInteger value = ((RlpString) values.getValues().get(4)).asBigInteger(); String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() > 6) { byte v = ((RlpString) values.getValues().get(6)).getBytes()[0]; byte[] r = zeroPadded(((RlpString) values.getValues().get(7)).getBytes(), 32); byte[] s = zeroPadded(((RlpString) values.getValues().get(8)).getBytes(), 32); Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction(nonce, gasPrice, gasLimit, to, value, data, signatureData); } else { return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } }
Example #2
Source File: DelegateContract.java From client-sdk-java with Apache License 2.0 | 6 votes |
/** * 获得解除委托时所提取的委托收益(当减持/撤销委托成功时调用) * * @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: BaseContract.java From client-sdk-java with Apache License 2.0 | 6 votes |
private TransactionResponse getResponseFromTransactionReceipt(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 log 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); TransactionResponse transactionResponse = new TransactionResponse(); transactionResponse.setCode(statusCode); transactionResponse.setTransactionReceipt(transactionReceipt); return transactionResponse; }
Example #4
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 #5
Source File: TransactionDecoder.java From web3j with Apache License 2.0 | 5 votes |
public static RawTransaction decode(final String hexTransaction) { final byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); final RlpList rlpList = RlpDecoder.decode(transaction); final RlpList values = (RlpList) rlpList.getValues().get(0); final BigInteger nonce = ((RlpString) values.getValues().get(0)).asPositiveBigInteger(); final BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asPositiveBigInteger(); final BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asPositiveBigInteger(); final String to = ((RlpString) values.getValues().get(3)).asString(); final BigInteger value = ((RlpString) values.getValues().get(4)).asPositiveBigInteger(); final String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() == 6 || (values.getValues().size() == 8 && ((RlpString) values.getValues().get(7)).getBytes().length == 10) || (values.getValues().size() == 9 && ((RlpString) values.getValues().get(8)).getBytes().length == 10)) { // the 8th or 9nth element is the hex // representation of "restricted" for private transactions return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } else { final byte[] v = ((RlpString) values.getValues().get(6)).getBytes(); final byte[] r = Numeric.toBytesPadded( Numeric.toBigInt(((RlpString) values.getValues().get(7)).getBytes()), 32); final byte[] s = Numeric.toBytesPadded( Numeric.toBigInt(((RlpString) values.getValues().get(8)).getBytes()), 32); final Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction( nonce, gasPrice, gasLimit, to, value, data, signatureData); } }
Example #6
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 #7
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 #8
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 #9
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 #10
Source File: RewardContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
/** * 获得提取的明细(当提取账户当前所有的可提取的委托奖励成功时调用) * * @param transactionReceipt * @return * @throws TransactionException */ public List<Reward> decodeWithdrawDelegateRewardLog(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"); } List<Reward> rewards = new ArrayList<>(); ((RlpList)((RlpList)RlpDecoder.decode(((RlpString)rlpList.get(1)).getBytes())).getValues().get(0)).getValues() .stream() .forEach(rl -> { RlpList rlpL = (RlpList)rl; Reward reward = new Reward(); reward.setNodeId(((RlpString)rlpL.getValues().get(0)).asString()); reward.setStakingNum(((RlpString)rlpL.getValues().get(1)).asPositiveBigInteger()); reward.setRewardBigIntegerValue((((RlpString)rlpL.getValues().get(2)).asPositiveBigInteger())); rewards.add(reward); }); return rewards; }
Example #11
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 #12
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 #13
Source File: TransactionDecoder.java From client-sdk-java with Apache License 2.0 | 5 votes |
public static RawTransaction decode(String hexTransaction) { byte[] transaction = Numeric.hexStringToByteArray(hexTransaction); RlpList rlpList = RlpDecoder.decode(transaction); RlpList values = (RlpList) rlpList.getValues().get(0); BigInteger nonce = ((RlpString) values.getValues().get(0)).asPositiveBigInteger(); BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asPositiveBigInteger(); BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asPositiveBigInteger(); String to = ((RlpString) values.getValues().get(3)).asString(); BigInteger value = ((RlpString) values.getValues().get(4)).asPositiveBigInteger(); String data = ((RlpString) values.getValues().get(5)).asString(); if (values.getValues().size() == 6 || (values.getValues().size() == 8 && ((RlpString) values.getValues().get(7)).getBytes().length == 10) || (values.getValues().size() == 9 && ((RlpString) values.getValues().get(8)).getBytes().length == 10)) { // the 8th or 9nth element is the hex // representation of "restricted" for private transactions return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); } else { final byte[] v = ((RlpString) values.getValues().get(6)).getBytes(); final byte[] r = Numeric.toBytesPadded( Numeric.toBigInt(((RlpString) values.getValues().get(7)).getBytes()), 32); final byte[] s = Numeric.toBytesPadded( Numeric.toBigInt(((RlpString) values.getValues().get(8)).getBytes()), 32); final Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s); return new SignedRawTransaction( nonce, gasPrice, gasLimit, to, value, data, signatureData); } }
Example #14
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 #15
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 #16
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 #17
Source File: RestrictingPlan.java From client-sdk-java with Apache License 2.0 | 4 votes |
@Override public RlpType getRlpEncodeData() { return new RlpList(RlpString.create(epoch), RlpString.create(amount)); }
Example #18
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 #19
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 #20
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 #21
Source File: PrivateTransactionDecoder.java From web3j with Apache License 2.0 | 4 votes |
private static List<Base64String> extractBase64List(final RlpType values) { return ((RlpList) values) .getValues().stream() .map(PrivateTransactionDecoder::extractBase64) .collect(Collectors.toList()); }
Example #22
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 #23
Source File: Base64String.java From web3j with Apache License 2.0 | 4 votes |
public static RlpList unwrapListToRlp(final List<Base64String> base64Strings) { return new RlpList( base64Strings.stream().map(Base64String::asRlp).collect(Collectors.toList())); }
Example #24
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 #25
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 #26
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); }