Files
node/internal/ids/rpcaliasreader/alias_reader_client.go
T

58 lines
1.2 KiB
Go

//go:build grpc
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpcaliasreader
import (
"context"
"github.com/luxfi/ids"
aliasreaderpb "github.com/luxfi/node/proto/pb/aliasreader"
)
var _ ids.AliaserReader = (*Client)(nil)
// Client implements alias lookups that talk over RPC.
type Client struct {
client aliasreaderpb.AliasReaderClient
}
// NewClient returns an alias lookup instance connected to a remote alias lookup
// instance
func NewClient(client aliasreaderpb.AliasReaderClient) *Client {
return &Client{client: client}
}
func (c *Client) Lookup(alias string) (ids.ID, error) {
resp, err := c.client.Lookup(context.Background(), &aliasreaderpb.Alias{
Alias: alias,
})
if err != nil {
return ids.Empty, err
}
return ids.ToID(resp.Id)
}
func (c *Client) PrimaryAlias(id ids.ID) (string, error) {
resp, err := c.client.PrimaryAlias(context.Background(), &aliasreaderpb.ID{
Id: id[:],
})
if err != nil {
return "", err
}
return resp.Alias, nil
}
func (c *Client) Aliases(id ids.ID) ([]string, error) {
resp, err := c.client.Aliases(context.Background(), &aliasreaderpb.ID{
Id: id[:],
})
if err != nil {
return nil, err
}
return resp.Aliases, nil
}