Skip to content

fix: unlockcode to UUID - #2770

Merged
Evanfeenstra merged 2 commits into
stakwork:masterfrom
fayekelmith:fix/unlock-code
Oct 22, 2025
Merged

fix: unlockcode to UUID#2770
Evanfeenstra merged 2 commits into
stakwork:masterfrom
fayekelmith:fix/unlock-code

Conversation

@fayekelmith

Copy link
Copy Markdown
Contributor

Describe your changes

Issue ticket number and link

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have tested on Chrome and Firefox
  • I have tested on a mobile device
  • I have provided a screenshot or recording of changes in my PR if there were updates to the frontend

@Evanfeenstra
Evanfeenstra requested a review from Copilot October 22, 2025 18:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the unlock code generation mechanism from using the xid library to using UUID (Universally Unique Identifier). The change addresses potential collision risks by switching to a more robust identifier format.

Key Changes:

  • Replaced xid library with standard uuid package for unlock code generation
  • Updated database schema to accommodate longer UUID strings (36 characters vs 6)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
handlers/bounty.go Removed xid dependency and updated generateUnlockCode() to return UUID strings
db/structs.go Increased UnlockCode field length from 6 to 36 characters in both Bounty and NewBounty structs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread db/structs.go
PhasePriority *int `json:"phase_priority"`
PaymentPending bool `gorm:"default:false" json:"payment_pending"`
PaymentFailed bool `gorm:"default:false" json:"payment_failed"`
AccessRestriction *AccessRestrictionType `gorm:"type:varchar(20);default:null" json:"access_restriction,omitempty"`

Copilot AI Oct 22, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This schema change from varchar(6) to varchar(36) requires a database migration. Ensure that a migration script is included to alter existing database columns, otherwise existing deployments will fail when writing UUID values to the shorter column.

Suggested change
AccessRestriction *AccessRestrictionType `gorm:"type:varchar(20);default:null" json:"access_restriction,omitempty"`
AccessRestriction *AccessRestrictionType `gorm:"type:varchar(20);default:null" json:"access_restriction,omitempty"`
// NOTE: If upgrading from a previous schema where unlock_code was varchar(6), you MUST run the following migration:
// ALTER TABLE bounties ALTER COLUMN unlock_code TYPE varchar(36);

Copilot uses AI. Check for mistakes.
@Evanfeenstra

Copy link
Copy Markdown
Contributor

just do 6 random lowercase/uppercase letters. that would work right?

@Evanfeenstra

Copy link
Copy Markdown
Contributor
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

func GenerateRandomCode(length int) string {
    result := make([]byte, length)
    for i := range result {
        result[i] = letters[rand.Intn(len(letters))]
    }
    return string(result)
}

@Evanfeenstra

Copy link
Copy Markdown
Contributor

and js:

function generateRandomCode(length = 6) {
    const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    const randomValues = new Uint8Array(length);
    crypto.getRandomValues(randomValues);
    
    return Array.from(randomValues)
        .map(x => letters[x % letters.length])
        .join('');
}

Comment thread handlers/bounty.go Outdated
// rand.Seed(time.Now().UnixNano())
// return fmt.Sprintf("%06d", rand.Intn(1000000))
return xid.New().String()
length := 36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it needs to be 6 since its varchar(6)

@Evanfeenstra
Evanfeenstra merged commit 208827d into stakwork:master Oct 22, 2025
2 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants