Skip to content

Commit 85a1f59

Browse files
authored
Improve chat message timing in Geyser (#56)
1 parent 3c3d6fb commit 85a1f59

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

pkg/code/async/geyser/external_deposit.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ func processPotentialExternalDeposit(ctx context.Context, conf *conf, data code_
186186
return errors.Wrap(err, "invalid owner account")
187187
}
188188

189+
blockTime := time.Now()
190+
if tokenBalances.BlockTime != nil {
191+
blockTime = *tokenBalances.BlockTime
192+
}
193+
189194
// Use the account type to determine how we'll process this external deposit
190195
//
191196
// todo: Below logic is beginning to get messy and might be in need of a
@@ -247,7 +252,7 @@ func processPotentialExternalDeposit(ctx context.Context, conf *conf, data code_
247252
}
248253

249254
if isCodeSwap {
250-
chatMessage, err := chat_util.ToKinAvailableForUseMessage(signature, usdcQuarksSwapped, time.Now())
255+
chatMessage, err := chat_util.ToKinAvailableForUseMessage(signature, usdcQuarksSwapped, blockTime)
251256
if err != nil {
252257
return errors.Wrap(err, "error creating chat message")
253258
}
@@ -306,8 +311,7 @@ func processPotentialExternalDeposit(ctx context.Context, conf *conf, data code_
306311
case commonpb.AccountType_SWAP:
307312
bestEffortCacheExternalAccountBalance(ctx, data, tokenAccount, tokenBalances)
308313

309-
// todo: solana client doesn't return block time
310-
chatMessage, err := chat_util.ToUsdcDepositedMessage(signature, uint64(deltaQuarks), time.Now())
314+
chatMessage, err := chat_util.ToUsdcDepositedMessage(signature, uint64(deltaQuarks), blockTime)
311315
if err != nil {
312316
return errors.Wrap(err, "error creating chat message")
313317
}

pkg/code/async/geyser/messenger.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package async_geyser
33
import (
44
"context"
55
"slices"
6+
"time"
67

78
"github.com/mr-tron/base58"
89
"github.com/pkg/errors"
@@ -155,7 +156,11 @@ func processPotentialBlockchainMessage(ctx context.Context, data code_data.Provi
155156
return errors.Wrap(err, "invalid owner account")
156157
}
157158

158-
chatMessage, err := chat_util.ToBlockchainMessage(signature, feePayer, blockchainMessage, *txn.BlockTime)
159+
blockTime := time.Now()
160+
if txn.BlockTime != nil {
161+
blockTime = *txn.BlockTime
162+
}
163+
chatMessage, err := chat_util.ToBlockchainMessage(signature, feePayer, blockchainMessage, blockTime)
159164
if err != nil {
160165
return errors.Wrap(err, "error creating proto message")
161166
}

pkg/solana/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ type TransactionTokenBalances struct {
146146
PreTokenBalances []TokenBalance
147147
PostTokenBalances []TokenBalance
148148
Slot uint64
149+
BlockTime *time.Time
149150
}
150151

151152
type ConfirmedTransaction struct {
@@ -642,6 +643,7 @@ func (c *client) GetTransactionTokenBalances(sig Signature) (TransactionTokenBal
642643
AccountKeys []string `json:"accountKeys"`
643644
} `json:"message"`
644645
} `json:"transaction"`
646+
BlockTime *int64 `json:"blockTime"`
645647
}
646648

647649
var resp *rpcResp
@@ -666,6 +668,10 @@ func (c *client) GetTransactionTokenBalances(sig Signature) (TransactionTokenBal
666668
PostTokenBalances: resp.Meta.PostTokenBalances,
667669
Slot: resp.Slot,
668670
}
671+
if resp.BlockTime != nil {
672+
txTime := time.Unix(*resp.BlockTime, 0)
673+
tokenBalances.BlockTime = &txTime
674+
}
669675
return tokenBalances, nil
670676
}
671677

0 commit comments

Comments
 (0)