Skip to content

Commit

Permalink
Add API to retrieve a nodes location
Browse files Browse the repository at this point in the history
  • Loading branch information
alanorwick authored and wizeguyy committed Jan 25, 2023
1 parent 64ffd71 commit 6d3921c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,12 @@ func (l Location) ContainsAddress(a Address) bool {
// Ranges are fully inclusive
return uint8(prefix) >= prefixRange.lo && uint8(prefix) <= prefixRange.hi
}

func (l Location) RPCMarshal() []hexutil.Uint64 {
res := make([]hexutil.Uint64, 0)
for _, i := range l {
res = append(res, hexutil.Uint64(i))
}

return res
}
5 changes: 5 additions & 0 deletions internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func (api *PublicBlockChainQuaiAPI) ChainId() (*hexutil.Big, error) {
return nil, fmt.Errorf("chain not synced beyond EIP-155 replay-protection fork block")
}

// NodeLocation is the access call to the location of the node.
func (api *PublicBlockChainQuaiAPI) NodeLocation() []hexutil.Uint64 {
return common.NodeLocation.RPCMarshal()
}

// BlockNumber returns the block number of the chain head.
func (s *PublicBlockChainQuaiAPI) BlockNumber() hexutil.Uint64 {
header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available
Expand Down

0 comments on commit 6d3921c

Please sign in to comment.