CheckTokenApplyLimits checks developer and keypair for token apply limitations.
(db *gorp.DbMap, developer int64, account utils.AccountAddress, userLimits int64, accountLimits int64)
| 37 | |
| 38 | // CheckTokenApplyLimits checks developer and keypair for token apply limitations. |
| 39 | func CheckTokenApplyLimits(db *gorp.DbMap, developer int64, account utils.AccountAddress, userLimits int64, accountLimits int64) (err error) { |
| 40 | beginOfTheDay := time.Now().UTC().Truncate(24 * time.Hour).Unix() |
| 41 | |
| 42 | recordCount, err := db.SelectInt(`SELECT COUNT(1) AS "cnt" FROM "token_apply" WHERE "created" >= ? AND "developer_id" = ?`, |
| 43 | beginOfTheDay, developer) |
| 44 | if err != nil { |
| 45 | err = errors.Wrapf(err, "get developer daily token applied count failed") |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | if recordCount >= userLimits { |
| 50 | err = errors.New("user quota exceeded") |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | recordCount, err = db.SelectInt(`SELECT COUNT(1) AS "cnt" FROM "token_apply" WHERE "created" >= ? AND "account" = ?`, |
| 55 | beginOfTheDay, account) |
| 56 | if err != nil { |
| 57 | err = errors.Wrapf(err, "get account daily token applied count failed") |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | if recordCount >= accountLimits { |
| 62 | err = errors.New("account quota exceeded") |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | // AddTokenApplyRecord add new token apply record to database. |
| 70 | func AddTokenApplyRecord(db *gorp.DbMap, developer int64, account utils.AccountAddress, amount uint64) (r *TokenApply, err error) { |