@@ -14,6 +14,7 @@ type CachedNetworkData =
1414 UsdPrice: Map < Currency , CachedValue < decimal >>;
1515 Balances: Map < Currency , Map < PublicAddress , CachedValue < decimal >>>;
1616 OutgoingTransactions: Map < Currency , Map < PublicAddress , Map < string , CachedValue < decimal >>>>;
17+ UnconfirmedTransactions: Map < Currency , list < string * int64 >>
1718 }
1819 member self.GetLeastOldDate () =
1920 let allDates =
@@ -35,6 +36,7 @@ type CachedNetworkData =
3536 UsdPrice = Map.empty
3637 Balances = Map.empty
3738 OutgoingTransactions = Map.empty
39+ UnconfirmedTransactions = Map.empty
3840 }
3941
4042 static member FromDietCache ( dietCache : DietCache ): CachedNetworkData =
@@ -52,7 +54,8 @@ type CachedNetworkData =
5254 yield ( Currency.Parse currencyStr), Map.empty.Add( address,( balance, now))
5355 } |> Map.ofSeq
5456 { UsdPrice = fiatPrices; Balances = balances
55- OutgoingTransactions = Map.empty; }
57+ OutgoingTransactions = Map.empty;
58+ UnconfirmedTransactions = Map.empty }
5659
5760 member self.ToDietCache ( readOnlyAccounts : seq < ReadOnlyAccount >) =
5861 let rec extractAddressesFromAccounts ( acc : Map < PublicAddress , List < DietCurrency >>) ( accounts : List < IAccount >)
@@ -647,4 +650,34 @@ module Caching =
647650 member __.FirstRun
648651 with get() = firstRun
649652
653+ member self.StoreUnconfirmedTransaction ( currency : Currency ) ( txHash : string ) ( gasLimit : int64 ) =
654+ lock cacheFiles.CachedNetworkData ( fun _ ->
655+ let newTransactions =
656+ match sessionCachedNetworkData.UnconfirmedTransactions |> Map.tryFind currency with
657+ | Some transactionsForCurrency -> ( txHash, gasLimit) :: transactionsForCurrency
658+ | None -> List.singleton ( txHash, gasLimit)
659+ let newCachedData =
660+ { sessionCachedNetworkData with
661+ UnconfirmedTransactions =
662+ sessionCachedNetworkData.UnconfirmedTransactions
663+ |> Map.add currency newTransactions }
664+ SaveNetworkDataToDisk newCachedData
665+ )
666+
667+ member self.RemoveUnconfirmedTransaction ( currency : Currency ) ( txHash : string ) =
668+ lock cacheFiles.CachedNetworkData ( fun _ ->
669+ match sessionCachedNetworkData.UnconfirmedTransactions |> Map.tryFind currency with
670+ | Some transactionsForCurrency ->
671+ let newTransactionForCurrency =
672+ transactionsForCurrency
673+ |> List.filter ( fun ( hash , _ ) -> hash <> txHash)
674+ let newCachedData =
675+ { sessionCachedNetworkData with
676+ UnconfirmedTransactions =
677+ sessionCachedNetworkData.UnconfirmedTransactions
678+ |> Map.add currency newTransactionForCurrency }
679+ SaveNetworkDataToDisk newCachedData
680+ | None -> ()
681+ )
682+
650683 let Instance = MainCache ( None, TimeSpan.FromDays 1.0 )
0 commit comments