        * src/engine/Scrub.c:
        * src/engine/Scrub.h:
          Try to fix transactions that have no currency, perhaps because
          of a log replay (see bugs 165719 and 143720).
          
Index: src/engine/Scrub.c
===================================================================
--- src/engine/Scrub.c	(revision 13074)
+++ src/engine/Scrub.c	(working copy)
@@ -352,11 +352,74 @@
     Split *split = node->data;
     Transaction *trans = xaccSplitGetParent(split);
 
+    xaccTransScrubCurrencyFromSplits(trans);
+    
     xaccTransScrubImbalance (trans, xaccAccountGetRoot (acc), NULL);
   }
 }
 
 void
+xaccTransScrubCurrencyFromSplits(Transaction *trans)
+{
+  GList *node;
+  gnc_commodity *common_currency = NULL;
+    
+  if (!trans) return;
+  
+  for (node = xaccTransGetSplitList (trans); node; node = node->next) {
+    Split *split = node->data;
+    if (gnc_numeric_equal(xaccSplitGetAmount (split),
+                          xaccSplitGetValue (split))) {
+
+      Account *s_account = xaccSplitGetAccount (split);
+      gnc_commodity *s_commodity = xaccAccountGetCommodity (s_account);
+      
+      if (s_commodity) {
+        const char * namespace = gnc_commodity_get_namespace (s_commodity);
+        if (!safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) ||
+            !safe_strcmp (namespace, GNC_COMMODITY_NS_LEGACY)) {
+
+          /* Found a split where the amount is the same as the value and
+             the commodity is a currency.  If all splits in the transaction
+             that fit this description are in the same currency then the
+             transaction should be in that currency too. */
+
+          if (common_currency == NULL)
+            /* First one we've found, save the currency */
+            common_currency = s_commodity;
+          else if ( !gnc_commodity_equiv (common_currency, s_commodity)) {
+            /* Splits are inconsistent, more than one has a value equal to
+               the amount, but they aren't all in the same currency. */
+            common_currency = NULL;
+            break;
+          }
+        }
+      }
+    }
+  }
+    
+  if (common_currency &&
+      !gnc_commodity_equiv (common_currency, xaccTransGetCurrency (trans))) {
+
+    /* Found a common currency for the splits, and the transaction is not
+       in that currency */
+    gboolean trans_was_open;
+
+    PINFO ("transaction in wrong currency");
+      
+    trans_was_open = xaccTransIsOpen (trans);
+
+    if (!trans_was_open)
+      xaccTransBeginEdit (trans);
+
+    xaccTransSetCurrency (trans, common_currency);
+    
+    if (!trans_was_open)
+      xaccTransCommitEdit (trans);
+  }
+}
+
+void
 xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
                          Account *parent)
 {
Index: src/engine/Scrub.h
===================================================================
--- src/engine/Scrub.h	(revision 13074)
+++ src/engine/Scrub.h	(working copy)
@@ -124,6 +124,15 @@
  * fields of the parent accounts of the transaction's splits. */
 void xaccTransScrubCurrency (Transaction *trans);
 
+/** The xaccTransScrubCurrencyFromSplits method fixes transactions
+ * where the currency doesn't match the currency used in the splits
+ * in the transaction.  If all splits where the amount equals the 
+ * value and where the commodity is a currency have the same 
+ * currency, it sets the transaction's currency to that if it is
+ * anything else.  If the splits don't match that description the
+ * transaction currency is not changed. */
+void xaccTransScrubCurrencyFromSplits(Transaction *trans);
+
 /** The xaccAccountScrubCommodity method fixed accounts without
  * a commodity by using the old account currency and security. */
 void xaccAccountScrubCommodity (Account *account);
