mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 05:27:19 +00:00
11f4978ed4
Following our previous discussion on erigon's discord, this PR requests to upstream all Otterscan modifications to erigon's repo. That decision comes after getting feedback from lots of users at events this year, and although it may introduce some friction for development, it will make integrators life easier by having all our modifications available out of box, e.g., dappnode users will get our RPCs since their official packages are built from erigon repo. I'm submitting the source-code as-is, please let me know if you think there is a better code organization. The current set of modifications comprises only new RPCs. There are some proposals for extra-stages that would add new tables, but they are still WIP and will be submitted separately in future after more testing.
32 lines
806 B
Go
32 lines
806 B
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/rpc"
|
|
"github.com/ledgerwatch/erigon/turbo/adapter"
|
|
"github.com/ledgerwatch/erigon/turbo/rpchelper"
|
|
)
|
|
|
|
func (api *OtterscanAPIImpl) HasCode(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (bool, error) {
|
|
tx, err := api.db.BeginRo(ctx)
|
|
if err != nil {
|
|
return false, fmt.Errorf("hasCode cannot open tx: %w", err)
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
blockNumber, _, _, err := rpchelper.GetBlockNumber(blockNrOrHash, tx, api.filters)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
reader := adapter.NewStateReader(tx, blockNumber)
|
|
acc, err := reader.ReadAccountData(address)
|
|
if acc == nil || err != nil {
|
|
return false, err
|
|
}
|
|
return !acc.IsEmptyCodeHash(), nil
|
|
}
|