The backend for the project formerly known as signet, now known as beignet.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

getrewardfunds.go 3.0 KiB

hace 2 años
hace 2 años
hace 2 años
hace 2 años
hace 2 años
hace 2 años
hace 2 años
hace 2 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. . "github.com/imosed/signet/data"
  6. "github.com/rs/zerolog/log"
  7. )
  8. func getQualifiedRewardFunds() []RewardFund {
  9. var standalone []RewardFund
  10. var currentFromQueues []RewardFund
  11. var allQueues []RewardFund
  12. Db.Table("reward_funds").
  13. Select("reward_funds.id",
  14. "reward_funds.created_at",
  15. "reward_funds.updated_at",
  16. "reward_funds.deleted_at",
  17. "reward_funds.asset",
  18. "reward_funds.fund_wallet",
  19. "reward_funds.selling_wallet",
  20. "reward_funds.issuer_wallet",
  21. "reward_funds.memo",
  22. "reward_funds.price",
  23. "reward_funds.amount_available",
  24. "reward_funds.min_contribution").
  25. Joins("left outer join queue_orders qo on reward_funds.id = qo.reward_fund_id").
  26. Where("qo.reward_fund_id is null").
  27. Scan(&standalone)
  28. tempTable := Db.Table("contributions c").
  29. Select("c.reward_fund_id",
  30. "queue_id",
  31. "sum(amount) amt").
  32. Joins("inner join queue_orders qo on c.reward_fund_id = qo.reward_fund_id").
  33. Group("c.reward_fund_id").
  34. Group("qo.queue_id")
  35. Db.Table("reward_funds").
  36. Select("distinct on (qo.queue_id) reward_funds.id",
  37. "reward_funds.created_at",
  38. "reward_funds.updated_at",
  39. "reward_funds.deleted_at",
  40. "reward_funds.asset",
  41. "reward_funds.fund_wallet",
  42. "reward_funds.selling_wallet",
  43. "reward_funds.issuer_wallet",
  44. "reward_funds.memo",
  45. "reward_funds.price",
  46. "reward_funds.amount_available",
  47. "reward_funds.min_contribution").
  48. Joins("inner join queue_orders qo on reward_funds.id = qo.reward_fund_id").
  49. Joins("left join contributions c on reward_funds.id = c.reward_fund_id").
  50. Joins("inner join (?) tt on reward_funds.id = tt.reward_fund_id",
  51. tempTable,
  52. Db.Where("tt.amount < reward_funds.amount_available or tt.amount is null")).
  53. Order("qo.queue_id").
  54. Order("qo.order").
  55. Scan(&currentFromQueues)
  56. allQueues = append(standalone, currentFromQueues...)
  57. return allQueues
  58. }
  59. func GetRewardFunds(w http.ResponseWriter, r *http.Request) {
  60. var req GetRewardFundsRequest
  61. err := json.NewDecoder(r.Body).Decode(&req)
  62. if err != nil {
  63. log.Error().Err(err).Msg("Could not decode body in GetRewardFunds call")
  64. return
  65. }
  66. var resp GetRewardFundsResponse
  67. var rewardFunds []RewardFund
  68. rewardFunds = getQualifiedRewardFunds()
  69. for _, f := range rewardFunds {
  70. resp.RewardFunds = append(resp.RewardFunds, FundInfo{
  71. ID: f.ID,
  72. CreatedAt: f.CreatedAt,
  73. Asset: f.Asset,
  74. FundWallet: f.FundWallet,
  75. IssuerWallet: f.IssuerWallet,
  76. Memo: f.Memo,
  77. AmountAvailable: f.AmountAvailable,
  78. MinContribution: f.MinContribution,
  79. TelegramLink: f.TelegramLink,
  80. Bonuses: f.Bonuses,
  81. })
  82. }
  83. err = json.NewEncoder(w).Encode(resp)
  84. if err != nil {
  85. log.Error().Err(err).Msg("Could not deliver response in GetRewardFunds call")
  86. }
  87. }
  88. type GetRewardFundsRequest struct {
  89. Offset int `json:"offset"`
  90. }
  91. type GetRewardFundsResponse struct {
  92. RewardFunds []FundInfo `json:"rewardFunds"`
  93. Total int64 `json:"total"`
  94. }