feat(rpc.BlockNumber): Add "finalized" and "safe" case in marshal and unmarshal interface. (#213)

Add finalized, safe case
This commit is contained in:
maskpp 2023-02-10 17:11:39 +08:00 committed by GitHub
parent 0854d4bbb1
commit 8224bc8b9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -87,6 +87,12 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case "pending":
*bn = PendingBlockNumber
return nil
case "finalized":
*bn = FinalizedBlockNumber
return nil
case "safe":
*bn = SafeBlockNumber
return nil
}
blckNum, err := hexutil.DecodeUint64(input)
@ -111,6 +117,10 @@ func (bn BlockNumber) MarshalText() ([]byte, error) {
return []byte("latest"), nil
case PendingBlockNumber:
return []byte("pending"), nil
case FinalizedBlockNumber:
return []byte("finalized"), nil
case SafeBlockNumber:
return []byte("safe"), nil
default:
return hexutil.Uint64(bn).MarshalText()
}
@ -157,6 +167,14 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
bn := PendingBlockNumber
bnh.BlockNumber = &bn
return nil
case "finalized":
bn := FinalizedBlockNumber
bnh.BlockNumber = &bn
return nil
case "safe":
bn := SafeBlockNumber
bnh.BlockNumber = &bn
return nil
default:
if len(input) == 66 {
hash := common.Hash{}