The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package data
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/rs/zerolog/log"
  6. "github.com/spf13/viper"
  7. "gorm.io/driver/postgres"
  8. "gorm.io/gorm"
  9. )
  10. type ModelBase struct {
  11. ID uint `gorm:"primarykey" json:"id"`
  12. CreatedAt time.Time `json:"createdAt"`
  13. UpdatedAt time.Time `json:"updatedAt"`
  14. DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
  15. }
  16. type Bonus struct {
  17. ModelBase
  18. Goal float64 `json:"goal"`
  19. Percent float64 `json:"percent"`
  20. RewardFundID uint `json:"rewardFundID"`
  21. }
  22. type Queue struct {
  23. ModelBase
  24. Name string `gorm:"type:varchar(50)" json:"name"`
  25. Orders []QueueOrder `json:"order"`
  26. }
  27. type RewardFund struct {
  28. ModelBase
  29. Asset string `json:"asset"`
  30. FundWallet string `json:"fundWallet"`
  31. FundSecret string `json:"fundSecret"`
  32. SellingWallet string `json:"sellingWallet"`
  33. IssuerWallet string `json:"issuerWallet"`
  34. Memo string `json:"memo"`
  35. Price float64 `gorm:"type:decimal(19,7)" json:"price"`
  36. AmountAvailable float64 `gorm:"type:decimal(19,7)" json:"amountAvailable"`
  37. MinContribution float64 `gorm:"type:decimal(19,7)" json:"minContribution"`
  38. TelegramLink string `json:"telegramLink"`
  39. Contributions []Contribution `json:"contributions"`
  40. Bonuses []Bonus `json:"bonuses"`
  41. QueueOrder QueueOrder `json:"queueOrder"`
  42. }
  43. type QueueOrder struct {
  44. ModelBase
  45. QueueID uint `json:"queueID"`
  46. RewardFundID uint `json:"rewardFundID"`
  47. Order uint16 `gorm:"type:smallint" json:"order"`
  48. }
  49. type Contribution struct {
  50. ModelBase
  51. Wallet string `json:"wallet"`
  52. Amount float64 `gorm:"type:decimal(19,7)" json:"amount"`
  53. Submitted bool `gorm:"type:boolean" json:"submitted"`
  54. TransactionID string `json:"transactionID"`
  55. RewardFundID uint `json:"rewardFundID"`
  56. }
  57. type User struct {
  58. ModelBase
  59. Username string `json:"username"`
  60. Password string `json:"password"`
  61. Privileges uint `json:"admin"`
  62. }
  63. var Db *gorm.DB
  64. func InitializeDatabase() {
  65. var err error
  66. dcs := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s",
  67. viper.GetString("database.host"),
  68. viper.GetString("database.user"),
  69. viper.GetString("database.password"),
  70. viper.GetString("database.name"),
  71. viper.GetInt("database.port"),
  72. viper.GetString("database.ssl"))
  73. Db, err = gorm.Open(postgres.Open(dcs), &gorm.Config{})
  74. if err != nil {
  75. log.Error().Err(err).Msg("Could not open database")
  76. }
  77. err = Db.AutoMigrate(User{}, Queue{}, RewardFund{}, QueueOrder{}, Contribution{}, Bonus{})
  78. if err != nil {
  79. log.Error().Err(err).Msg("Could not migrate database")
  80. }
  81. }