public CoinViewModel(Network network, ICoin coin, BalanceOperation op) { _Network = network; var colored = coin as ColoredCoin; BTCValue = coin.TxOut.Value.ToUnit(MoneyUnit.BTC).ToString() + " BTC"; if (colored == null) { Value = BTCValue; } else { Value = colored.Asset.Quantity.ToString() + " Assets"; Type = colored.Asset.Id.GetWif(network).ToString(); } if (op != null) { Confirmations = op.Confirmations; Op = op; } Coin = coin; var address = coin.TxOut.ScriptPubKey.GetDestinationAddress(network); if (address != null) { Owner = address.ToString(); } else { Owner = coin.TxOut.ScriptPubKey.ToString(); } }
public void Edit_balance_operation() { var operation = new BalanceOperation(payer) { Sum = 500, Description = "Тест" }; session.Save(operation); FlushAndCommit(); Click($"Платежи/Счета {DateTime.Today.Year}"); var selector = $"#balance-summary-{DateTime.Today.Year}-tab"; WaitForCss(selector); Click(Css(selector), "Редактировать"); AssertText("Возврат"); Css("#operation_Sum").TypeText("1000"); Click("Сохранить"); AssertText("Сохранено"); session.Refresh(operation); Assert.That(operation.Sum, Is.EqualTo(1000)); }
public async Task ExecuteAsync(string assetId, decimal amount, string comment, bool allowChangeBalance, string userId) { var balanceOperation = new BalanceOperation { Time = DateTime.UtcNow, AssetId = assetId, Type = "Settlement", Amount = amount, Comment = comment, UserId = userId }; if (allowChangeBalance) { string walletId = await _settingsService.GetWalletIdAsync(); if (amount > 0) { await _lykkeExchangeService.CashInAsync(walletId, assetId, Math.Abs(amount), userId, comment); } else { await _lykkeExchangeService.CashOutAsync(walletId, assetId, Math.Abs(amount), userId, comment); } } await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Settlement was executed", balanceOperation); }
// ToDo: The finding of transaction in DB will probably has a better algorithm // The following one by one version is the preliminary design private async Task <Transaction> FindThePunishment(BalanceOperation op, MultisigOutputEntity output) { using (OffchainMonitorContext context = new OffchainMonitorContext()) { var commitments = from c in context.Commitments where c.CommitmentOutput.TransactionId == output.TransactionId && c.CommitmentOutput.OutputNumber == output.OutputNumber select c; if (commitments != null && commitments.Count() > 0) { foreach (var c in commitments) { if (TransactionsMatch(c, op)) { return(new Transaction(c.Punishment)); } } } else { // No commitment cosuming the specified output return(null); } // No commitment found matching the specified transaction, spending multisig output return(null); } }
private void UpdateHistory(IEnumerable <historyData> obj) { var result = new ObservableCollection <BalanceOperation>(); foreach (var historyRec in obj) { var operationName = historyRec.type.ToString(); if (alloperations.ContainsKey(historyRec.type)) { operationName = TranslationProvider.Translate(alloperations[historyRec.type]).ToString(); } var operation = new BalanceOperation(operationName, historyRec.ticket_number, historyRec.amount, historyRec.created_at, historyRec.comment, Currency); //Skip adding System recalculation with zero amount if (historyRec.type == "27" && historyRec.amount == 0) { continue; } result.Add(operation); } if (HistoryrowHeight == 0) { if (result.Count > 0 && result[0].DateTime == DateTime.MinValue) { result[0].Hidden = true; } } BalanceOperations = result.Take(pagesize).ToList(); }
public async Task UpdateAsync(string assetId, decimal amount, string comment, string userId) { Credit credit = await GetByAssetIdAsync(assetId); credit.Add(amount); string walletId = await _settingsService.GetWalletIdAsync(); if (amount > 0) { await _lykkeExchangeService.CashInAsync(walletId, assetId, Math.Abs(amount), userId, comment); } else { await _lykkeExchangeService.CashOutAsync(walletId, assetId, Math.Abs(amount), userId, comment); } await _creditRepository.InsertOrReplaceAsync(credit); _cache.Set(credit); var balanceOperation = new BalanceOperation { Time = DateTime.UtcNow, AssetId = assetId, Type = "Credit", Amount = amount, Comment = comment, UserId = userId }; await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Credit was updated", balanceOperation); }
private void updateSummaryView() { BalanceOperation.updateView(balanceTable, mappingMonthSelector.Value, numberPerPage, balancePage); decimal totalDiff = BalanceOperation.calculateMonthlyTotal(balanceTable); monthlyProfit.Text = String.Format("{0:0.000}", totalDiff * 1000); monthlyProfit.ForeColor = (totalDiff > 0) ? Color.Red : Color.Green; }
public async Task InsertAsync(BalanceOperation balanceOperation) { var entity = new BalanceOperationEntity(GetPartitionKey(balanceOperation.Time), GetRowKey(balanceOperation.Time)); Mapper.Map(balanceOperation, entity); await _storage.InsertAsync(entity); }
public TransactionMappingForm(Guid guid) { InitializeComponent(); initializeView(); operation = new BalanceOperation(guid); operation.getNotConsumedBuying(table); remainValue.Text = operation.getTransaction().amount.ToString(); }
public static PaymentBcnTransaction ToDomainPaymentTransaction(this BalanceOperation src, string walletAddress, BlockchainType bcnType = BlockchainType.Bitcoin) { return(new PaymentBcnTransaction { WalletAddress = walletAddress, Amount = src.Amount.ToDecimal(MoneyUnit.BTC), AssetId = nameof(MoneyUnit.BTC), Blockchain = bcnType, Id = src.TransactionId.ToString(), BlockId = src.BlockId?.ToString(), Confirmations = src.Confirmations }); }
public void Update_payer_balance() { var payer = DataMother.CreatePayerForBillingDocumentTest(); var operation = new BalanceOperation(payer); operation.Type = OperationType.DebtRelief; operation.Description = "Возврат средств"; operation.Sum = 1000; session.Save(operation); Flush(); Reopen(); payer = session.Load <Payer>(payer.Id); Assert.That(payer.Balance, Is.EqualTo(1000)); }
public void BalanceSummary(uint id, int year) { CancelLayout(); var begin = new DateTime(year, 1, 1); var end = new DateTime(year, 12, 31); var payer = DbSession.Load <Payer>(id); var summary = new BalanceSummary(begin, end, payer); PropertyBag["year"] = year; PropertyBag["operation"] = new BalanceOperation(payer); PropertyBag["payer"] = payer; PropertyBag["items"] = summary.Items; PropertyBag["summary"] = summary; PropertyBag["before"] = summary.Before; PropertyBag["total"] = summary.Total; }
public void NewBalanceOperation(uint id, int year) { var payer = DbSession.Load <Payer>(id); var operation = new BalanceOperation(payer); BindObjectInstance(operation, "operation"); if (IsValid(operation)) { ActiveRecordMediator.Save(operation); Notify("Сохранено"); } else { Error(GetFirstErrorWithProperty(operation)); } //мы должны возвращаться на туже вкладку с которой был совершен переход RedirectToUrl(String.Format("~/Billing/Edit?BillingCode={0}#tab-balance-summary-{1}", payer.Id, year)); }
public static SerializableBalanceOperation GetSerializable(this BalanceOperation bo) { return(new SerializableBalanceOperation { Amount = new SerializableMoney { Satoshi = bo.Amount }, BlockId = new Serializableuint256 { Value = bo.BlockId.ToString() }, Confirmations = bo.Confirmations, FirstSeen = bo.FirstSeen, Height = bo.Height, ReceivedCoins = bo.ReceivedCoins.Select(c => c.GetSerializable()).ToList(), SpentCoins = bo.SpentCoins.Select(c => c.GetSerializable()).ToList(), TransactionId = new Serializableuint256 { Value = bo.TransactionId.ToString() } }); }
private bool TransactionsMatch(CommitmentEntity c, BalanceOperation op) { var commitmentTx = new Transaction(c.Commitment); foreach (var input in commitmentTx.Inputs) { if (!op.SpentCoins.Select(sp => sp.Outpoint.Hash == input.PrevOut.Hash && sp.Outpoint.N == input.PrevOut.N).Any()) { return(false); } } foreach (var output in commitmentTx.Outputs) { if (!op.ReceivedCoins.Select(rc => rc.GetScriptCode() == output.ScriptPubKey).Any()) { return(false); } } return(true); }
public async Task UpdateAmountAsync(string assetId, BalanceOperationType balanceOperationType, decimal amount, string comment, string userId) { await _semaphore.WaitAsync(); try { Token previousToken = await GetAsync(assetId); Token currentToken = previousToken.Copy(); string walletId = _settingsService.GetWalletId(); string transactionId; switch (balanceOperationType) { case BalanceOperationType.CashIn: currentToken.IncreaseAmount(amount); transactionId = await _lykkeExchangeService .CashInAsync(walletId, assetId, amount, userId, comment); break; case BalanceOperationType.CashOut: currentToken.DecreaseAmount(amount); try { transactionId = await _lykkeExchangeService .CashOutAsync(walletId, assetId, amount, userId, comment); } catch (NotEnoughFundsException) { throw new InvalidOperationException("No enough funds"); } break; default: throw new InvalidEnumArgumentException(nameof(balanceOperationType), (int)balanceOperationType, typeof(BalanceOperationType)); } await _tokenRepository.SaveAsync(currentToken); _cache.Set(currentToken); var balanceOperation = new BalanceOperation { Timestamp = DateTime.UtcNow, AssetId = assetId, Type = balanceOperationType, Amount = amount, IsCredit = false, Comment = comment, UserId = userId, TransactionId = transactionId }; await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Token amount updated", new { PreviuosToken = previousToken, CurrentToken = currentToken, BalanceOperation = balanceOperation }); } catch (Exception exception) { _log.WarningWithDetails("An error occurred while updating token", exception, new { AssetId = assetId, Type = balanceOperationType, Amount = amount, Comment = comment, UserId = userId }); throw; } finally { _semaphore.Release(); } }
public AddressHistoryRecord(BitcoinAddress address, BalanceOperation operation) { Address = address; Operation = operation; }
public async Task UpdateAsync(string assetId, BalanceOperationType balanceOperationType, decimal amount, string comment, string userId) { try { string walletId = _settingsService.GetWalletId(); string transactionId; switch (balanceOperationType) { case BalanceOperationType.CashIn: transactionId = await _lykkeExchangeService.CashInAsync(walletId, assetId, amount, userId, comment); break; case BalanceOperationType.CashOut: try { transactionId = await _lykkeExchangeService.CashOutAsync(walletId, assetId, amount, userId, comment); } catch (NotEnoughFundsException) { throw new InvalidOperationException("No enough funds"); } break; default: throw new InvalidEnumArgumentException(nameof(balanceOperationType), (int)balanceOperationType, typeof(BalanceOperationType)); } var balanceOperation = new BalanceOperation { Timestamp = DateTime.UtcNow, AssetId = assetId, Type = balanceOperationType, IsCredit = false, Amount = amount, Comment = comment, UserId = userId, TransactionId = transactionId }; await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Balance changed", balanceOperation); } catch (Exception exception) { _log.WarningWithDetails("An error occurred while changing balance", exception, new { AssetId = assetId, Type = balanceOperationType, Amount = amount, Comment = comment, UserId = userId }); throw; } }
public async Task UpdateAsync(BalanceOperationType balanceOperationType, decimal amount, string comment, string userId) { await _semaphore.WaitAsync(); try { Funding funding = (await GetAsync()).Copy(); string walletId = _settingsService.GetWalletId(); string transactionId; switch (balanceOperationType) { case BalanceOperationType.CashIn: funding.Add(amount); transactionId = await _lykkeExchangeService.CashInAsync(walletId, AssetId, amount, userId, comment); break; case BalanceOperationType.CashOut: funding.Subtract(amount); try { transactionId = await _lykkeExchangeService.CashOutAsync(walletId, AssetId, amount, userId, comment); } catch (NotEnoughFundsException) { throw new InvalidOperationException("No enough funds"); } break; default: throw new InvalidEnumArgumentException(nameof(balanceOperationType), (int)balanceOperationType, typeof(BalanceOperationType)); } await _fundingRepository.InsertOrReplaceAsync(funding); _cache.Set(funding); var balanceOperation = new BalanceOperation { Timestamp = DateTime.UtcNow, AssetId = AssetId, Type = balanceOperationType, IsCredit = true, Amount = amount, Comment = comment, UserId = userId, TransactionId = transactionId }; await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Funding amount updated", balanceOperation); } catch (Exception exception) { _log.WarningWithDetails("An error occurred while updating funding", exception, new { AssetId, Type = balanceOperationType, Amount = amount, Comment = comment, UserId = userId }); throw; } finally { _semaphore.Release(); } }
public AddressHistoryRecord(string address, BalanceOperation operation) { Address = address; _operation = operation; }
public Task AddAsync(BalanceOperation balanceOperation) { return(_balanceOperationRepository.InsertAsync(balanceOperation)); }
private static async Task <(string transactionId, decimal fee, bool isCashout, DateTime date, string address)> Execute(CustomQBitNinjaClient client, BalanceOperation op, BitcoinAddress addr) { var getBlock = client.GetBlock(new BlockFeature(op.BlockId), true); var getTx = client.GetTransaction(op.TransactionId); var date = getBlock.Result.AdditionalInformation.BlockTime.DateTime; var fee = getTx.Result.Fees.ToUnit(MoneyUnit.BTC); var isCashout = getTx.Result.SpentCoins.Any(p => p.TxOut.ScriptPubKey.GetDestinationAddress(Network.Main) == addr); Console.WriteLine($"{addr} {op.TransactionId} {fee} {isCashout} {date}"); return(transactionId : op.TransactionId.ToString(), fee : fee, isCashout : isCashout, date : date, address : addr.ToString()); }
public static Response <BalanceResult> Balance( this BalanceOperation operation, [NotNull] ISegwitDestination destination ) => operation.Get(destination.GetSegwitAddress().ToString());
public static async Task <Response <BalanceResult> > BalanceAsync( this BalanceOperation operation, [NotNull] ISegwitDestination destination ) => await operation.GetAsync(destination.GetSegwitAddress().ToString());
private static bool IsDeposit(BalanceOperation source) { return(!source.SpentCoins.Any()); }