use of org.fisco.bcos.web3j.rlp.RlpType in project web3sdk by FISCO-BCOS.
the class ReceiptEncoder method encode.
public static String encode(TransactionReceipt transactionReceipt) {
List<RlpType> values = asRlpValues(transactionReceipt);
RlpList rlpList = new RlpList(values);
byte[] rlpBytes = RlpEncoder.encode(rlpList);
return Numeric.toHexString(rlpBytes);
}
use of org.fisco.bcos.web3j.rlp.RlpType in project web3sdk by FISCO-BCOS.
the class ReceiptEncoder method asRlpValues.
private static List<RlpType> asRlpValues(TransactionReceipt transactionReceipt) {
List<RlpType> result = new ArrayList<>();
// bytes
result.add(RlpString.create(Numeric.hexStringToByteArray(transactionReceipt.getRoot())));
// BigInteger
result.add(RlpString.create(Numeric.toBigInt(transactionReceipt.getGasUsedRaw())));
result.add(RlpString.create(Numeric.hexStringToByteArray(transactionReceipt.getContractAddress())));
result.add(RlpString.create(Numeric.hexStringToByteArray(transactionReceipt.getLogsBloom())));
result.add(RlpString.create(Numeric.toBigInt(transactionReceipt.getStatus())));
result.add(RlpString.create(Numeric.hexStringToByteArray(transactionReceipt.getOutput())));
// List
List<Log> logs = transactionReceipt.getLogs();
List<RlpType> logList = new ArrayList<>();
for (Log log : logs) {
List<RlpType> logUnit = new ArrayList<>();
logUnit.add(RlpString.create(Numeric.hexStringToByteArray(log.getAddress())));
List<String> topics = log.getTopics();
List<RlpType> topicList = new ArrayList<>();
for (String topic : topics) {
topicList.add(RlpString.create(Numeric.hexStringToByteArray(topic)));
}
RlpList topicRlpList = new RlpList(topicList);
logUnit.add(topicRlpList);
logUnit.add(RlpString.create(Numeric.hexStringToByteArray(log.getData())));
logList.add(new RlpList(logUnit));
}
RlpList logRlpList = new RlpList(logList);
result.add(logRlpList);
return result;
}