From b7e26b3f1d46c41f554f4bc947ecce6229d4ff2f Mon Sep 17 00:00:00 2001 From: John Hyde Date: Wed, 10 Sep 2025 14:23:16 -0700 Subject: [PATCH] Check for no sponsor when validating star sponsorship --- client.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client.go b/client.go index 9a103d2..b5b9b00 100644 --- a/client.go +++ b/client.go @@ -254,6 +254,22 @@ func (c *Client) IsShipActive(ctx context.Context, point uint32) (bool, error) { return resp.AzimuthIsActive.Value, nil } +// GetSponsor retrieves the sponsor of a point +func (c *Client) HasSponsor(ctx context.Context, point uint32) (bool, error) { + // Convert point to BigInt + pointBigInt := NewBigIntFromUint32(point) + + // Use generated GraphQL client + resp, err := HasSponsor(ctx, c.gqlClient, "latest", c.contractAddress, pointBigInt) + if err != nil { + return false, fmt.Errorf("failed to query sponsor: %w", err) + } + + // Parse sponsor point number from BigInt + hasSponsor := resp.AzimuthHasSponsor.Value + return hasSponsor, nil +} + // GetSponsor retrieves the sponsor of a point func (c *Client) GetSponsor(ctx context.Context, point uint32) (uint32, error) { // Get current block hash @@ -426,6 +442,14 @@ func (c *Client) getLatestBlockHash(ctx context.Context) (string, error) { // ValidateStarSponsorship validates that a star is sponsored by the expected galaxy func ValidateStarSponsorship(ctx context.Context, starID uint32, expectedGalaxyID uint32, client *Client) error { + hasSponsor, err := client.HasSponsor(ctx, starID) + if err != nil { + return fmt.Errorf("failed to get sponsor: %w", err) + } + if !hasSponsor { + return fmt.Errorf("star %d is not sponsored by galaxy %d (no sponsor)", + starID, expectedGalaxyID) + } sponsor, err := client.GetSponsor(ctx, starID) if err != nil { return fmt.Errorf("failed to get sponsor: %w", err)