@@ -16,8 +16,8 @@ import (
1616
1717const (
1818 yakMintAddress = "ZDaUDL4XFdEct7UgeztrFQAptsvh4ZdhyZDZ1RpxYAK"
19- yakClaimAmount = 2000000000 // 2 YAK with 9 decimals - amount required to claim a prize
20- yakAirdropAmount = 1000000000 // 1 YAK with 9 decimals - amount awarded in coin airdrop prizes
19+ yakClaimAmount = 2000000000 // 2 YAK with 9 decimals - amount required to claim a prize (for Solana transaction)
20+ yakAirdropAmount = 1 // 1 YAK (whole YAK, no decimals) - amount awarded in coin airdrop prizes
2121 prizeReceiverAddress = "EHd892m3xNWGBuAXnafavqcFjXXUZp9bGecdSDNP2SLR"
2222)
2323
@@ -236,7 +236,8 @@ func (app *ApiServer) v1PrizesClaim(c *fiber.Ctx) error {
236236 var metadata PrizeMetadata
237237 if err := json .Unmarshal ([]byte (selectedPrize .Metadata .String ), & metadata ); err == nil {
238238 if metadata .Type == "coin_airdrop" && metadata .Amount == yakAirdropAmount {
239- code , url , err := app .generateRedeemCodeForPrize (ctx , yakMintAddress , yakAirdropAmount )
239+ // yakAirdropAmount is already in whole YAK (no decimals)
240+ code , url , err := app .generateRedeemCodeForPrize (ctx , yakMintAddress , int64 (yakAirdropAmount ))
240241 if err != nil {
241242 app .logger .Error ("Failed to generate redeem code" , zap .Error (err ))
242243 return fiber .NewError (fiber .StatusInternalServerError , "Failed to generate redeem code" )
@@ -278,6 +279,14 @@ func (app *ApiServer) v1PrizesClaim(c *fiber.Ctx) error {
278279 RETURNING prize_id, prize_name, wallet, prize_type, action_data
279280 `
280281
282+ app .logger .Info ("Inserting claimed prize into database" ,
283+ zap .String ("wallet" , req .Wallet ),
284+ zap .String ("signature" , req .Signature ),
285+ zap .String ("prize_id" , selectedPrize .ID ),
286+ zap .String ("prize_name" , selectedPrize .Name ),
287+ zap .Any ("prize_type" , prizeType ),
288+ zap .Bool ("has_action_data" , len (actionData ) > 0 ))
289+
281290 rows , err := app .pool .Query (ctx , sql , pgx.NamedArgs {
282291 "wallet" : req .Wallet ,
283292 "signature" : req .Signature ,
@@ -289,16 +298,35 @@ func (app *ApiServer) v1PrizesClaim(c *fiber.Ctx) error {
289298 "action_data" : actionData ,
290299 })
291300 if err != nil {
292- app .logger .Error ("Failed to insert claimed prize" , zap .Error (err ))
301+ app .logger .Error ("Failed to insert claimed prize" ,
302+ zap .String ("wallet" , req .Wallet ),
303+ zap .String ("signature" , req .Signature ),
304+ zap .Error (err ))
293305 return fiber .NewError (fiber .StatusInternalServerError , "Failed to save result" )
294306 }
307+ app .logger .Info ("Successfully inserted claimed prize, reading response" )
295308
296309 response , err := pgx .CollectExactlyOneRow (rows , pgx .RowToStructByName [PrizeClaimResponse ])
297310 if err != nil {
298- app .logger .Error ("Failed to read response" , zap .Error (err ))
311+ app .logger .Error ("Failed to read response from database" ,
312+ zap .String ("wallet" , req .Wallet ),
313+ zap .String ("signature" , req .Signature ),
314+ zap .String ("prize_id" , selectedPrize .ID ),
315+ zap .Error (err ))
316+ // Try to get more details about the error
317+ if err == pgx .ErrNoRows {
318+ app .logger .Error ("No rows returned from INSERT...RETURNING query" )
319+ }
299320 return fiber .NewError (fiber .StatusInternalServerError , "Failed to read response" )
300321 }
301322
323+ app .logger .Info ("Successfully read response" ,
324+ zap .String ("prize_id" , response .PrizeID ),
325+ zap .String ("prize_name" , response .PrizeName ),
326+ zap .String ("wallet" , response .Wallet ),
327+ zap .Any ("prize_type" , response .PrizeType ),
328+ zap .Bool ("has_action_data" , len (response .ActionData ) > 0 ))
329+
302330 return c .JSON (response )
303331}
304332
0 commit comments