org.web3j.rlp.RlpDecoder Java Examples
The following examples show how to use
org.web3j.rlp.RlpDecoder.
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: 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 #2
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 #3
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 #4
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 #5
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 #6
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); } }