Skip to content

Commit

Permalink
ChainID adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
i-norden committed Aug 8, 2022
1 parent c9e6055 commit 2bf3e06
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type PublicEthAPI struct {

// NewPublicEthAPI creates a new PublicEthAPI with the provided underlying Backend
func NewPublicEthAPI(b *Backend, client *rpc.Client, supportsStateDiff, forwardEthCalls, proxyOnError bool) (*PublicEthAPI, error) {
if b == nil {
return nil, errors.New("ipld-eth-server must be configured with an ethereum backend")
}
if forwardEthCalls && client == nil {
return nil, errors.New("ipld-eth-server is configured to forward eth_calls to proxy node but no proxy node is configured")
}
Expand Down Expand Up @@ -191,20 +194,16 @@ func (pea *PublicEthAPI) GetBlockByHash(ctx context.Context, hash common.Hash, f

// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
func (pea *PublicEthAPI) ChainId() *hexutil.Big {
block, err := pea.B.CurrentBlock()
if err != nil {
if pea.B.Config.ChainConfig.ChainID == nil || pea.B.Config.ChainConfig.ChainID.Cmp(big.NewInt(0)) <= 0 {
if pea.proxyOnError {
if id, err := pea.ethClient.ChainID(context.Background()); err == nil {
return (*hexutil.Big)(id)
}
return nil
}
return nil
}

if config := pea.B.Config.ChainConfig; config.IsEIP155(block.Number()) {
return (*hexutil.Big)(config.ChainID)
}
return nil
return (*hexutil.Big)(pea.B.Config.ChainConfig.ChainID)
}

/*
Expand Down

0 comments on commit 2bf3e06

Please sign in to comment.