public void SyncPayment(Payment payment, DateTime paymentTime) { if (PaymentCache.GetInstance().GetPaymentByTransactionId(payment.Transaction.ID) == null) { //if payment not entered yet for this transaction, insert a new one PaymentCache.GetInstance().InsertPayment(payment, paymentTime); } else { payment.ID = PaymentCache.GetInstance().GetPaymentByTransactionId(payment.Transaction.ID).ID; PaymentCache.GetInstance().UpdatePayment(payment); } }
public static PaymentFilter Parse(PaymentCache payment) { PaymentFilter pf = new PaymentFilter() { address = payment.address, amount = payment.amount, category = payment.category, time = payment.time, txId = payment.txId, vout = payment.vout }; return(pf); }
public List <SalesSummary> GetSalesSummary(DateTime startTime, DateTime endTime) { SalesSummary salesSummary; List <SalesSummary> salesSummaries = new List <SalesSummary>(); //every sales will have a payment entry, even if zero payed. So look for payments List <Payment> paymentsForDay = PaymentCache.GetInstance().GetPaymentsByTime(startTime, endTime); foreach (Payment payment in paymentsForDay) { salesSummary = new SalesSummary(); salesSummary.Payment = payment; salesSummaries.Add(salesSummary); } return(salesSummaries); }
public void InsertMem(PaymentCache paymentCache) { lock (lockObj) { if (PaymentBook.Contains(paymentCache.ToString())) { return; } if (Payment_Mem.Any(x => x.ToString() == paymentCache.ToString())) { return; } Payment_Mem.Add(paymentCache); PaymentFilters.Add(PaymentFilter.Parse(paymentCache)); } }
public void Insert(PaymentCache paymentCache) { lock (lockObj) { var paymentKey = paymentCache.ToString(); if (PaymentBook.Contains(paymentKey)) { return; } PutPaymentBook(new List <string> { paymentKey }); PaymentFilters.Add(PaymentFilter.Parse(paymentCache)); var key = GetKey(AppTables.TradeRecord, paymentKey); AppDomain.Put(key, paymentCache); } }
internal void RefreshCache() { PaymentCache.GetInstance().Clear(); PaymentCache.GetInstance(); }
internal void DeletePayment(int paymentId) { PaymentCache.GetInstance().DeletePayment(paymentId); }
internal double GetTotalPaymentForDay(DateTime day, bool bankMoney) { return(PaymentCache.GetInstance().GetPaymentTotalForDay(day, bankMoney)); }
internal double GetPaymentTotalByCustomerId(int customerID, DateTime startDate) { return(PaymentCache.GetInstance().GetPaymentTotalByCustomerId(customerID, startDate)); }
public Payment GetPaymentByTransactionID(int transactionID) { return(PaymentCache.GetInstance().GetPaymentByTransactionId(transactionID)); }
public static List <PaymentCache> GetPayments(this TransactionMsg transaction, List <string> accounts = null) { List <PaymentCache> payments = new List <PaymentCache>(); if (accounts == null) { accounts = AccountDac.Default.GetAccountBook(); } var spentHashIndexs = transaction.Inputs.Select(x => $"{x.OutputTransactionHash}_{x.OutputIndex}"); var outUtxos = UtxoSetDac.Default.Get(spentHashIndexs); var hasmyInput = outUtxos.Any(x => accounts.Contains(x.Account)); var newUtxos = transaction.GetUtxoSets(); var otherUtxos = newUtxos.Where(x => !accounts.Contains(x.Account)); var hasOtherOuput = otherUtxos.Any(); if (!hasmyInput && newUtxos.Count == otherUtxos.Count()) { return(payments); } if (hasmyInput) { if (transaction.InputCount == 1 && transaction.Inputs[0].OutputTransactionHash == DbDomains.EmptyHash) { //挖矿所得 var myUtxo = newUtxos.FirstOrDefault(); PaymentCache payment = new PaymentCache(); payment.address = myUtxo.Account; payment.account = ""; payment.category = PaymentCatelog.Generate; payment.totalInput = 0; payment.totalOutput = myUtxo.Amount; payment.amount = myUtxo.Amount; payment.fee = 0; payment.txId = myUtxo.TransactionHash; payment.vout = 0; payment.time = myUtxo.TransactionTime; payment.size = transaction.Outputs.FirstOrDefault().Size; payments.Add(payment); } else if (!hasOtherOuput) { //给自己 var totalInput = outUtxos.Sum(x => x.Amount); //总输入 var totalOuput = newUtxos.Sum(x => x.Amount); //总支出 var totalfee = totalInput - totalOuput; //手续费 var output = newUtxos.FirstOrDefault(); PaymentCache payment = new PaymentCache(); payment.address = output.Account; payment.account = ""; payment.category = PaymentCatelog.Self; payment.amount = output.Amount; payment.fee = totalfee; payment.size = transaction.Outputs.Sum(x => x.Size); payment.time = output.TransactionTime; payment.totalInput = totalInput; payment.totalOutput = output.Amount; payment.txId = output.TransactionHash; payment.vout = 0; payments.Add(payment); } else { //发送 var totalInput = outUtxos.Sum(x => x.Amount); //总输入 var totalOuput = newUtxos.Sum(x => x.Amount); //总支出 var totalfee = totalInput - totalOuput; //手续费 bool useFee = false; foreach (var newUtxo in newUtxos) { if (accounts.Contains(newUtxo.Account)) { continue; } PaymentCache payment = new PaymentCache(); payment.category = PaymentCatelog.Send; payment.address = newUtxo.Account; payment.account = ""; if (!useFee) { payment.fee = totalfee; useFee = true; } payment.amount = newUtxo.Amount + payment.fee; payment.size = 85; payment.time = newUtxo.TransactionTime; payment.totalInput = totalInput; payment.totalOutput = newUtxo.Amount; payment.txId = newUtxo.TransactionHash; payment.vout = newUtxo.Index; payments.Add(payment); } } } else { //接收 var totalInput = outUtxos.Sum(x => x.Amount); //总输入 var totalOuput = newUtxos.Sum(x => x.Amount); //总支出 var totalfee = totalInput - totalOuput; //手续费 foreach (var newUtxo in newUtxos) { if (!accounts.Contains(newUtxo.Account)) { continue; } PaymentCache payment = new PaymentCache(); payment.category = PaymentCatelog.Receive; payment.address = newUtxo.Account; payment.account = ""; if (newUtxo.Index == 0) { payment.fee = totalfee; } payment.amount = newUtxo.Amount; payment.size = 85; payment.time = newUtxo.TransactionTime; payment.totalInput = totalInput; payment.totalOutput = newUtxo.Amount; payment.txId = newUtxo.TransactionHash; payment.vout = newUtxo.Index; payments.Add(payment); } } return(payments); }
/// <summary> /// Get total payment happened for day /// </summary> /// <param name="day"></param> /// <param name="bankMoney"></param> /// <param name="paymtMadeOrReceived">True if payment made, false if payment received</param> /// <returns></returns> internal double GetTotalPaymentForDay(DateTime day, bool bankMoney, bool paymtMadeOrReceived) { return(PaymentCache.GetInstance().GetPaymentTotalForDay(day, bankMoney, paymtMadeOrReceived)); }
/// <summary> /// Get payment made or received /// </summary> /// <param name="customerID"></param> /// <param name="startDate"></param> /// <param name="paymtMadeOrReceived">true for payment made, false for payment received</param> /// <returns></returns> internal double GetPaymentTotalByCustomerId(int customerID, DateTime startDate, bool paymtMadeOrReceived) { return(PaymentCache.GetInstance().GetPaymentTotalByCustomerId(customerID, startDate, paymtMadeOrReceived)); }