From 8df8eb4e7af495305d2ea101c49cdae9c1261027 Mon Sep 17 00:00:00 2001 From: Rachel Bousfield Date: Tue, 30 Aug 2022 07:56:39 -0500 Subject: [PATCH] ethclient: add 'finalized' and 'safe' block number support (#25580) --- ethclient/ethclient.go | 8 ++++++++ ethclient/gethclient/gethclient.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 8a00184318..766efcf571 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -570,6 +570,14 @@ func toBlockNumArg(number *big.Int) string { 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) } diff --git a/ethclient/gethclient/gethclient.go b/ethclient/gethclient/gethclient.go index a86f4339f4..edc441bd1e 100644 --- a/ethclient/gethclient/gethclient.go +++ b/ethclient/gethclient/gethclient.go @@ -187,6 +187,14 @@ func toBlockNumArg(number *big.Int) string { 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) }