Search in sources :

Example 6 with RlpType

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);
}
Also used : RlpType(org.fisco.bcos.web3j.rlp.RlpType) RlpList(org.fisco.bcos.web3j.rlp.RlpList)

Example 7 with RlpType

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;
}
Also used : Log(org.fisco.bcos.web3j.protocol.core.methods.response.Log) ArrayList(java.util.ArrayList) RlpString(org.fisco.bcos.web3j.rlp.RlpString) RlpType(org.fisco.bcos.web3j.rlp.RlpType) RlpList(org.fisco.bcos.web3j.rlp.RlpList)

Aggregations

RlpType (org.fisco.bcos.web3j.rlp.RlpType)7 RlpList (org.fisco.bcos.web3j.rlp.RlpList)5 ArrayList (java.util.ArrayList)4 RlpString (org.fisco.bcos.web3j.rlp.RlpString)3 Log (org.fisco.bcos.web3j.protocol.core.methods.response.Log)1