block and tx logs bloom and tx receipt logs (#119)

* Add bloom filter to tx receipt

* wip tx receipt logs to be tested

* Added Bloom - Height Mapping
* keeper.go sets <height:bloombits>
* keeper.go gets <height> --> bloombits

* updating and querying bloom by block (to be tested with real logs)

* fix bug with contract address return

* added error handling instead of logging
This commit is contained in:
Austin Abell
2019-10-04 15:32:56 -04:00
committed by GitHub
parent 8bb8b40b32
commit eab81bc578
9 changed files with 202 additions and 22 deletions
+30 -7
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"math/big"
"strconv"
emintcrypto "github.com/cosmos/ethermint/crypto"
emintkeys "github.com/cosmos/ethermint/keys"
@@ -18,6 +19,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/cosmos/cosmos-sdk/client/context"
@@ -393,12 +395,20 @@ func (e *PublicEthAPI) getEthBlockByNumber(value int64, fullTx bool) (map[string
}
}
return formatBlock(header, block.Block.Size(), gasLimit, gasUsed, transactions), nil
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryLogsBloom, strconv.FormatInt(block.Block.Height, 10)))
if err != nil {
return nil, err
}
var out types.QueryBloomFilter
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
return formatBlock(header, block.Block.Size(), gasLimit, gasUsed, transactions, out.Bloom), nil
}
func formatBlock(
header tmtypes.Header, size int, gasLimit int64,
gasUsed *big.Int, transactions []interface{},
gasUsed *big.Int, transactions []interface{}, bloom ethtypes.Bloom,
) map[string]interface{} {
return map[string]interface{}{
"number": hexutil.Uint64(header.Height),
@@ -406,7 +416,7 @@ func formatBlock(
"parentHash": hexutil.Bytes(header.LastBlockID.Hash),
"nonce": nil, // PoW specific
"sha3Uncles": nil, // No uncles in Tendermint
"logsBloom": "", // TODO: Complete with #55
"logsBloom": bloom,
"transactionsRoot": hexutil.Bytes(header.DataHash),
"stateRoot": hexutil.Bytes(header.AppHash),
"miner": hexutil.Bytes(header.ValidatorsHash),
@@ -584,6 +594,17 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter
status = hexutil.Uint(0)
}
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryTxLogs, hash.Hex()))
if err != nil {
return nil, err
}
var logs types.QueryTxLogs
e.cliCtx.Codec.MustUnmarshalJSON(res, &logs)
// TODO: change hard coded indexing of bytes
bloomFilter := ethtypes.BytesToBloom(tx.TxResult.GetData()[20:])
fields := map[string]interface{}{
"blockHash": blockHash,
"blockNumber": hexutil.Uint64(tx.Height),
@@ -594,13 +615,15 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter
"gasUsed": hexutil.Uint64(tx.TxResult.GasUsed),
"cumulativeGasUsed": nil, // ignore until needed
"contractAddress": nil,
"logs": nil, // TODO: Do with #55 (eth_getLogs output)
"logsBloom": nil,
"logs": logs.Logs,
"logsBloom": bloomFilter,
"status": status,
}
if common.BytesToAddress(tx.TxResult.GetData()) != (common.Address{}) {
fields["contractAddress"] = hexutil.Bytes(tx.TxResult.GetData())
contractAddress := common.BytesToAddress(tx.TxResult.GetData()[:20])
if contractAddress != (common.Address{}) {
// TODO: change hard coded indexing of first 20 bytes
fields["contractAddress"] = contractAddress
}
return fields, nil