Repository navigation
Reward Code Redemption endpoints - #540
Conversation
| if redeemCode != "" { | ||
| // Read and burn code in one go | ||
| // Use CTE to capture old is_used value before updating | ||
| sql := `WITH old_row AS ( |
There was a problem hiding this comment.
Intentional choice to push this query as far down into the function as possible so that arbitrary errors in code that is not the actual claim process will just return early with 4xx/5xx. Once we get to this point, we're burning it and grabbing it in a single query (while also checking if it had already been used).
Note that using a code for the wrong mint and using a code that doesn't exist both return the same error.
If we want that to be different, will need to rework this.
|
|
||
| var rewardStateAddress string | ||
| var minVotes int | ||
| err = app.pool.QueryRow(c.Context(), `SELECT reward_manager_state, min_votes FROM sol_reward_manager_inits WHERE mint = @mint`, pgx.NamedArgs{ |
There was a problem hiding this comment.
Shortcut here to get min_votes from the table. Technically this could fail if the table has a different value than what's currently on chain. But that feels highly unlikely.
| rewardClaim := oap_rewards.RewardClaim{ | ||
| RecipientEthAddress: userWalletAddress, | ||
| Amount: amount, | ||
| RewardID: "code", // TODO: Use shared constant/generator |
There was a problem hiding this comment.
this will depend on the result of the query, too, right? like if there's a "gift" reward the code will be the ID?
There was a problem hiding this comment.
All the use cases that use a redeemable code can use 'code' as the rewardId (these don't need to be unique across programatic rewards) and the code itself as the specifier.
| "github.com/jackc/pgx/v5" | ||
| ) | ||
|
|
||
| func getAttestationSignatureForRewardClaimAuthority(rewardClaim oap_rewards.RewardClaim, claimAuthorityKey *ecdsa.PrivateKey) (string, error) { |
There was a problem hiding this comment.
doesn't this already exist?
There was a problem hiding this comment.
There was a problem hiding this comment.
Oh good call. I didn't know that was a thing.
a890130 to
e7b4088
Compare
e7b4088 to
41a5f21
Compare
41a5f21 to
7369b93
Compare
|
|
||
| response, err := oap.Rewards.GetRewardAttestation(c.Context(), &v1.GetRewardAttestationRequest{ | ||
| EthRecipientAddress: userWalletAddress, | ||
| Amount: uint64(amount) / uint64(math.Pow10(int(coinDecimals))), // Convert from token decimals |
There was a problem hiding this comment.
Confirming this is all right?
Opted to re-use the handlers since there is very little difference in the logic between using a code and not using one.
Can split out if we don't love it.
Not going to work as-is, needs some stuff from an unmerged PR. But the bones are there.