@@ -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(),