@@ -159,10 +159,23 @@ prefilterTx wKey tx = ((prefInps',prefOuts'),metas)
159
159
(nothingToZero acc prefOutCoins)
160
160
(onlyOurInps && onlyOurOuts) acc) allAccounts
161
161
162
+ -- | Prefilter the transaction with each wallet key respectively and
163
+ -- combine the results.
164
+ --
165
+ -- NOTE: we can rely on a Monoidal fold here to combine the maps
166
+ -- 'Map HdAccountId a' since the accounts will be unique accross wallet keys.
167
+ prefilterTxForWallets :: [WalletKey ]
168
+ -> ResolvedTx
169
+ -> ((Map HdAccountId (Set TxIn )
170
+ , Map HdAccountId UtxoSummaryRaw )
171
+ , [TxMeta ])
172
+ prefilterTxForWallets wKeys tx =
173
+ mconcat $ map ((flip prefilterTx) tx) wKeys
174
+
162
175
-- | Prefilter inputs of a transaction
163
176
prefilterInputs :: WalletKey
164
- -> [(TxIn , ResolvedInput )]
165
- -> (Bool , Map HdAccountId (Set (TxIn ,Coin )))
177
+ -> [(TxIn , ResolvedInput )]
178
+ -> (Bool , Map HdAccountId (Set (TxIn ,Coin )))
166
179
prefilterInputs wKey inps
167
180
= prefilterResolvedTxPairs wKey mergeF inps
168
181
where
@@ -265,26 +278,24 @@ extendWithSummary (onlyOurInps,onlyOurOuts) utxoWithAddrId
265
278
and Transaction metadata.
266
279
-------------------------------------------------------------------------------}
267
280
268
- -- | Prefilter the transactions of a resolved block for the given wallet .
281
+ -- | Prefilter the transactions of a resolved block for the given wallets .
269
282
--
270
283
-- Returns prefiltered blocks indexed by HdAccountId.
271
284
prefilterBlock :: ResolvedBlock
272
- -> WalletId
273
- -> EncryptedSecretKey
285
+ -> [(WalletId , EncryptedSecretKey )]
274
286
-> (Map HdAccountId PrefilteredBlock , [TxMeta ])
275
- prefilterBlock block wid esk =
287
+ prefilterBlock block rawKeys =
276
288
(Map. fromList
277
289
$ map (mkPrefBlock (block ^. rbContext) inpAll outAll)
278
290
$ Set. toList accountIds
279
291
, metas)
280
292
where
281
- wdc :: WalletDecrCredentials
282
- wdc = keyToWalletDecrCredentials $ KeyForRegular esk
283
- wKey = (wid, wdc)
293
+ wKeys :: [WalletKey ]
294
+ wKeys = map toWalletKey rawKeys
284
295
285
296
inps :: [Map HdAccountId (Set TxIn )]
286
297
outs :: [Map HdAccountId UtxoSummaryRaw ]
287
- (ios, conMetas) = unzip $ map (prefilterTx wKey ) (block ^. rbTxs)
298
+ (ios, conMetas) = unzip $ map (prefilterTxForWallets wKeys ) (block ^. rbTxs)
288
299
(inps, outs) = unzip ios
289
300
metas = concat conMetas
290
301
@@ -295,6 +306,9 @@ prefilterBlock block wid esk =
295
306
296
307
accountIds = Map. keysSet inpAll `Set.union` Map. keysSet outAll
297
308
309
+ toWalletKey :: (WalletId , EncryptedSecretKey ) -> WalletKey
310
+ toWalletKey (wid, esk) = (wid, keyToWalletDecrCredentials $ KeyForRegular esk)
311
+
298
312
mkPrefBlock :: BlockContext
299
313
-> Map HdAccountId (Set TxIn )
300
314
-> Map HdAccountId (Map TxIn (TxOutAux , AddressSummary ))
0 commit comments