Skip to content

Commit

Permalink
Merge pull request #2208 from stakwork/feat/fix_7days_pending_bounties
Browse files Browse the repository at this point in the history
Feat: Added more logs for reversal
  • Loading branch information
elraphty authored Dec 17, 2024
2 parents 4af2473 + 26df2ec commit 30f54f6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"errors"
"fmt"
"log"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -724,15 +725,26 @@ func (db database) ProcessReversePayments(paymentId uint) error {
paymentHistory.PaymentStatus = PaymentFailed

workspace_uuid := paymentHistory.WorkspaceUuid
log.Println("WorkspaceUuid =====", workspace_uuid)

// get workspace
workspace := Workspace{}
tx.Model(&Workspace{}).Where("uuid = ?", workspace_uuid).Find(&workspace)

log.Println("Workspace =====", workspace)

// check that the sum of budget withdrawals and payments is not greater than deposits

var depositAmount uint
tx.Model(&NewPaymentHistory{}).Where("workspace_uuid = ?", workspace_uuid).Where("status = ?", true).Where("payment_type = ?", "deposit").Select("SUM(amount)").Row().Scan(&depositAmount)

log.Println("DepositAmount =====", depositAmount)

var withdrawalAmount uint
tx.Model(&NewPaymentHistory{}).Where("workspace_uuid = ?", workspace_uuid).Where("status = ?", true).Where("payment_type != ?", "deposit").Select("SUM(amount)").Row().Scan(&withdrawalAmount)

log.Println("WithdrawalAmount =====", withdrawalAmount)

if withdrawalAmount > depositAmount {
tx.Rollback()
return errors.New("cannot perform this reversal")
Expand Down

0 comments on commit 30f54f6

Please sign in to comment.