Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the amount is null and return 0 instead #2455

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions lib/databases/timescale/spooler/spooler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func CreatePendingWinners(winner worker.EthereumWinnerAnnouncement, tokenDetails

fluidTokenDetails = winner.TokenDetails

network_ = winner.Network
hash = winner.TransactionHash
blockNumber = winner.BlockNumber
senderAddress = winner.FromAddress
senderWinAmount = winner.FromWinAmount
recipientAddress = winner.ToAddress
recipientWinAmount = winner.ToWinAmount
logIndex = winner.LogIndex
application = winner.Application
network_ = winner.Network
hash = winner.TransactionHash
blockNumber = winner.BlockNumber
senderAddress = winner.FromAddress
senderWinAmount = winner.FromWinAmount
recipientAddress = winner.ToAddress
recipientWinAmount = winner.ToWinAmount
logIndex = winner.LogIndex
application = winner.Application
)

for utility, payout := range senderWinAmount {
Expand Down Expand Up @@ -71,17 +71,17 @@ func CreatePendingWinners(winner worker.EthereumWinnerAnnouncement, tokenDetails

// create the sender
pendingWinners = append(pendingWinners, PendingWinner{
TokenDetails: details,
TokenDetails: details,
TransactionHash: hash,
SenderAddress: senderAddress,
SenderAddress: senderAddress,
NativeWinAmount: nativeWinAmount,
UsdWinAmount: usdWinAmount,
Utility: utility,
BlockNumber: blockNumber,
Network: network_,
RewardType: "send",
LogIndex: logIndex,
Application: application,
UsdWinAmount: usdWinAmount,
Utility: utility,
BlockNumber: blockNumber,
Network: network_,
RewardType: "send",
LogIndex: logIndex,
Application: application,
})
}

Expand Down Expand Up @@ -111,9 +111,9 @@ func CreatePendingWinners(winner worker.EthereumWinnerAnnouncement, tokenDetails

// create the recipient
pendingWinners = append(pendingWinners, PendingWinner{
TokenDetails: details,
TokenDetails: details,
TransactionHash: hash,
SenderAddress: recipientAddress,
SenderAddress: recipientAddress,
NativeWinAmount: nativeWinAmount,
UsdWinAmount: usdWinAmount,
Utility: utility,
Expand Down Expand Up @@ -238,15 +238,18 @@ func UnpaidWinningsForCategory(network_ network.BlockchainNetwork, token token_d
token.TokenShortName,
)

var total float64
var total sql.NullFloat64

err := row.Scan(&total)

if err == sql.ErrNoRows {
switch err {
case sql.ErrNoRows:
return 0
}

if err != nil {
case nil:
// nothing

default:
log.Fatal(func(k *log.Log) {
k.Context = Context

Expand All @@ -259,7 +262,11 @@ func UnpaidWinningsForCategory(network_ network.BlockchainNetwork, token token_d
})
}

return total
if total.Valid {
return total.Float64
} else {
return 0
}
}

func GetAndRemoveRewardsForCategory(network_ network.BlockchainNetwork, token token_details.TokenDetails) []worker.EthereumReward {
Expand Down
Loading