core: eth: rpc: implement safe rpc block (#25165)

* core: eth: rpc: implement safe rpc block

* core: fix setHead, panics
This commit is contained in:
Marius van der Wijden
2022-07-25 18:42:05 +03:00
committed by GitHub
parent f543e6b065
commit c6dcd018d2
7 changed files with 73 additions and 5 deletions
+10
View File
@@ -61,6 +61,7 @@ type jsonWriter interface {
type BlockNumber int64
const (
SafeBlockNumber = BlockNumber(-4)
FinalizedBlockNumber = BlockNumber(-3)
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
@@ -92,6 +93,9 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case "finalized":
*bn = FinalizedBlockNumber
return nil
case "safe":
*bn = SafeBlockNumber
return nil
}
blckNum, err := hexutil.DecodeUint64(input)
@@ -118,6 +122,8 @@ func (bn BlockNumber) MarshalText() ([]byte, error) {
return []byte("pending"), nil
case FinalizedBlockNumber:
return []byte("finalized"), nil
case SafeBlockNumber:
return []byte("safe"), nil
default:
return hexutil.Uint64(bn).MarshalText()
}
@@ -168,6 +174,10 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
bn := FinalizedBlockNumber
bnh.BlockNumber = &bn
return nil
case "safe":
bn := SafeBlockNumber
bnh.BlockNumber = &bn
return nil
default:
if len(input) == 66 {
hash := common.Hash{}