Check for no sponsor when validating star sponsorship

This commit is contained in:
John Hyde 2025-09-10 14:23:16 -07:00
parent 8bcf220c5d
commit b7e26b3f1d

View File

@ -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)