Pārlūkot izejas kodu

Fix a couple bugs and send claimable balance instead

master
Jared pirms 1 gada
vecāks
revīzija
f31060c7e5
4 mainītis faili ar 22 papildinājumiem un 3 dzēšanām
  1. +1
    -0
      data/context.go
  2. +19
    -2
      endpoints/distributerewards.go
  3. +1
    -1
      endpoints/getrewardfund.go
  4. +1
    -0
      main.go

+ 1
- 0
data/context.go Parādīt failu

@@ -59,6 +59,7 @@ type Contribution struct {
Wallet string `json:"wallet"`
Amount float64 `gorm:"type:decimal(19,7)" json:"amount"`
Submitted bool `gorm:"type:boolean" json:"submitted"`
Received bool `gorm:"type:boolean" json:"received"`
TransactionID string `json:"transactionID"`
RewardFundID uint `json:"rewardFundID"`
}


+ 19
- 2
endpoints/distributerewards.go Parādīt failu

@@ -7,8 +7,10 @@ import (

. "github.com/imosed/signet/data"
"github.com/imosed/signet/utils"
"github.com/rs/zerolog/log"
"github.com/stellar/go/keypair"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
)

type RewardDistributionInfo struct {
@@ -48,6 +50,16 @@ func DistributeRewards(w http.ResponseWriter, r *http.Request) {
},
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)
@@ -59,8 +71,13 @@ func DistributeRewards(w http.ResponseWriter, r *http.Request) {
func constructOperations(sourceAccount *keypair.Full, asset txnbuild.CreditAsset, payments []RewardDistributionInfo) []txnbuild.Operation {
var operations []txnbuild.Operation
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),
Asset: asset,
SourceAccount: sourceAccount.Address(),


+ 1
- 1
endpoints/getrewardfund.go Parādīt failu

@@ -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)
baseCount.Group("wallet").Count(&contribs.Total)
} 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)
}



+ 1
- 0
main.go Parādīt failu

@@ -41,6 +41,7 @@ func main() {
router.HandleFunc("/CreateRewardFund", endpoints.CreateRewardFund)
router.HandleFunc("/CloseRewardFund", endpoints.CloseRewardFund)
router.HandleFunc("/SubmitRewardFund", endpoints.SubmitFund)
router.HandleFunc("/DistributeRewardFund", endpoints.DistributeRewards)
// router.HandleFunc("/SubmitFund", endpoints.SubmitFund)
router.HandleFunc("/GetBalance", endpoints.GetBalance)
router.HandleFunc("/Contribute", endpoints.Contribute)


Notiek ielāde…
Atcelt
Saglabāt