From 1a568ba765ac0f456255be62f8f7f8ecfafc437e Mon Sep 17 00:00:00 2001 From: John Hyde Date: Tue, 9 Sep 2025 16:25:40 -0700 Subject: [PATCH] Add GetPointOwnership function for comprehensive ownership queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- client.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/client.go b/client.go index d0dd90f..b6eb41b 100644 --- a/client.go +++ b/client.go @@ -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