-
Notifications
You must be signed in to change notification settings - Fork 643
/
subnet_lookup_server.go
43 lines (35 loc) · 1022 Bytes
/
subnet_lookup_server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package gsubnetlookup
import (
"context"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
subnetlookuppb "github.com/ava-labs/avalanchego/proto/pb/subnetlookup"
)
var _ subnetlookuppb.SubnetLookupServer = &Server{}
// Server is a subnet lookup that is managed over RPC.
type Server struct {
subnetlookuppb.UnsafeSubnetLookupServer
aliaser snow.SubnetLookup
}
// NewServer returns a subnet lookup connected to a remote subnet lookup
func NewServer(aliaser snow.SubnetLookup) *Server {
return &Server{aliaser: aliaser}
}
func (s *Server) SubnetID(
_ context.Context,
req *subnetlookuppb.SubnetIDRequest,
) (*subnetlookuppb.SubnetIDResponse, error) {
chainID, err := ids.ToID(req.ChainId)
if err != nil {
return nil, err
}
id, err := s.aliaser.SubnetID(chainID)
if err != nil {
return nil, err
}
return &subnetlookuppb.SubnetIDResponse{
Id: id[:],
}, nil
}