mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
JSON parsing of safe & finalized (#4524)
This commit is contained in:
parent
7896fc60b6
commit
8de7c5e41c
26
rpc/types.go
26
rpc/types.go
@ -71,15 +71,15 @@ type BlockNumber int64
|
||||
type Timestamp uint64
|
||||
|
||||
const (
|
||||
FinalizeBlockNumber = BlockNumber(-4)
|
||||
SafeBlockNumber = BlockNumber(-3)
|
||||
PendingBlockNumber = BlockNumber(-2)
|
||||
LatestBlockNumber = BlockNumber(-1)
|
||||
EarliestBlockNumber = BlockNumber(0)
|
||||
FinalizedBlockNumber = BlockNumber(-4)
|
||||
SafeBlockNumber = BlockNumber(-3)
|
||||
PendingBlockNumber = BlockNumber(-2)
|
||||
LatestBlockNumber = BlockNumber(-1)
|
||||
EarliestBlockNumber = BlockNumber(0)
|
||||
)
|
||||
|
||||
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
|
||||
// - "latest", "earliest" or "pending" as string arguments
|
||||
// - "latest", "earliest", "pending", "safe", or "finalized" as string arguments
|
||||
// - the block number
|
||||
// Returned errors:
|
||||
// - an invalid block number error when the given argument isn't a known strings
|
||||
@ -100,6 +100,12 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
||||
case "pending":
|
||||
*bn = PendingBlockNumber
|
||||
return nil
|
||||
case "safe":
|
||||
*bn = SafeBlockNumber
|
||||
return nil
|
||||
case "finalized":
|
||||
*bn = FinalizedBlockNumber
|
||||
return nil
|
||||
case "null":
|
||||
*bn = LatestBlockNumber
|
||||
return nil
|
||||
@ -173,6 +179,14 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
|
||||
bn := PendingBlockNumber
|
||||
bnh.BlockNumber = &bn
|
||||
return nil
|
||||
case "safe":
|
||||
bn := SafeBlockNumber
|
||||
bnh.BlockNumber = &bn
|
||||
return nil
|
||||
case "finalized":
|
||||
bn := FinalizedBlockNumber
|
||||
bnh.BlockNumber = &bn
|
||||
return nil
|
||||
default:
|
||||
if len(input) == 66 {
|
||||
hash := common.Hash{}
|
||||
|
@ -50,7 +50,7 @@ func _GetBlockNumber(requireCanonical bool, blockNrOrHash rpc.BlockNumberOrHash,
|
||||
}
|
||||
case rpc.EarliestBlockNumber:
|
||||
blockNumber = 0
|
||||
case rpc.FinalizeBlockNumber:
|
||||
case rpc.FinalizedBlockNumber:
|
||||
blockNumber, err = GetFinalizedBlockNumber(tx)
|
||||
if err != nil {
|
||||
return 0, common.Hash{}, false, err
|
||||
|
Loading…
Reference in New Issue
Block a user