diff --git a/src/Stratis.Features.SQLiteWalletRepository/Tables/HDTransactionData.cs b/src/Stratis.Features.SQLiteWalletRepository/Tables/HDTransactionData.cs index 8cb3a6d06f..50f45040d6 100644 --- a/src/Stratis.Features.SQLiteWalletRepository/Tables/HDTransactionData.cs +++ b/src/Stratis.Features.SQLiteWalletRepository/Tables/HDTransactionData.cs @@ -271,14 +271,17 @@ END Amount , t.Address AS ReceiveAddress , t.OutputBlockHeight as BlockHeight FROM HDTransactionData AS t + -- We want to skip any rows that join up to this sub-query but only for non-staking receives. + -- The idea is that any address appearing as both source and destination would otherwise be a change address that should be skipped. LEFT JOIN ( SELECT DISTINCT SpendTxId, Address FROM HDTransactionData AS t2 WHERE t2.WalletId = {strWalletId} AND t2.SpendTxId is not null and t2.AccountIndex = {strAccountIndex}) t2 ON t2.SpendTxId = t.OutputTxId AND t2.Address = t.Address + AND t.OutputTxIsCoinbase = 0 -- Don't join up if staking. WHERE t.WalletId = {strWalletId} AND t.AccountIndex = {strAccountIndex}{((address == null) ? "" : $@" AND t.Address = {strAddress}")} - AND (t.OutputTxIsCoinbase != 0 OR t2.SpendTxId IS NULL){(!forCirrus ? "" : $@" + AND t2.SpendTxId IS NULL /* Not joining up */{(!forCirrus ? "" : $@" AND t.OutputTxIsCoinbase = 0")} GROUP BY t.OutputTxId UNION ALL"; diff --git a/src/Stratis.Features.SQLiteWalletRepository/Tables/HDWallet.cs b/src/Stratis.Features.SQLiteWalletRepository/Tables/HDWallet.cs index f02e93a07c..18644d1dd9 100644 --- a/src/Stratis.Features.SQLiteWalletRepository/Tables/HDWallet.cs +++ b/src/Stratis.Features.SQLiteWalletRepository/Tables/HDWallet.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using NBitcoin; using SQLite; @@ -164,13 +165,13 @@ internal ChainedHeader GetFork(ChainedHeader chainTip) var blockLocator = new BlockLocator() { - Blocks = this.BlockLocator.Split(',').Select(strHash => uint256.Parse(strHash)).ToList() + Blocks = this.BlockLocator.Split(',', System.StringSplitOptions.RemoveEmptyEntries).Select(strHash => uint256.Parse(strHash)).ToList() }; List locatorHeights = ChainedHeaderExt.GetLocatorHeights(this.LastBlockSyncedHeight); // Find a locator block at or below the chain tip. - for (int i = 0; i < locatorHeights.Count; i++) + for (int i = 0; i < Math.Min(locatorHeights.Count, blockLocator.Blocks.Count); i++) { if (chainTip.Height < locatorHeights[i]) continue;