Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align rpc/types.go with upstream #381

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,6 @@ func (ec *client) SendTransaction(ctx context.Context, tx *types.Transaction) er
}

func ToBlockNumArg(number *big.Int) string {
// The Ethereum implementation uses a different mapping from
// negative numbers to special strings (latest, pending) then is
// used on its server side. See rpc/types.go for the comparison.
// In Coreth, latest, pending, and accepted are all treated the same
// therefore, if [number] is nil or a negative number in [-4, -1]
// we want the latest accepted block
if number == nil {
return "latest"
}
Expand Down
22 changes: 15 additions & 7 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type jsonWriter interface {
type BlockNumber int64

const (
SafeBlockNumber = BlockNumber(-4)
AcceptedBlockNumber = BlockNumber(-3)
LatestBlockNumber = BlockNumber(-2)
PendingBlockNumber = BlockNumber(-1)
Expand Down Expand Up @@ -101,11 +102,13 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case "pending":
*bn = PendingBlockNumber
return nil
// Include "finalized" and "safe" as an option for compatibility with
// FinalizedBlockNumber and SafeBlockNumber from geth.
case "accepted", "finalized", "safe":
// Include "finalized" as an option for compatibility with FinalizedBlockNumber
case "accepted", "finalized":
*bn = AcceptedBlockNumber
return nil
case "safe":
*bn = SafeBlockNumber
return nil
}

blckNum, err := hexutil.DecodeUint64(input)
Expand Down Expand Up @@ -141,6 +144,8 @@ func (bn BlockNumber) String() string {
return "pending"
case AcceptedBlockNumber:
return "accepted"
case SafeBlockNumber:
return "safe"
default:
if bn < 0 {
return fmt.Sprintf("<invalid %d>", bn)
Expand All @@ -151,7 +156,7 @@ func (bn BlockNumber) String() string {

// IsAccepted returns true if this blockNumber should be treated as a request for the last accepted block
func (bn BlockNumber) IsAccepted() bool {
return bn < EarliestBlockNumber && bn >= AcceptedBlockNumber
return bn < EarliestBlockNumber && bn >= SafeBlockNumber
}

type BlockNumberOrHash struct {
Expand Down Expand Up @@ -191,12 +196,15 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
bn := PendingBlockNumber
bnh.BlockNumber = &bn
return nil
// Include "finalized" and "safe" as an option for compatibility with
// FinalizedBlockNumber and SafeBlockNumber from geth.
case "accepted", "finalized", "safe":
// Include "finalized" as an option for compatibility with FinalizedBlockNumber from geth.
case "accepted", "finalized":
bn := AcceptedBlockNumber
bnh.BlockNumber = &bn
return nil
case "safe":
bn := SafeBlockNumber
bnh.BlockNumber = &bn
return nil
default:
if len(input) == 66 {
hash := common.Hash{}
Expand Down