mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 05:27:19 +00:00
38 lines
1018 B
Go
38 lines
1018 B
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
|
|
"github.com/ledgerwatch/erigon/core/state"
|
|
"github.com/ledgerwatch/erigon/core/systemcontracts"
|
|
"github.com/ledgerwatch/erigon/rpc"
|
|
"github.com/ledgerwatch/erigon/turbo/rpchelper"
|
|
)
|
|
|
|
func (api *OtterscanAPIImpl) HasCode(ctx context.Context, address libcommon.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
|
|
}
|
|
chainConfig, err := api.chainConfig(tx)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
reader := state.NewPlainState(tx, blockNumber, systemcontracts.SystemContractCodeLookup[chainConfig.ChainName])
|
|
acc, err := reader.ReadAccountData(address)
|
|
if acc == nil || err != nil {
|
|
return false, err
|
|
}
|
|
return !acc.IsEmptyCodeHash(), nil
|
|
}
|