/
farm.go
44 lines (35 loc) · 1.09 KB
/
farm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package orm
import "github.com/fastock/fastock-chain/x/backend/types"
// AddClaimInfo insert farm claimed coins into db
func (orm *ORM) AddClaimInfo(claimInfos []*types.ClaimInfo) (addedCnt int, err error) {
orm.singleEntryLock.Lock()
defer orm.singleEntryLock.Unlock()
tx := orm.db.Begin()
defer orm.deferRollbackTx(tx, err)
cnt := 0
for _, claimInfo := range claimInfos {
if claimInfo != nil {
ret := tx.Create(claimInfo)
if ret.Error != nil {
return cnt, ret.Error
} else {
cnt++
}
}
}
tx.Commit()
return cnt, nil
}
// nolint
func (orm *ORM) GetAccountClaimInfos(address string) []types.ClaimInfo {
var claimInfos []types.ClaimInfo
query := orm.db.Model(types.ClaimInfo{}).Where("address = ?", address)
query.Order("timestamp asc").Find(&claimInfos)
return claimInfos
}
func (orm *ORM) GetAccountClaimedByPool(address string, poolName string) []types.ClaimInfo {
var claimInfos []types.ClaimInfo
query := orm.db.Model(types.ClaimInfo{}).Where("address = ? and pool_name = ?", address, poolName)
query.Order("timestamp asc").Find(&claimInfos)
return claimInfos
}