mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-15 00:13:46 +00:00
feat(rpc.BlockNumber): Add "finalized" and "safe" case in marshal and unmarshal interface. (#213)
Add finalized, safe case
This commit is contained in:
parent
0854d4bbb1
commit
8224bc8b9c
1 changed files with 18 additions and 0 deletions
18
rpc/types.go
18
rpc/types.go
|
|
@ -87,6 +87,12 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
||||||
case "pending":
|
case "pending":
|
||||||
*bn = PendingBlockNumber
|
*bn = PendingBlockNumber
|
||||||
return nil
|
return nil
|
||||||
|
case "finalized":
|
||||||
|
*bn = FinalizedBlockNumber
|
||||||
|
return nil
|
||||||
|
case "safe":
|
||||||
|
*bn = SafeBlockNumber
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
blckNum, err := hexutil.DecodeUint64(input)
|
blckNum, err := hexutil.DecodeUint64(input)
|
||||||
|
|
@ -111,6 +117,10 @@ func (bn BlockNumber) MarshalText() ([]byte, error) {
|
||||||
return []byte("latest"), nil
|
return []byte("latest"), nil
|
||||||
case PendingBlockNumber:
|
case PendingBlockNumber:
|
||||||
return []byte("pending"), nil
|
return []byte("pending"), nil
|
||||||
|
case FinalizedBlockNumber:
|
||||||
|
return []byte("finalized"), nil
|
||||||
|
case SafeBlockNumber:
|
||||||
|
return []byte("safe"), nil
|
||||||
default:
|
default:
|
||||||
return hexutil.Uint64(bn).MarshalText()
|
return hexutil.Uint64(bn).MarshalText()
|
||||||
}
|
}
|
||||||
|
|
@ -157,6 +167,14 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
|
||||||
bn := PendingBlockNumber
|
bn := PendingBlockNumber
|
||||||
bnh.BlockNumber = &bn
|
bnh.BlockNumber = &bn
|
||||||
return nil
|
return nil
|
||||||
|
case "finalized":
|
||||||
|
bn := FinalizedBlockNumber
|
||||||
|
bnh.BlockNumber = &bn
|
||||||
|
return nil
|
||||||
|
case "safe":
|
||||||
|
bn := SafeBlockNumber
|
||||||
|
bnh.BlockNumber = &bn
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
if len(input) == 66 {
|
if len(input) == 66 {
|
||||||
hash := common.Hash{}
|
hash := common.Hash{}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue