| @@ -59,6 +59,7 @@ type Contribution struct { | |||||
| Wallet string `json:"wallet"` | Wallet string `json:"wallet"` | ||||
| Amount float64 `gorm:"type:decimal(19,7)" json:"amount"` | Amount float64 `gorm:"type:decimal(19,7)" json:"amount"` | ||||
| Submitted bool `gorm:"type:boolean" json:"submitted"` | Submitted bool `gorm:"type:boolean" json:"submitted"` | ||||
| Received bool `gorm:"type:boolean" json:"received"` | |||||
| TransactionID string `json:"transactionID"` | TransactionID string `json:"transactionID"` | ||||
| RewardFundID uint `json:"rewardFundID"` | RewardFundID uint `json:"rewardFundID"` | ||||
| } | } | ||||
| @@ -7,8 +7,10 @@ import ( | |||||
| . "github.com/imosed/signet/data" | . "github.com/imosed/signet/data" | ||||
| "github.com/imosed/signet/utils" | "github.com/imosed/signet/utils" | ||||
| "github.com/rs/zerolog/log" | |||||
| "github.com/stellar/go/keypair" | "github.com/stellar/go/keypair" | ||||
| "github.com/stellar/go/txnbuild" | "github.com/stellar/go/txnbuild" | ||||
| "github.com/stellar/go/xdr" | |||||
| ) | ) | ||||
| type RewardDistributionInfo struct { | type RewardDistributionInfo struct { | ||||
| @@ -48,6 +50,16 @@ func DistributeRewards(w http.ResponseWriter, r *http.Request) { | |||||
| }, | }, | ||||
| req.Payments), | req.Payments), | ||||
| ) | ) | ||||
| if err != nil { | |||||
| log.Error().Err(err).Msg("Could not distribute asset") | |||||
| } | |||||
| if resp.Success { | |||||
| var receivedWallets []string | |||||
| for _, payment := range req.Payments { | |||||
| receivedWallets = append(receivedWallets, payment.Destination) | |||||
| } | |||||
| Db.Table("contributions").Where("wallet in ? and reward_fund_id = ? and not submitted = true", receivedWallets, req.RewardFundID).Updates(Contribution{Received: true}) | |||||
| } | |||||
| } | } | ||||
| err = json.NewEncoder(w).Encode(resp) | err = json.NewEncoder(w).Encode(resp) | ||||
| @@ -59,8 +71,13 @@ func DistributeRewards(w http.ResponseWriter, r *http.Request) { | |||||
| func constructOperations(sourceAccount *keypair.Full, asset txnbuild.CreditAsset, payments []RewardDistributionInfo) []txnbuild.Operation { | func constructOperations(sourceAccount *keypair.Full, asset txnbuild.CreditAsset, payments []RewardDistributionInfo) []txnbuild.Operation { | ||||
| var operations []txnbuild.Operation | var operations []txnbuild.Operation | ||||
| for _, payment := range payments { | for _, payment := range payments { | ||||
| operations = append(operations, &txnbuild.Payment{ | |||||
| Destination: payment.Destination, | |||||
| operations = append(operations, &txnbuild.CreateClaimableBalance{ | |||||
| Destinations: []txnbuild.Claimant{ | |||||
| { | |||||
| Destination: payment.Destination, | |||||
| Predicate: xdr.ClaimPredicate{}, | |||||
| }, | |||||
| }, | |||||
| Amount: fmt.Sprintf("%f", payment.Amount), | Amount: fmt.Sprintf("%f", payment.Amount), | ||||
| Asset: asset, | Asset: asset, | ||||
| SourceAccount: sourceAccount.Address(), | SourceAccount: sourceAccount.Address(), | ||||
| @@ -51,7 +51,7 @@ func GetRewardFund(resp http.ResponseWriter, req *http.Request) { | |||||
| baseQuery.Select("wallet, sum(amount) amount").Group("wallet").Order("wallet").Scan(&contribs.List) | baseQuery.Select("wallet, sum(amount) amount").Group("wallet").Order("wallet").Scan(&contribs.List) | ||||
| baseCount.Group("wallet").Count(&contribs.Total) | baseCount.Group("wallet").Count(&contribs.Total) | ||||
| } else { | } else { | ||||
| baseQuery.Select("wallet, amount, created_at").Order("created_at desc").Scan(&contribs.List) | |||||
| baseQuery.Select("wallet, amount, created_at").Order("created_at desc").Debug().Scan(&contribs.List) | |||||
| baseCount.Count(&contribs.Total) | baseCount.Count(&contribs.Total) | ||||
| } | } | ||||
| @@ -41,6 +41,7 @@ func main() { | |||||
| router.HandleFunc("/CreateRewardFund", endpoints.CreateRewardFund) | router.HandleFunc("/CreateRewardFund", endpoints.CreateRewardFund) | ||||
| router.HandleFunc("/CloseRewardFund", endpoints.CloseRewardFund) | router.HandleFunc("/CloseRewardFund", endpoints.CloseRewardFund) | ||||
| router.HandleFunc("/SubmitRewardFund", endpoints.SubmitFund) | router.HandleFunc("/SubmitRewardFund", endpoints.SubmitFund) | ||||
| router.HandleFunc("/DistributeRewardFund", endpoints.DistributeRewards) | |||||
| // router.HandleFunc("/SubmitFund", endpoints.SubmitFund) | // router.HandleFunc("/SubmitFund", endpoints.SubmitFund) | ||||
| router.HandleFunc("/GetBalance", endpoints.GetBalance) | router.HandleFunc("/GetBalance", endpoints.GetBalance) | ||||
| router.HandleFunc("/Contribute", endpoints.Contribute) | router.HandleFunc("/Contribute", endpoints.Contribute) | ||||