Db0056: Debugging something weird

This commit is contained in:
Rick Falkvinge
2017-11-20 21:43:12 +01:00
parent cfae63d512
commit a7440f5e8d
5 changed files with 90 additions and 2 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Database
/// </summary>
public static int DbVersionExpected
{
get { return 55; }
get { return 56; }
}
+16 -1
View File
@@ -232,7 +232,7 @@ namespace Swarmops.Database
AddParameterWithName(command, "amountSatoshis", amountSatoshis);
AddParameterWithName(command, "confirmationCount", confirmationCount);
return Convert.ToInt32(command.ExecuteScalar());
return Convert.ToInt32(command.ExecuteScalar()); // A negative number means the record was updated, a positive that it was created
}
}
}
@@ -254,6 +254,21 @@ namespace Swarmops.Database
}
}
public void UpdateHotBitcoinAddressUnspentTotals()
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
using (DbCommand command = GetDbCommand("UpdateHotBitcoinAddressUnspentTotals", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();
}
}
}
#endregion
}
}
+1
View File
@@ -53,3 +53,4 @@
0053 - Bugfix for 0052 [RF]
0054 - Fix for Conditional-CreateUTXO procedure with fork in effect [RF]
0055 - Fix for bug introduced with 0054, hash collisions in index [RF]
0056 - Splitting a storedproc into two; debugging a weird multi-row select return [RF]
+71
View File
@@ -0,0 +1,71 @@
DROP PROCEDURE IF EXISTS `UpdateHotBitcoinAddressUnspentTotals`
#
DROP PROCEDURE IF EXISTS `CreateHotBitcoinAddressUnspentConditional`
#
CREATE PROCEDURE `CreateHotBitcoinAddressUnspentConditional`(
IN hotBitcoinAddressId INT,
IN amountSatoshis BIGINT,
IN transactionHash VARCHAR(128),
IN transactionOutputIndex INT,
IN confirmationCount INT
)
BEGIN
DECLARE unspentId INT;
IF ((SELECT COUNT(*) FROM HotBitcoinAddressUnspents
WHERE HotBitcoinAddressUnspents.TransactionHash=transactionHash
AND HotBitcoinAddressUnspents.TransactionOutputIndex=transactionOutputIndex
AND HotBitcoinAddressUnspents.HotBitcoinAddressId=hotBitcoinAddressId) = 0)
THEN
INSERT INTO HotBitcoinAddressUnspents
(HotBitcoinAddressId,AmountSatoshis,TransactionHash,TransactionOutputIndex,ConfirmationCount)
VALUES
(hotBitcoinAddressId,amountSatoshis,transactionHash,transactionOutputIndex,confirmationCount);
SELECT LAST_INSERT_ID() AS Identity;
ELSE
SELECT HotBitcoinAddressUnspents.HotBitcoinAddressUnspentId INTO unspentId
FROM HotBitcoinAddressUnspents
WHERE HotBitcoinAddressUnspents.TransactionHash=transactionHash
AND HotBitcoinAddressUnspents.TransactionOutputIndex=transactionOutputIndex
AND HotBitcoinAddressId=hotBitcoinAddressId;
UPDATE HotBitcoinAddressUnspents
SET HotBitcoinAddressUnspents.ConfirmationCount=confirmationCount
WHERE HotBitcoinAddressUnspents.HotBitcoinAddressUnspentId=unspentId;
SELECT -unspentId AS Identity;
END IF;
END
#
CREATE PROCEDURE `UpdateHotBitcoinAddressUnspentTotals` ()
BEGIN
UPDATE HotBitcoinAddresses
INNER JOIN
(
SELECT HotBitcoinAddressId, SUM(AmountSatoshis) AS UnspentAmountSum
FROM HotBitcoinAddressUnspents
GROUP BY HotBitcoinAddressId
) innerSelection ON HotBitcoinAddresses.HotBitcoinAddressId = innerSelection.HotBitcoinAddressId
SET HotBitcoinAddresses.BalanceSatoshis = innerSelection.UnspentAmountSum
WHERE HotBitcoinAddresses.HotBitcoinAddressId=hotBitcoinAddressId;
END
@@ -26,6 +26,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
if (address.Chain == BitcoinChain.Core)
{
// These shouldn't exist much, so make sure that we have the equivalent Cash address registered
BitcoinUtility.TestUnspents(BitcoinChain.Cash, address.Address);
try
{