Skip to content

Commit

Permalink
patch: Add safe and finalized tags to ethclient SDK (ethereum#202)
Browse files Browse the repository at this point in the history
add safe and finalized tags to ethclient SDK
  • Loading branch information
Thegaram authored Jan 27, 2023
1 parent cdaea93 commit 08ba436
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 13 additions & 1 deletion ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,22 @@ func toBlockNumArg(number *big.Int) string {
if number == nil {
return "latest"
}
pending := big.NewInt(-1)
latest := big.NewInt(int64(rpc.LatestBlockNumber))
if number.Cmp(latest) == 0 {
return "latest"
}
pending := big.NewInt(int64(rpc.PendingBlockNumber))
if number.Cmp(pending) == 0 {
return "pending"
}
finalized := big.NewInt(int64(rpc.FinalizedBlockNumber))
if number.Cmp(finalized) == 0 {
return "finalized"
}
safe := big.NewInt(int64(rpc.SafeBlockNumber))
if number.Cmp(safe) == 0 {
return "safe"
}
return hexutil.EncodeBig(number)
}

Expand Down
8 changes: 5 additions & 3 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ type jsonWriter interface {
type BlockNumber int64

const (
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
SafeBlockNumber = BlockNumber(-4)
FinalizedBlockNumber = BlockNumber(-3)
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
)

// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
Expand Down

0 comments on commit 08ba436

Please sign in to comment.