Db0054 - fix to Create-UTXO procedure with Cash

This commit is contained in:
Rick Falkvinge
2017-11-20 12:26:59 +01:00
parent 70deaad23e
commit 44dd7a1aa6
3 changed files with 61 additions and 2 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Database
/// </summary>
public static int DbVersionExpected
{
get { return 53; }
get { return 54; }
}
+2 -1
View File
@@ -50,4 +50,5 @@
0050 - Added VatReports.OpenTransaction, .CloseTransaction
0051 - Fix for CreateFinancialTransactionStub with Amount field gone (caused in 0043) [RF]
0052 - Added database support for multiple Bitcoin chain forks [RF]
0053 - Bugfix for 0052 [RF]
0053 - Bugfix for 0052 [RF]
0054 - Fix for Conditional-CreateUTXO procedure with fork in effect [RF]
+58
View File
@@ -0,0 +1,58 @@
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() INTO unspentId;
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;
END IF;
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;
SELECT unspentId AS Identity;
END