Skip to content

Add create code routes - #537

Merged
raymondjacobson merged 3 commits into
mainfrom
rj-codes2
Nov 6, 2025
Merged

raymondjacobson merged 3 commits into
mainfrom
rj-codes2

Conversation

@raymondjacobson

Copy link
Copy Markdown
Member
POST /v1/rewards/code

body: {
	signature: XYZ,
	mint: yyZ..xYAK,
	amount: 12345
}
  • Add endpoint for creating reward codes
  • Added config.RewardCodeAuthorizedKeys for authorized keys who are able to post
  • Verify signature for authorized key when adding new row
  • Add tests

Does not create the core reward type just yet, that will be a subsequent PR

Comment thread config/config.go Outdated
Cfg.AudiusdChainID = core_config.StageAcdcChainID
Cfg.AudiusdEntityManagerAddress = core_config.StageAcdcAddress
Cfg.AudiusAppUrl = "https://staging.audius.co"
Cfg.RewardCodeAuthorizedKeys = []string{"9XeZbswbSSUU4AHVArQbTQjAEjAPhVweGU5cogBVkvh4"}

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.

might have missed discussion on this but should these not be dynamic and on a per-mint basis?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah, figured it can be a future change. it needs more machinery, probably another column somewhere. for now ok like this

})
}

func TestVerifySignature(t *testing.T) {

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.

could test that wallets in positions other than the first also work

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will add later in next PR

type CreateRewardCodeRequest struct {
Signature string `json:"signature" validate:"required"`
Mint string `json:"mint" validate:"required"`
Amount int64 `json:"amount" validate:"required,min=1"`

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.

could add a max? configurable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

probably but idk what it should be yet

type: string
description: The coin mint address
example: "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM"
amount:

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.

What's the plan for creating a set of codes? Hit this endpoint N times?
Or should we have an optional count/number of codes to generate field?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

N times!

properties:
signature:
type: string
description: Base64-encoded Solana Ed25519 signature of the string "code"

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.

What's the secret code?!
.
.
.
.
..."code"

charsLen := big.NewInt(int64(len(codeChars)))

for i := 0; i < codeLength; i++ {
num, err := rand.Int(rand.Reader, charsLen)

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.

I am surprised there is not a crypto function that does this already. Any concerns with randomness/seed here?

)

const (
signedMessage = "code"

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.

nit: variable name here is a tad generic, I had to jump and forth a few times to figure out how it was used :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will change in next PR

return fiber.NewError(fiber.StatusInternalServerError, "Database error: "+err.Error())
}

response, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[CreateRewardCodeResponse])

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.

Assuming we would get an error of some sort in this section if we collide. Just have the user try again in that case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah AI originally made this try a few times... too complicated. probablity low

Comment thread config/config.go
Cfg.AudiusdChainID = core_config.ProdAcdcChainID
Cfg.AudiusdEntityManagerAddress = core_config.ProdAcdcAddress
Cfg.AudiusAppUrl = "https://audius.co"
Cfg.RewardCodeAuthorizedKeys = []string{"DDT15s6MMNxE4jkyGN46wNYqrgLWofT6WAvWtjYYrCUq"}

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.

  1. Was kind of hoping we might DB this, but I guess this is a little more intention on adding new keys.
  2. Miiiiight want to map authorized keys to the mints they are allowed to generate codes for.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. db in future. not now! i think this probably should be indexed because the data will be available on various pools
  2. only 1 mint we care abt atm

@raymondjacobson
raymondjacobson merged commit eb7e584 into main Nov 6, 2025
5 of 6 checks passed
@raymondjacobson
raymondjacobson deleted the rj-codes2 branch November 6, 2025 21:30
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.

4 participants