Lots of work on unique HBAs, OInvs

This commit is contained in:
Rick Falkvinge
2017-11-29 17:52:23 +01:00
parent e130ae0cbb
commit a6e333aa3f
17 changed files with 210 additions and 38 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ namespace Swarmops.Database
/// <summary>
/// This is the IN-CODE revision of the database. The version we expect to be running against.
/// </summary>
public static int DbVersionExpected => 61;
public static int DbVersionExpected => 63;
// This class is in horrible need of serious refactoring. For its simplicity in task, it's a horrible bowl of spaghetti.
+65 -9
View File
@@ -16,8 +16,8 @@ namespace Swarmops.Database
#region Field reading code
private const string hotBitcoinAddressFieldSequence =
" HotBitcoinAddressId,OrganizationId,BitcoinChainId,DerivationPath,AddressString," + // 0-4
" AddressStringFallback,BalanceSatoshis,ThroughputSatoshis" + // 5-7
" HotBitcoinAddressId,OrganizationId,BitcoinChainId,DerivationPath,UniqueDerive," + // 0-4
" AddressString,AddressStringFallback,BalanceSatoshis,ThroughputSatoshis" + // 5-7
" FROM HotBitcoinAddresses ";
private const string hotBitcoinAddressUnspentFieldSequence =
@@ -31,12 +31,13 @@ namespace Swarmops.Database
int organizationId = reader.GetInt32 (1);
BitcoinChain chain = (BitcoinChain) reader.GetInt32(2);
string derivationPath = reader.GetString (3);
string addressString = reader.GetString(4);
string addressStringFallback = reader.GetString(5);
Int64 balanceSatoshis = reader.GetInt64 (6);
Int64 throughputSatoshis = reader.GetInt64 (7);
int uniqueDerive = reader.GetInt32(4);
string addressString = reader.GetString(5);
string addressStringFallback = reader.GetString(6);
Int64 balanceSatoshis = reader.GetInt64 (7);
Int64 throughputSatoshis = reader.GetInt64 (8);
return new BasicHotBitcoinAddress (hotBitcoinAddressId, organizationId, chain, derivationPath, addressString, addressStringFallback, balanceSatoshis, throughputSatoshis);
return new BasicHotBitcoinAddress (hotBitcoinAddressId, organizationId, chain, derivationPath, uniqueDerive, addressString, addressStringFallback, balanceSatoshis, throughputSatoshis);
}
private BasicHotBitcoinAddressUnspent ReadHotBitcoinAddressUnspentFromDataReader(IDataRecord reader)
@@ -177,6 +178,25 @@ namespace Swarmops.Database
#region Creation and manipulation
public int CreateHotBitcoinAddress(int organizationId, BitcoinChain chain, string derivationPath)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
using (DbCommand command = GetDbCommand("CreateHotBitcoinAddress", connection))
{
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "organizationId", organizationId);
AddParameterWithName(command, "bitcoinChainId", (int)chain);
AddParameterWithName(command, "derivationPath", derivationPath);
return Convert.ToInt32(command.ExecuteScalar());
}
}
}
public int CreateHotBitcoinAddressConditional(int organizationId, BitcoinChain chain, string derivationPath, string address, string addressFallback = "")
{
using (DbConnection connection = GetMySqlDbConnection())
@@ -188,7 +208,7 @@ namespace Swarmops.Database
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "organizationId", organizationId);
AddParameterWithName(command, "bitcoinChainId", (int) chain);
AddParameterWithName(command, "bitcoinChainId", (int)chain);
AddParameterWithName(command, "derivationPath", derivationPath);
AddParameterWithName(command, "addressString", address);
AddParameterWithName(command, "addressStringFallback", addressFallback);
@@ -198,7 +218,43 @@ namespace Swarmops.Database
}
}
public int SetHotBitcoinAddressBalance (int hotBitcoinAddressId, Int64 balanceSatoshis)
public int SetHotBitcoinAddressAddress(int hotBitcoinAddressId, string addressString)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
using (DbCommand command = GetDbCommand("SetHotBitcoinAddressAddress", connection))
{
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "hotBitcoinAddressId", hotBitcoinAddressId);
AddParameterWithName(command, "addressString", addressString);
return Convert.ToInt32(command.ExecuteScalar());
}
}
}
public int SetHotBitcoinAddressFallbackAddress(int hotBitcoinAddressId, string fallbackAddressString)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
using (DbCommand command = GetDbCommand("SetHotBitcoinAddressFallbackAddress", connection))
{
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "hotBitcoinAddressId", hotBitcoinAddressId);
AddParameterWithName(command, "balanceSatoshis", fallbackAddressString);
return Convert.ToInt32(command.ExecuteScalar());
}
}
}
public int SetHotBitcoinAddressBalance(int hotBitcoinAddressId, Int64 balanceSatoshis)
{
using (DbConnection connection = GetMySqlDbConnection())
{
+22 -4
View File
@@ -13,7 +13,7 @@ namespace Swarmops.Database
private const string outboundInvoiceFieldSequence =
" OutboundInvoiceId,CustomerName,InvoiceAddressPaper,InvoiceAddressMail,CurrencyId," + // 0-4
"0,OrganizationId,BudgetId,CreatedDateTime,CreatedByPersonId," + // 5-9
"OrganizationId,OrganizationSequenceId,BudgetId,CreatedDateTime,CreatedByPersonId," + // 5-9
"DueDate,ReminderCount,Reference,Domestic,Open, " + // 10-14
"Sent,SecurityCode,TheirReference " +
"FROM OutboundInvoices ";
@@ -32,8 +32,8 @@ namespace Swarmops.Database
string invoiceAddressPaper = reader.GetString (2);
string invoiceAddressMail = reader.GetString (3);
int currencyId = reader.GetInt32 (4);
// double amount = reader.GetDouble(5);
int organizationId = reader.GetInt32 (6);
int organizationId = reader.GetInt32 (5);
int organizationSequenceId = reader.GetInt32(6);
int budgetId = reader.GetInt32 (7);
DateTime createdDateTime = reader.GetDateTime (8);
int createdByPersonId = reader.GetInt32 (9);
@@ -47,7 +47,7 @@ namespace Swarmops.Database
string theirReference = reader.GetString (17);
return new BasicOutboundInvoice (outboundInvoiceId, customerName, invoiceAddressPaper, invoiceAddressMail,
currencyId, organizationId, budgetId, createdDateTime,
currencyId, organizationId, organizationSequenceId, budgetId, createdDateTime,
createdByPersonId, dueDate, reminderCount, reference, domestic, open, sent, securityCode, theirReference);
}
@@ -210,6 +210,24 @@ namespace Swarmops.Database
}
public int SetOutboundInvoiceSequence(int outboundInvoiceId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetOutboundInvoiceOrganizationSequenceId", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "outboundInvoiceId", outboundInvoiceId);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int CreateOutboundInvoiceItem (int outboundInvoiceId, string description, double amount)
{
using (DbConnection connection = GetMySqlDbConnection())
+2
View File
@@ -59,3 +59,5 @@
0059 - Added BackendServiceOrders, quite a bit of code too, for returning echo UTXOs from backend [RF]
0060 - Dumb fix for BSO tables: forgot autoincrement on the primary keys [RF]
0061 - And CreatedDateTime can't be an INT, while we're at it; also renaming dateTime => nowUtc [RF]
0062 - Added OrganizationSequenceId to OutboundInvoices (like 0041 but outbound) [RF]
0063 - Added DeriveUnique to HotBitcoinAddresses for ability to create unique HBAs [RF]