@@ -2398,7 +2398,7 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request
23982398 PostsByHash : postEntryResponses ,
23992399 LastSeenIndex : lastSeenIndex ,
24002400 }
2401- if err : = json .NewEncoder (ww ).Encode (res ); err != nil {
2401+ if err = json .NewEncoder (ww ).Encode (res ); err != nil {
24022402 _AddBadRequestError (ww , fmt .Sprintf (
24032403 "GetNotifications: Problem encoding response as JSON: %v" , err ))
24042404 return
@@ -2520,38 +2520,46 @@ func (fes *APIServer) _getDBNotifications(request *GetNotificationsRequest, bloc
25202520
25212521 // In this case we need to look up the full transaction and convert
25222522 // it into a proper transaction response.
2523- txnMeta := lib .DbGetTxindexTransactionRefByTxID (fes .TXIndex .TXIndexChain .DB (), nil , txID )
2524- if txnMeta == nil {
2523+ dbTxnMeta := lib .DbGetTxindexTransactionRefByTxID (fes .TXIndex .TXIndexChain .DB (), nil , txID )
2524+ if dbTxnMeta == nil {
25252525 // We should never be missing a transaction for a given txid, but
25262526 // just continue in this case.
25272527 glog .Errorf ("GetNotifications: Missing TransactionMetadata for txid %v" , txID )
25282528 continue
25292529 }
2530- // Skip transactions that aren't notifications
2531- if ! TxnMetaIsNotification (txnMeta , request .PublicKeyBase58Check , utxoView ) {
2532- continue
2530+ txnMetas := []* lib.TransactionMetadata {dbTxnMeta }
2531+ if dbTxnMeta .AtomicTxnsWrapperTxindexMetadata != nil {
2532+ // If this is an atomic transaction, we need to iterate over the inner transactions
2533+ // and convert them into TransactionMetadata objects.
2534+ txnMetas = dbTxnMeta .AtomicTxnsWrapperTxindexMetadata .InnerTxnsTransactionMetadata
25332535 }
2534- transactorPkBytes , _ , err := lib .Base58CheckDecode (txnMeta .TransactorPublicKeyBase58Check )
2535- if err != nil {
2536- glog .Errorf ("GetNotifications: unable to decode public key %v" , txnMeta .TransactorPublicKeyBase58Check )
2537- continue
2538- }
2539- // Skip transactions from blocked users.
2540- if _ , ok := blockedPubKeys [lib .PkToString (transactorPkBytes , fes .Params )]; ok {
2541- continue
2542- }
2543- // Skip transactions from blacklisted public keys
2544- transactorPKID := utxoView .GetPKIDForPublicKey (transactorPkBytes )
2545- if transactorPKID == nil || fes .IsUserBlacklisted (transactorPKID .PKID , utxoView ) {
2546- continue
2547- }
2548- currentIndexBytes := keysFound [ii ][len (lib .DbTxindexPublicKeyPrefix (pkBytes )):]
2549- res := & TransactionMetadataResponse {
2550- Metadata : txnMeta ,
2551- Index : int64 (lib .DecodeUint32 (currentIndexBytes )),
2552- }
2553- if NotificationTxnShouldBeIncluded (res .Metadata , & filteredOutCategories ) {
2554- dbTxnMetadataFound = append (dbTxnMetadataFound , res )
2536+ for _ , txnMeta := range txnMetas {
2537+ // Skip transactions that aren't notifications
2538+ if ! TxnMetaIsNotification (txnMeta , request .PublicKeyBase58Check , utxoView ) {
2539+ continue
2540+ }
2541+ transactorPkBytes , _ , err := lib .Base58CheckDecode (txnMeta .TransactorPublicKeyBase58Check )
2542+ if err != nil {
2543+ glog .Errorf ("GetNotifications: unable to decode public key %v" , txnMeta .TransactorPublicKeyBase58Check )
2544+ continue
2545+ }
2546+ // Skip transactions from blocked users.
2547+ if _ , ok := blockedPubKeys [lib .PkToString (transactorPkBytes , fes .Params )]; ok {
2548+ continue
2549+ }
2550+ // Skip transactions from blacklisted public keys
2551+ transactorPKID := utxoView .GetPKIDForPublicKey (transactorPkBytes )
2552+ if transactorPKID == nil || fes .IsUserBlacklisted (transactorPKID .PKID , utxoView ) {
2553+ continue
2554+ }
2555+ currentIndexBytes := keysFound [ii ][len (lib .DbTxindexPublicKeyPrefix (pkBytes )):]
2556+ res := & TransactionMetadataResponse {
2557+ Metadata : txnMeta ,
2558+ Index : int64 (lib .DecodeUint32 (currentIndexBytes )),
2559+ }
2560+ if NotificationTxnShouldBeIncluded (res .Metadata , & filteredOutCategories ) {
2561+ dbTxnMetadataFound = append (dbTxnMetadataFound , res )
2562+ }
25552563 }
25562564 }
25572565
@@ -2625,51 +2633,60 @@ func (fes *APIServer) _getMempoolNotifications(request *GetNotificationsRequest,
26252633
26262634 mempoolTxnMetadata := []* TransactionMetadataResponse {}
26272635 for _ , poolTx := range poolTxns {
2628- txnMeta := poolTx .TxMeta
2629- if txnMeta == nil {
2636+ poolTxnMeta := poolTx .TxMeta
2637+ if poolTxnMeta == nil {
26302638 continue
26312639 }
26322640
26332641 // Set the current index we will use to identify this transaction.
26342642 currentIndex := NextIndex
26352643
2636- // Increment the NextIndex if this transaction is associated with the user's
2637- // public key in any way. This is what the db would do when storing it, and so
2638- // this treatment should be consistent.
2639- if TxnIsAssociatedWithPublicKey ( txnMeta , request . PublicKeyBase58Check ) {
2640- NextIndex ++
2644+ txnMetas := [] * lib. TransactionMetadata { poolTxnMeta }
2645+ if poolTxnMeta . AtomicTxnsWrapperTxindexMetadata != nil {
2646+ // If this is an atomic transaction, we need to iterate over the inner transactions
2647+ // and convert them into TransactionMetadata objects.
2648+ txnMetas = poolTxnMeta . AtomicTxnsWrapperTxindexMetadata . InnerTxnsTransactionMetadata
26412649 }
2650+ for _ , txnMeta := range txnMetas {
26422651
2643- // If the transaction is a notification then add it to our list with the proper
2644- // index value if the transactor is not a blocked public key
2645- if TxnMetaIsNotification (txnMeta , request .PublicKeyBase58Check , utxoView ) {
2646- transactorPkBytes , _ , err := lib .Base58CheckDecode (txnMeta .TransactorPublicKeyBase58Check )
2647- if err != nil {
2648- glog .Errorf ("GetNotifications: unable to decode public key %v" , txnMeta .TransactorPublicKeyBase58Check )
2649- continue
2652+ // Increment the NextIndex if this transaction is associated with the user's
2653+ // public key in any way. This is what the db would do when storing it, and so
2654+ // this treatment should be consistent.
2655+ if TxnIsAssociatedWithPublicKey (txnMeta , request .PublicKeyBase58Check ) {
2656+ NextIndex ++
26502657 }
26512658
2652- // Skip transactions from blocked users.
2653- if _ , ok := blockedPubKeys [lib .PkToString (transactorPkBytes , fes .Params )]; ok {
2654- continue
2655- }
2656- // Skip blacklisted public keys
2657- transactorPKID := utxoView .GetPKIDForPublicKey (transactorPkBytes )
2658- if transactorPKID == nil || fes .IsUserBlacklisted (transactorPKID .PKID , utxoView ) {
2659- continue
2660- }
2659+ // If the transaction is a notification then add it to our list with the proper
2660+ // index value if the transactor is not a blocked public key
2661+ if TxnMetaIsNotification (txnMeta , request .PublicKeyBase58Check , utxoView ) {
2662+ transactorPkBytes , _ , err := lib .Base58CheckDecode (txnMeta .TransactorPublicKeyBase58Check )
2663+ if err != nil {
2664+ glog .Errorf ("GetNotifications: unable to decode public key %v" , txnMeta .TransactorPublicKeyBase58Check )
2665+ continue
2666+ }
26612667
2662- // Skip transactions when notification should not be included based on filter
2663- if ! NotificationTxnShouldBeIncluded (txnMeta , & filteredOutCategories ) {
2664- continue
2665- }
2668+ // Skip transactions from blocked users.
2669+ if _ , ok := blockedPubKeys [lib .PkToString (transactorPkBytes , fes .Params )]; ok {
2670+ continue
2671+ }
2672+ // Skip blacklisted public keys
2673+ transactorPKID := utxoView .GetPKIDForPublicKey (transactorPkBytes )
2674+ if transactorPKID == nil || fes .IsUserBlacklisted (transactorPKID .PKID , utxoView ) {
2675+ continue
2676+ }
26662677
2667- // Only include transactions that occur on or after the start index, if defined
2668- if request .FetchStartIndex < 0 || (request .FetchStartIndex >= currentIndex && iterateReverse ) || (request .FetchStartIndex <= currentIndex && ! iterateReverse ) {
2669- mempoolTxnMetadata = append (mempoolTxnMetadata , & TransactionMetadataResponse {
2670- Metadata : txnMeta ,
2671- Index : currentIndex ,
2672- })
2678+ // Skip transactions when notification should not be included based on filter
2679+ if ! NotificationTxnShouldBeIncluded (txnMeta , & filteredOutCategories ) {
2680+ continue
2681+ }
2682+
2683+ // Only include transactions that occur on or after the start index, if defined
2684+ if request .FetchStartIndex < 0 || (request .FetchStartIndex >= currentIndex && iterateReverse ) || (request .FetchStartIndex <= currentIndex && ! iterateReverse ) {
2685+ mempoolTxnMetadata = append (mempoolTxnMetadata , & TransactionMetadataResponse {
2686+ Metadata : txnMeta ,
2687+ Index : currentIndex ,
2688+ })
2689+ }
26732690 }
26742691 }
26752692
0 commit comments