Db0031 - added blockchain tx tracking

This commit is contained in:
Rick Falkvinge
2015-12-01 11:45:52 +01:00
parent 87c3dac718
commit fa4d08d441
3 changed files with 51 additions and 1 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Database
/// </summary>
public static int DbVersionExpected
{
get { return 30; }
get { return 31; }
}
+1
View File
@@ -28,3 +28,4 @@
0028 - Bugfix for 0027 [RF]
0029 - Added unspent satoshis to hotaddress on create unspent [RF]
0030 - Added flexibility for Resolver classes for OutboundComms [RF]
0031 - Added foreign ID tables, procs for transactions, to track blockchain [RF]
+49
View File
@@ -0,0 +1,49 @@
CREATE TABLE `FinancialTransactionForeignIds` (
`FinancialTransactionForeignIdId` INT NOT NULL AUTO_INCREMENT,
`FinancialTransactionId` INT NOT NULL,
`ForeignIdType` INT NOT NULL,
`ForeignId` VARCHAR(256) NOT NULL,
PRIMARY KEY (`FinancialTransactionForeignIdId`),
INDEX `Ix_TxId` (`FinancialTransactionId` ASC),
INDEX `Ix_IdType` (`ForeignIdType` ASC),
INDEX `Ix_Identifier` (`ForeignId` ASC)
)
#
DROP procedure IF EXISTS `SetFinancialTransactionForeignIdentity`
#
CREATE PROCEDURE `SetFinancialTransactionForeignIdentity`(
IN financialTransactionId INT,
IN foreignIdType INT,
IN foreignId VARCHAR(256)
)
BEGIN
IF ((SELECT COUNT(*) FROM FinancialTransactionForeignIds
WHERE FinancialTransactionForeignIds.FinancialTransactionId=financialTransactionId
AND FinancialTransactionForeignIds.ForeignIdType=foreignIdType) = 0)
THEN
INSERT INTO FinancialTransactionForeignIds (FinancialTransactionId,ForeignIdType,ForeignId)
VALUES (financialTransactionId,foreignIdType,foreignId);
SELECT LAST_INSERT_ID() AS Identity;
ELSE
UPDATE FinancialTransactionForeignIds
SET FinancialTransactionForeignId.ForeignId=foreignId
WHERE FinancialTransactionForeignIds.FinancialTransactionId=financialTransactionId
AND FinancialTransactionForeignIds.ForeignIdType=foreignIdType;
SELECT 0 AS Identity;
END IF;
END