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

Replace the locations of the accounts for testing a Mint #2442

Merged
merged 8 commits into from
Dec 11, 2023
15 changes: 13 additions & 2 deletions cmd/microservice-solana-transactions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,27 @@ func main() {
for i, transaction := range block.Transactions {
apps := solanaLib.ClassifyApplication(transaction, applications)

signature := transaction.Transaction.Signatures[0]

if len(apps) == 0 {
log.Debugf(
"Transaction position %d block %v didn't have an application classified!",
"Transaction signature %v position %d block %v didn't have an application classified!",
signature,
i,
slot.Slot,
)

continue
}

log.Debugf(
`Transaction signature %v position %d block %v had "%v" applications classified!`,
signature,
i,
slot.Slot,
apps,
)

transactionFeeUsd := new(big.Rat).SetUint64(transaction.Meta.Fee)

transactionFeeUsd.Quo(transactionFeeUsd, LamportDecimalPlacesRat)
Expand All @@ -143,7 +154,7 @@ func main() {
transactionFeeUsd.Mul(transactionFeeUsd, solanaPrice)

parsed := worker.SolanaApplicationTransaction{
Signature: transaction.Transaction.Signatures[0],
Signature: signature,
Result: transaction,
AdjustedFee: transactionFeeUsd,
Applications: apps,
Expand Down
7 changes: 7 additions & 0 deletions cmd/microservice-solana-user-actions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func main() {

fluidityOwners := make([]string, len(accountKeys))

log.Debugf
"Token balances for transaction signature %v: %v",
signature,
accountKeys,
)

for _, bal := range tokenBalances {
if bal.Mint == fluidityTokenMint {
fluidityOwners[bal.AccountIndex] = bal.Owner
Expand Down Expand Up @@ -135,6 +141,7 @@ func main() {
accountKeys,
fluidityOwners,
tokenDetails,
applications,
)

case SplProgramId:
Expand Down
21 changes: 16 additions & 5 deletions cmd/microservice-solana-user-actions/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,22 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans

if fluidityTransaction.Payout != nil {
var (
winnerAIndex = instruction.Accounts[5]
winnerBIndex = instruction.Accounts[6]
winnerAIndex = instruction.Accounts[7]
winnerBIndex = instruction.Accounts[8]
)

// payout for different token
if fluidityOwners[winnerAIndex] == "" {
if ind := fluidityOwners[winnerAIndex]; ind == "" {
log.App(func(k *log.Log) {
k.Format(
"Got a winning payout, but token mint was wrong, transaction hash %v, winnerAIndex %v, winnerBIndex %v, fluidity owners %v",
`Got a winning payout, but token mint was wrong, transaction hash %v, winnerAIndex %v, winnerBIndex %v, fluidity owners %v, fluidity owners length %v, content when accessing winnerAIndex "%v", instruction accounts "%v"`,
transactionHash,
winnerAIndex,
winnerBIndex,
fluidityOwners,
len(fluidityOwners),
ind,
instruction.Accounts,
)
})
return nil, nil, nil, nil, nil
Expand All @@ -107,8 +110,14 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans
var (
winner1_ = winner_
winner2_ = winner_

application string
)

if len(applications) > 0 {
application = applications[0].String()
}

winningAmount1 := new(big.Int).Mul(winningAmount, Winner1Split)

winningAmount1.Quo(winningAmount1, winner10Split)
Expand All @@ -119,6 +128,7 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans

winner1_.WinnerAddress = accounts[winnerAIndex]
winner1_.SolanaWinnerOwnerAddress = fluidityOwners[winnerAIndex]
winner1_.Application = application

winner1_.WinningAmount = misc.NewBigIntFromInt(*winningAmount1)
winner1_.RewardType = "send"
Expand All @@ -127,7 +137,8 @@ func processFluidityTransaction(transactionHash string, instruction solana.Trans
winner2_.SolanaWinnerOwnerAddress = fluidityOwners[winnerBIndex]

winner2_.WinningAmount = misc.NewBigIntFromInt(*winningAmount2)
winner2.RewardType = "receive"
winner2._RewardType = "receive"
winner2_.Application = application

winner1 = &winner1_
winner2 = &winner2_
Expand Down
9 changes: 9 additions & 0 deletions common/solana/transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package solana

import (
"github.com/fluidity-money/fluidity-app/common/solana/applications"
"github.com/fluidity-money/fluidity-app/lib/log"
"github.com/fluidity-money/fluidity-app/lib/types/solana"
)

Expand All @@ -14,6 +15,14 @@ func ClassifyApplication(transaction solana.TransactionResult, apps map[string]a

foundApps := make(map[applications.Application]struct{}, 0)

log.Debug(func(k *log.Log) {
k.Format(
`About to search apps "%v" for account keys "%v"`,
apps,
accounts,
)
})

for _, account := range accounts {
app, exists := apps[account]
if !exists {
Expand Down
Loading