REFACTOR: 'NativeCents' to 'ForeignCents'

This commit is contained in:
Rick Falkvinge
2016-01-16 23:37:18 +01:00
parent 64ab8792b7
commit d8291b6cdb
7 changed files with 25 additions and 16 deletions
+2 -2
View File
@@ -1069,7 +1069,7 @@ namespace Swarmops.Database
public Int64 GetFinancialTransactionRowNativeAmountCents(int financialTransactionRowId, int currencyId)
public Int64 GetFinancialTransactionRowAmountForeignCents(int financialTransactionRowId, int currencyId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
@@ -1094,7 +1094,7 @@ namespace Swarmops.Database
public void SetFinancialTransactionRowNativeAmountCents(int financialTransactionRowId, int currencyId, Int64 nativeAmountCents)
public void SetFinancialTransactionRowAmountForeignCents(int financialTransactionRowId, int currencyId, Int64 nativeAmountCents)
{
using (DbConnection connection = GetMySqlDbConnection())
{
+2 -2
View File
@@ -387,10 +387,10 @@ namespace Swarmops.Logic.Financial
// this is a known blockchain row, note its ledgered value in satoshis
if (!organizationLedgerUsesBitcoin)
{
Money nativeMoney = row.NativeAmountCents;
Money nativeMoney = row.AmountForeignCents;
if (nativeMoney.Currency.IsBitcoin) // it damn well should be, but just checking
{
satoshisLookup[row.AmountCents] = row.NativeAmountCents.Cents;
satoshisLookup[row.AmountCents] = row.AmountForeignCents.Cents;
}
}
}
+2 -2
View File
@@ -115,11 +115,11 @@ namespace Swarmops.Logic.Financial
}
public Currency NativeCurrency
public Currency ForeignCurrency
{
get
{
int currencyId = OptionalData.GetOptionalDataInt (ObjectOptionalDataType.FinancialAccountNativeCurrency);
int currencyId = OptionalData.GetOptionalDataInt (ObjectOptionalDataType.FinancialAccountNativeCurrency); // "Native" word is legacy
return (currencyId != 0 ? Currency.FromIdentity (currencyId) : null);
}
set
+14 -5
View File
@@ -59,18 +59,27 @@ namespace Swarmops.Logic.Financial
}
}
public Money NativeAmountCents
public Money AmountForeignCents
{
get
{
Currency currency = this.Account.NativeCurrency;
Currency currency = this.Account.ForeignCurrency;
int currencyId = currency.Identity;
Int64 nativeCents = SwarmDb.GetDatabaseForReading().GetFinancialTransactionRowNativeAmountCents (this.Identity, currencyId);
return new Money(nativeCents, currency, this.CreatedDateTime); // includes the valuation datetime, as it's a non-org currency
Int64 foreignCents = SwarmDb.GetDatabaseForReading().GetFinancialTransactionRowAmountForeignCents (this.Identity, currencyId);
return new Money(foreignCents, currency, this.CreatedDateTime); // includes the valuation datetime, as it's a non-org currency
}
set
{
SwarmDb.GetDatabaseForWriting().SetFinancialTransactionRowNativeAmountCents (this.Identity, value.Currency.Identity, value.Cents);
if (this.Account.ForeignCurrency == null)
{
this.Account.ForeignCurrency = value.Currency;
}
else if (this.Account.ForeignCurrency.Identity != value.Currency.Identity)
{
throw new InvalidOperationException("Trying to assign foreign-currency value to account with a different foreign currency set");
}
SwarmDb.GetDatabaseForWriting().SetFinancialTransactionRowAmountForeignCents (this.Identity, value.Currency.Identity, value.Cents);
}
}
+1 -1
View File
@@ -820,7 +820,7 @@ namespace Swarmops.Logic.Financial
// If the ledger isn't using bitcoin natively, we need to translate the miner fee paid to ledger cents before entering it into ledger
Int64 feeCentsLedger = new Money (feeSatoshis, Currency.Bitcoin).ToCurrency (organization.Currency).Cents;
ledgerTransaction.AddRow(organization.FinancialAccounts.AssetsBitcoinHot, -(masterPayoutPrototype.AmountCents + feeCentsLedger), null).NativeAmountCents = new Money(satoshisUsed, Currency.Bitcoin);
ledgerTransaction.AddRow(organization.FinancialAccounts.AssetsBitcoinHot, -(masterPayoutPrototype.AmountCents + feeCentsLedger), null).AmountForeignCents = new Money(satoshisUsed, Currency.Bitcoin);
ledgerTransaction.AddRow (organization.FinancialAccounts.CostsBitcoinFees, feeCentsLedger, null);
}
+2 -2
View File
@@ -115,7 +115,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin
Currency.Bitcoin);
// Make sure that the hotwallet native currency is bitcoin
authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.NativeCurrency = Currency.Bitcoin;
authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.ForeignCurrency = Currency.Bitcoin;
// Create success message and ledger transaction
string successMessage = string.Empty;
@@ -156,7 +156,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin
FinancialTransaction ledgerTx = FinancialTransaction.Create(authData.CurrentOrganization,
DateTime.UtcNow, "Bitcoin echo test (will be repaid immediately)");
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, -orgNativeCents, authData.CurrentUser);
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).NativeAmountCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.Bitcoin);
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).AmountForeignCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.Bitcoin);
ledgerTx.BlockchainHash = txHash;
successMessage = string.Format(Resources.Pages.Admin.BitcoinEchoTest_FundsReceived,
+2 -2
View File
@@ -121,7 +121,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
Currency.Bitcoin);
// Make sure that the hotwallet native currency is bitcoin
authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.NativeCurrency = Currency.Bitcoin;
authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.ForeignCurrency = Currency.Bitcoin;
// Create success message and ledger transaction
string successMessage = string.Empty;
@@ -169,7 +169,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
FinancialTransaction ledgerTx = FinancialTransaction.Create(authData.CurrentOrganization,
DateTime.UtcNow, "Donation (bitcoin to hotwallet)");
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.IncomeDonations, -orgNativeCents, authData.CurrentUser);
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).NativeAmountCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.Bitcoin);
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).AmountForeignCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.Bitcoin);
ledgerTx.BlockchainHash = txHash;
successMessage = string.Format (Resources.Pages.Financial.Donate_FundsReceived,