[rpc] Add rpc to get block headers from any block

pull/3179/head
Janet Liang 5 years ago committed by Leo Chen
parent 0cbd2bcc8d
commit c372ab9fa1
  1. 12
      internal/hmyapi/apiv1/blockchain.go
  2. 12
      internal/hmyapi/apiv2/blockchain.go

@ -569,6 +569,18 @@ func (s *PublicBlockChainAPI) LatestHeader(ctx context.Context) *HeaderInformati
return newHeaderInformation(header) return newHeaderInformation(header)
} }
// GetHeaderByNumber returns block header at given number
func (s *PublicBlockChainAPI) GetHeaderByNumber(ctx context.Context, blockNum rpc.BlockNumber) (*HeaderInformation, error) {
if err := s.isBlockGreaterThanLatest(blockNum); err != nil {
return nil, err
}
header, err := s.b.HeaderByNumber(context.Background(), blockNum)
if err != nil {
return nil, err
}
return newHeaderInformation(header), nil
}
// GetTotalStaking returns total staking by validators, only meant to be called on beaconchain // GetTotalStaking returns total staking by validators, only meant to be called on beaconchain
// explorer node // explorer node
func (s *PublicBlockChainAPI) GetTotalStaking() (*big.Int, error) { func (s *PublicBlockChainAPI) GetTotalStaking() (*big.Int, error) {

@ -520,6 +520,18 @@ func (s *PublicBlockChainAPI) LatestHeader(ctx context.Context) *HeaderInformati
return newHeaderInformation(header) return newHeaderInformation(header)
} }
// GetHeaderByNumber returns block header at given number
func (s *PublicBlockChainAPI) GetHeaderByNumber(ctx context.Context, blockNum uint64) (*HeaderInformation, error) {
if err := s.isBlockGreaterThanLatest(blockNum); err != nil {
return nil, err
}
header, err := s.b.HeaderByNumber(context.Background(), rpc.BlockNumber(blockNum))
if err != nil {
return nil, err
}
return newHeaderInformation(header), nil
}
// GetTotalStaking returns total staking by validators, only meant to be called on beaconchain // GetTotalStaking returns total staking by validators, only meant to be called on beaconchain
// explorer node // explorer node
func (s *PublicBlockChainAPI) GetTotalStaking() (*big.Int, error) { func (s *PublicBlockChainAPI) GetTotalStaking() (*big.Int, error) {

Loading…
Cancel
Save