Skip to content

Commit

Permalink
Merge PR: add pending mode for test (#506)
Browse files Browse the repository at this point in the history
Co-authored-by: MengXiangJian <805442788@qq.com>
  • Loading branch information
summerpro and xiangjianmeng authored Dec 19, 2020
1 parent 3df2261 commit 18bc7bf
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 59 deletions.
19 changes: 15 additions & 4 deletions app/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
type Backend interface {
// Used by block filter; also used for polling
BlockNumber() (hexutil.Uint64, error)
LatestBlockNumber() (int64, error)
HeaderByNumber(blockNum rpctypes.BlockNumber) (*ethtypes.Header, error)
HeaderByHash(blockHash common.Hash) (*ethtypes.Header, error)
GetBlockByNumber(blockNum rpctypes.BlockNumber, fullTx bool) (map[string]interface{}, error)
Expand Down Expand Up @@ -60,13 +61,12 @@ func New(clientCtx clientcontext.CLIContext) *EthermintBackend {

// BlockNumber returns the current block number.
func (b *EthermintBackend) BlockNumber() (hexutil.Uint64, error) {
// NOTE: using 0 as min and max height returns the blockchain info up to the latest block.
info, err := b.clientCtx.Client.BlockchainInfo(0, 0)
blockNumber, err := b.LatestBlockNumber()
if err != nil {
return hexutil.Uint64(0), err
}

return hexutil.Uint64(info.LastHeight), nil
return hexutil.Uint64(blockNumber), nil
}

// GetBlockByNumber returns the block identified by number.
Expand Down Expand Up @@ -196,7 +196,7 @@ func (b *EthermintBackend) PendingTransactions() ([]*rpctypes.Transaction, error
return nil, err
}

transactions := make([]*rpctypes.Transaction, pendingTxs.Count)
transactions := make([]*rpctypes.Transaction, 0)
for _, tx := range pendingTxs.Txs {
ethTx, err := rpctypes.RawTxToEthTx(b.clientCtx, tx)
if err != nil {
Expand Down Expand Up @@ -257,3 +257,14 @@ func (b *EthermintBackend) GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, er
func (b *EthermintBackend) BloomStatus() (uint64, uint64) {
return 4096, 0
}

// LatestBlockNumber gets the latest block height in int64 format.
func (b *EthermintBackend) LatestBlockNumber() (int64, error) {
// NOTE: using 0 as min and max height returns the blockchain info up to the latest block.
info, err := b.clientCtx.Client.BlockchainInfo(0, 0)
if err != nil {
return 0, err
}

return info.LastHeight, nil
}
Loading

0 comments on commit 18bc7bf

Please sign in to comment.