Add GetPointOwnership function for comprehensive ownership queries

- Add PointOwnership struct with Owner, IsActive, HasSponsor, Sponsor fields
- Implement GetPointOwnership function using GraphQL queries to azimuth-watcher
- Use "latest" block hash for efficiency
- Properly handle sponsor detection using HasSponsor query
- Support galaxy ~zod (point 0) as valid sponsor

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
John Hyde 2025-09-09 16:25:40 -07:00
parent 60ee72d192
commit 1a568ba765

View File

@ -66,6 +66,14 @@ type CachedKey struct {
ExpiresAt time.Time
}
// PointOwnership represents point ownership information from Azimuth
type PointOwnership struct {
Owner string `json:"owner"`
IsActive bool `json:"is_active"`
HasSponsor bool `json:"has_sponsor"`
Sponsor uint32 `json:"sponsor,omitempty"`
}
// NewClient creates a new Azimuth client with default configuration
func NewClient(endpoint string) *Client {
return NewClientWithOptions(ClientOptions{
@ -296,6 +304,49 @@ func (c *Client) GetOwner(ctx context.Context, point uint32) (string, error) {
return resp.AzimuthGetOwner.Value, nil
}
// GetPointOwnership retrieves comprehensive ownership information for a point
func (c *Client) GetPointOwnership(ctx context.Context, point uint32) (*PointOwnership, error) {
// Convert point to BigInt
pointBigInt := NewBigIntFromUint32(point)
// Query for owner using "latest" block
ownerResp, err := GetOwner(ctx, c.gqlClient, "latest", c.contractAddress, pointBigInt)
if err != nil {
return nil, fmt.Errorf("failed to query owner: %w", err)
}
// Query for active status
activeResp, err := IsActive(ctx, c.gqlClient, "latest", c.contractAddress, pointBigInt)
if err != nil {
return nil, fmt.Errorf("failed to query active status: %w", err)
}
// Query for sponsor status using HasSponsor
hasSponsorResp, err := HasSponsor(ctx, c.gqlClient, "latest", c.contractAddress, pointBigInt)
if err != nil {
return nil, fmt.Errorf("failed to query sponsor status: %w", err)
}
// Query for sponsor point number
sponsorPoint := uint32(0)
if hasSponsorResp.AzimuthHasSponsor.Value {
sponsorResp, err := GetSponsor(ctx, c.gqlClient, pointBigInt, "latest", c.contractAddress)
if err != nil {
return nil, fmt.Errorf("failed to query sponsor: %w", err)
}
if parsed, err := strconv.ParseUint(sponsorResp.AzimuthGetSponsor.Value, 10, 32); err == nil {
sponsorPoint = uint32(parsed)
}
}
return &PointOwnership{
Owner: ownerResp.AzimuthGetOwner.Value,
IsActive: activeResp.AzimuthIsActive.Value,
HasSponsor: hasSponsorResp.AzimuthHasSponsor.Value,
Sponsor: sponsorPoint,
}, nil
}
// getShipKeys retrieves all keys for a ship from the API
func (c *Client) getShipKeys(ctx context.Context, point uint32) (*ShipKeys, error) {
// Get current block hash