Moved second ledger entry to BSO

This commit is contained in:
Rick Falkvinge
2017-11-28 10:08:30 +01:00
parent 942be550c1
commit ac50462cb6
3 changed files with 64 additions and 16 deletions
@@ -35,7 +35,10 @@ namespace Swarmops.Logic.Support.BackendServices
string returnAddress = BitcoinUtility.GetInputAddressesForTransaction(BitcoinChain.Cash, utxoToReturn.TransactionHash)[0]; // assumes at least one input address -- not coinbase
// Return the money
BitcoinTransactionInputs inputs = utxoToReturn.AsInputs;
Int64 satoshisToReturn = utxoToReturn.AmountSatoshis;
Coin[] coins = inputs.Coins;
ICoin[] iCoins = coins;
@@ -53,6 +56,15 @@ namespace Swarmops.Logic.Support.BackendServices
BitcoinUtility.BroadcastTransaction(tx, BitcoinChain.Cash);
utxoToReturn.Delete();
utxoAddress.UpdateTotal();
// Update the ledger
string tx2Description = "Bitcoin echo test repayment";
FinancialTransaction ledgerTx2 = FinancialTransaction.Create(this.Organization,
DateTime.UtcNow, tx2Description);
ledgerTx2.AddRow(this.Organization.FinancialAccounts.DebtsOther, satoshisToReturn, this.Person);
ledgerTx2.AddRow(this.Organization.FinancialAccounts.AssetsBitcoinHot, -satoshisToReturn, this.Person);
ledgerTx2.BlockchainHash = tx.GetHash().ToString();
}
public int UtxoIdentity { get; set; }
+50 -3
View File
@@ -15,7 +15,7 @@ namespace Swarmops.Logic.Support
System.DateTime transactionDateTimeUtc = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
thisTx.TransactionDateTimeUtc = transactionDateTimeUtc.AddSeconds(Int64.Parse((string)json["time"]));
thisTx.TransactionHash = (string) json["hash"];
thisTx.TransactionHash = (string)json["hash"];
Int64 satoshiCount = 0;
thisTx.Inputs = new List<BlockchainTransactionRow>();
@@ -23,8 +23,8 @@ namespace Swarmops.Logic.Support
foreach (JObject inputRow in json["inputs"])
{
BlockchainTransactionRow newRow =
BlockchainTransactionRow.FromBlockchainInfoJson ((JObject) inputRow["prev_out"]);
thisTx.Inputs.Add (newRow);
BlockchainTransactionRow.FromBlockchainInfoJson((JObject)inputRow["prev_out"]);
thisTx.Inputs.Add(newRow);
satoshiCount += newRow.ValueSatoshis;
}
foreach (JObject outputRow in json["out"])
@@ -40,12 +40,48 @@ namespace Swarmops.Logic.Support
return thisTx;
}
static public BlockchainTransaction FromInsightInfoJson(JObject json)
{
BlockchainTransaction thisTx = new BlockchainTransaction();
System.DateTime transactionDateTimeUtc = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
thisTx.TransactionDateTimeUtc = transactionDateTimeUtc.AddSeconds(Int64.Parse((string)json["time"]));
thisTx.TransactionHash = (string)json["txid"];
Int64 satoshiCount = 0;
thisTx.Inputs = new List<BlockchainTransactionRow>();
thisTx.Outputs = new List<BlockchainTransactionRow>();
foreach (JObject inputRow in json["vin"])
{
BlockchainTransactionRow newRow =
BlockchainTransactionRow.FromInsightInfoJson(inputRow, true);
thisTx.Inputs.Add(newRow);
satoshiCount += newRow.ValueSatoshis;
}
foreach (JObject outputRow in json["vout"])
{
BlockchainTransactionRow newRow =
BlockchainTransactionRow.FromInsightInfoJson(outputRow);
thisTx.Outputs.Add(newRow);
satoshiCount -= newRow.ValueSatoshis;
}
thisTx.FeeSatoshis = satoshiCount; // inputs minus outputs equals fee
return thisTx;
}
public DateTime TransactionDateTimeUtc { get; private set; }
public Int64 FeeSatoshis { get; private set; }
public string TransactionHash { get; private set; }
public List<BlockchainTransactionRow> Inputs { get; private set; }
public List<BlockchainTransactionRow> Outputs { get; private set; }
}
public class BlockchainTransactionRow
@@ -61,6 +97,17 @@ namespace Swarmops.Logic.Support
return newRow;
}
static public BlockchainTransactionRow FromInsightInfoJson(JObject json, bool inRow = false)
{
BlockchainTransactionRow newRow = new BlockchainTransactionRow();
newRow.Address = (string)json["addr"];
newRow.ValueSatoshis = Int64.Parse((string)json["valueSat"]);
newRow.Index = Int32.Parse((string)json["n"]);
newRow.Spent = inRow && (bool)(json["spentTxId"] == null? false: true);
return newRow;
}
public string Address { get; private set; }
public bool Spent { get; private set; }
public Int64 ValueSatoshis { get; private set; }
+2 -13
View File
@@ -117,7 +117,6 @@ namespace Swarmops.Frontend.Pages.v5.Admin
backendOrder.Create(authData.CurrentOrganization, authData.CurrentUser);
string tx1Description = "Bitcoin technical echo test (will be repaid immediately)";
string tx2Description = "Bitcoin echo test repayment";
if (authData.CurrentOrganization.Currency.IsBitcoinCash)
@@ -130,11 +129,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin
ledgerTx1.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, satoshisReceived, authData.CurrentUser);
ledgerTx1.BlockchainHash = txHash;
FinancialTransaction ledgerTx2 = FinancialTransaction.Create(authData.CurrentOrganization,
DateTime.UtcNow, tx2Description);
ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, satoshisReceived, authData.CurrentUser);
ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, -satoshisReceived, authData.CurrentUser);
// ledgerTx2.BlockchainHash = returnTxHash; // TODO? Unknown at this point
// The return payment will be logged when made, so its hash can be recorded
if (satoshisReceived % 100 == 0)
{
@@ -158,16 +153,10 @@ namespace Swarmops.Frontend.Pages.v5.Admin
ledgerTx1.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).AmountForeignCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.BitcoinCash);
ledgerTx1.BlockchainHash = txHash;
FinancialTransaction ledgerTx2 = FinancialTransaction.Create(authData.CurrentOrganization,
DateTime.UtcNow, tx2Description);
ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, orgNativeCents, authData.CurrentUser);
ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, -orgNativeCents, authData.CurrentUser).AmountForeignCents = new Swarmops.Logic.Financial.Money(-satoshisReceived, Currency.BitcoinCash);
// ledgerTx2.BlockchainHash = returnTxHash; // TODO: How do we solve this, the recording of the return hash? It's not known here
// The second transaction is logged when executed in the back-end order
successMessage = string.Format(Resources.Pages.Admin.BitcoinEchoTest_FundsReceived,
authData.CurrentOrganization.Currency.DisplayCode, orgNativeCents/100.0, satoshisReceived/100.0);
// TODO: Second tx
}
return new AjaxCallResult() {DisplayMessage = successMessage, Success = true};