Skip to content

Commit bbfed05

Browse files
authored
Use a data push to execute the Swap RPC (#120)
1 parent d6c16c7 commit bbfed05

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

pkg/code/async/geyser/external_deposit.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,31 @@ func processPotentialExternalDeposit(ctx context.Context, conf *conf, data code_
327327
case commonpb.AccountType_SWAP:
328328
bestEffortCacheExternalAccountBalance(ctx, data, tokenAccount, tokenBalances)
329329

330-
go delayedUsdcDepositProcessing(
330+
// go delayedUsdcDepositProcessing(
331+
// ctx,
332+
// conf,
333+
// data,
334+
// pusher,
335+
// chatMessageReceiver,
336+
// tokenAccount,
337+
// signature,
338+
// blockTime,
339+
// )
340+
341+
owner, err := common.NewAccountFromPublicKeyString(accountInfoRecord.OwnerAccount)
342+
if err != nil {
343+
return errors.Wrap(err, "invalid owner account")
344+
}
345+
346+
err = push.SendTriggerSwapRpcPushNotification(
331347
ctx,
332-
conf,
333348
data,
334349
pusher,
335-
chatMessageReceiver,
336-
tokenAccount,
337-
signature,
338-
blockTime,
350+
owner,
339351
)
352+
if err != nil {
353+
return errors.Wrap(err, "error sending push to trigger swap rpc on client")
354+
}
340355

341356
syncedDepositCache.Insert(cacheKey, true, 1)
342357

pkg/code/push/data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
dataPushTypeKey = "code_notification_type"
1818

1919
chatMessageDataPush dataPushType = "ChatMessage"
20+
executeSwapDataPush dataPushType = "ExecuteSwap"
2021
)
2122

2223
// sendRawDataPushNotificationToOwner is a generic utility for sending raw data push

pkg/code/push/notifications.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,34 @@ func SendTwitterAccountConnectedPushNotification(
241241
)
242242
}
243243

244+
// SendTriggerSwapRpcPushNotification sends a data push to trigger the Swap RPC
245+
func SendTriggerSwapRpcPushNotification(
246+
ctx context.Context,
247+
data code_data.Provider,
248+
pusher push_lib.Provider,
249+
owner *common.Account,
250+
) error {
251+
log := logrus.StandardLogger().WithFields(logrus.Fields{
252+
"method": "SendTriggerSwapRpcPushNotification",
253+
"owner": owner.PublicKey().ToBase58(),
254+
})
255+
256+
err := sendRawDataPushNotificationToOwner(
257+
ctx,
258+
data,
259+
pusher,
260+
owner,
261+
executeSwapDataPush,
262+
make(map[string]string),
263+
)
264+
if err != nil {
265+
log.WithError(err).Warn("failure sending data push notification")
266+
return err
267+
}
268+
269+
return nil
270+
}
271+
244272
// SendChatMessagePushNotification sends a push notification for chat messages
245273
func SendChatMessagePushNotification(
246274
ctx context.Context,

pkg/code/server/grpc/transaction/v2/swap.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
372372
// Section: Transaction submission
373373
//
374374

375-
chatMessageTs := time.Now()
375+
// chatMessageTs := time.Now()
376376

377377
_, err = s.data.SubmitBlockchainTransaction(ctx, &txn)
378378
if err != nil {
@@ -386,10 +386,10 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
386386

387387
log.WithField("txn", base64.StdEncoding.EncodeToString(txn.Marshal())).Info("transaction submitted")
388388

389-
err = s.bestEffortNotifyUserOfSwapInProgress(ctx, owner, chatMessageTs)
390-
if err != nil {
391-
log.WithError(err).Warn("failure notifying user of swap in progress")
392-
}
389+
// err = s.bestEffortNotifyUserOfSwapInProgress(ctx, owner, chatMessageTs)
390+
// if err != nil {
391+
// log.WithError(err).Warn("failure notifying user of swap in progress")
392+
// }
393393

394394
if !initiateReq.WaitForBlockchainStatus {
395395
err = streamer.Send(&transactionpb.SwapResponse{

0 commit comments

Comments
 (0)