-
Notifications
You must be signed in to change notification settings - Fork 667
/
subnet_lookup_server.go
42 lines (35 loc) · 1.03 KB
/
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
// Copyright (C) 2019-2021, 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"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/gsubnetlookup/gsubnetlookupproto"
)
var _ gsubnetlookupproto.SubnetLookupServer = &Server{}
// Server is a subnet lookup that is managed over RPC.
type Server struct {
gsubnetlookupproto.UnimplementedSubnetLookupServer
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 *gsubnetlookupproto.SubnetIDRequest,
) (*gsubnetlookupproto.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 &gsubnetlookupproto.SubnetIDResponse{
Id: id[:],
}, nil
}