Added native currency to txrows
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
<Compile Include="Enums\ExternalIdentityType.cs" />
|
||||
<Compile Include="Enums\FinancialAccountType.cs" />
|
||||
<Compile Include="Enums\FinancialDependencyType.cs" />
|
||||
<Compile Include="Enums\FinancialForeignIdType.cs" />
|
||||
<Compile Include="Enums\FinancialValidationType.cs" />
|
||||
<Compile Include="Enums\GeographyLevel.cs" />
|
||||
<Compile Include="Enums\InvalidMembershipType.cs" />
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Swarmops.Common.Enums
|
||||
{
|
||||
public enum FinancialForeignIdType
|
||||
{
|
||||
Unknown = 0,
|
||||
BitcoinTransaction = 1
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace Swarmops.Database
|
||||
/// </summary>
|
||||
public static int DbVersionExpected
|
||||
{
|
||||
get { return 31; }
|
||||
get { return 32; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -614,10 +614,10 @@ namespace Swarmops.Database
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
using (DbCommand command =
|
||||
GetDbCommand (
|
||||
"select AmountCents from FinancialAccountBudgetsMonthly where Year=" + year +
|
||||
" AND FinancialAccountId=" + financialAccountId + " ORDER BY Month;", connection);
|
||||
" AND FinancialAccountId=" + financialAccountId + " ORDER BY Month;", connection))
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
@@ -1042,6 +1042,50 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
|
||||
public void SetFinancialTransactionForeignId(int financialTransactionId, FinancialForeignIdType foreignIdType, string foreignId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialTransactionForeignId", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialTransactionId", financialTransactionId);
|
||||
AddParameterWithName(command, "financialTransactionForeignIdType", (int) foreignIdType);
|
||||
AddParameterWithName(command, "foreignId", foreignId);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Int64 GetFinancialTransactionFromForeignId(FinancialForeignIdType foreignIdType, string foreignId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"Select FinancialTransactionId from FinancialTransactionForeignIds WHERE FinancialTransactionForeignIdType=" + (int) foreignIdType +
|
||||
" AND ForeignId='" + SqlSanitize (foreignId) + "';", connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return reader.GetInt32 (0);
|
||||
}
|
||||
|
||||
return 0; // none found. Todo: throw exception instead? This behavior is inconsistent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public DateTime GetFinancialAccountFirstTransactionDate (int financialAccountId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
|
||||
@@ -28,4 +28,5 @@
|
||||
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]
|
||||
0031 - Added foreign ID tables, procs for transactions, to track blockchain [RF]
|
||||
0032 - Added native currency to transaction rows, for multi-currency accounting [RF]
|
||||
@@ -0,0 +1,42 @@
|
||||
CREATE TABLE `FinancialTransactionRowsNativeCurrency` (
|
||||
`FinancialTransactionRowId` INT NOT NULL,
|
||||
`CurrencyId` INT NOT NULL,
|
||||
`NativeAmountCents` BIGINT NOT NULL,
|
||||
PRIMARY KEY (`FinancialTransactionRowId`))
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `SetFinancialTransactionRowNativeCurrency`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetFinancialTransactionRowNativeCurrency`(
|
||||
IN financialTransactionRowId INT,
|
||||
IN currencyId INT,
|
||||
IN nativeAmountCents BIGINT
|
||||
)
|
||||
BEGIN
|
||||
|
||||
IF ((SELECT COUNT(*) FROM FinancialTransactionRows
|
||||
WHERE FinancialTransactionRows.FinancialTransactionRowId=financialTransactionRowId) = 0)
|
||||
THEN
|
||||
|
||||
INSERT INTO FinancialTransactionRowsNativeCurrency (FinancialTransactionRowId,CurrencyId,NativeAmountCents)
|
||||
VALUES (financialTransactionRowId,currencyId,nativeAmountCents);
|
||||
|
||||
ELSE
|
||||
|
||||
UPDATE FinancialTransactionRowsNativeCurrency
|
||||
SET FinancialTransactionRowsNativeCurrency.CurrencyId=currencyId,
|
||||
FinancialTransactionRowsNativeCurrency.NativeAmountCents=nativeAmountCents
|
||||
WHERE FinancialTransactionRowsNativeCurrency.FinancialTransactionRowId=
|
||||
financialTransactionRowId;
|
||||
|
||||
END IF;
|
||||
|
||||
END
|
||||
@@ -53,8 +53,6 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static ExtKey BitcoinHotPrivateRoot
|
||||
@@ -179,6 +177,57 @@ namespace Swarmops.Logic.Financial
|
||||
return addresses.FindAmount (satoshis); // Will throw on a number of circumstances
|
||||
}
|
||||
|
||||
|
||||
static public FinancialTransaction GetSwarmopsTransactionFromBlockchainId (string transactionId)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static public void CheckColdStorageForOrganization (Organization organization)
|
||||
{
|
||||
FinancialAccount coldRoot = organization.FinancialAccounts.AssetsBitcoinCold;
|
||||
|
||||
if (coldRoot == null)
|
||||
{
|
||||
return; // no cold assets to check
|
||||
}
|
||||
}
|
||||
|
||||
// https://blockchain.info/address/1Axd4QQhRSCMAuHe93uVKRjNSFj6WypcZa?format=json&api_key=I_am_testing_the_format_please_ignore
|
||||
|
||||
static private void CheckColdStorageRecurse (FinancialAccount parent)
|
||||
{
|
||||
foreach (FinancialAccount child in parent.Children)
|
||||
{
|
||||
CheckColdStorageRecurse (child);
|
||||
}
|
||||
|
||||
// After recursing, get all transactions for this account and verify against our records
|
||||
|
||||
// is the account name a valid bitcoin address on the main network?
|
||||
|
||||
string address = parent.Name.Trim();
|
||||
|
||||
try
|
||||
{
|
||||
BitcoinAddress addressTest = new BitcoinAddress (BitcoinTestAddress, Network.Main);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// the name wasn't an address, so return
|
||||
}
|
||||
|
||||
var addressData =
|
||||
JObject.Parse(
|
||||
new WebClient().DownloadString("https://blockchain.info/address/" + address + "?format=json&api_key=" +
|
||||
SystemSettings.BlockchainSwarmopsApiKey)); // warn: will 500 if no unspent outpoints
|
||||
|
||||
// TODO: PARSE (awaiting functions for native currency to be added to FinancialTransactionRows)
|
||||
|
||||
}
|
||||
|
||||
|
||||
public const int BitcoinWalletIndex = 1;
|
||||
public const int BitcoinDonationsIndex = 2;
|
||||
public const int BitcoinLoansIndex = 3;
|
||||
|
||||
Reference in New Issue
Block a user