Exemplo n.º 1
0
            /// <summary>
            /// Gets the transaction info
            /// </summary>
            /// <param name="txId">Transaction id</param>
            /// <param name="assetId">Denominator asset</param>
            /// <returns>Transaction info</returns>
            /// <exception cref="InvalidOperationException">Denominator asset not registered</exception>
            public TransactionInfo TransactionInfo(string txId, string assetId = null)
            {
                Asset asset = null;

                if (assetId != null)
                {
                    var assetsList = _bus.QueryAsync(new AssetPairsInfoQuery()).Result;
                    asset = assetsList.Assets.SingleOrDefault(a => a.AssetId == assetId);
                    if (asset == null)
                    {
                        throw new InvalidOperationException($"Asset {assetId} not registered");
                    }
                }

                var latest = Resolve(new TransactionInfoQuery(txId));
                var date   = latest.Date;

                if (date == default)
                {
                    throw new InvalidOperationException($"No transaction information found for {txId}");
                }

                var quote = latest.Quotes.SingleOrDefault(q => q.Denominator == asset);

                if (quote != null || assetId == null)
                {
                    return(new TransactionInfo(latest.TxId, date, quote ?? latest.Quantity, latest.TransactionType, latest.Comment));
                }

                var diff = _timeline.Now.Minus(date);

                if (diff.Days > 0 || diff.Hours > 0)
                {
                    _bus.Command(new RetroactiveCommand <UpdateQuote>(
                                     new UpdateQuote(AssetPair.Fordom(latest.Quantity.Denominator, asset)), date)).Wait();

                    return(Resolve(
                               new HistoricalQuery <TransactionInfoQuery, TransactionInfo>(
                                   new TransactionInfoQuery(txId, asset), date)));
                }

                _bus.Command(new UpdateQuote(AssetPair.Fordom(latest.Quantity.Denominator, asset))).Wait();
                return(Resolve(new TransactionInfoQuery(txId, asset)));
            }
Exemplo n.º 2
0
        public override void EnterCreateBlock(HyconParser.CreateBlockContext context)
        {
            var hash         = context.hash().GetText();
            var previousHash = context.previousHash().GetText();
            var id           = Guid.NewGuid();

            var command = new CreateBlockCommand(id, hash, new List <string> {
                previousHash
            });

            _bus.Command(command);

            base.EnterCreateBlock(context);
        }
Exemplo n.º 3
0
        public override void EnterPutBlock(HyconParser.PutBlockContext context)
        {
            var hash         = context.hash().GetText();
            var previousHash = context.previousHash().GetText();

            var id = _bus.Query(new BlockQuery(hash));

            if (id == Guid.Empty)
            {
                id = Guid.NewGuid();
            }

            var command = new PutBlockCommand(id, hash, new List <string> {
                previousHash
            });

            _bus.Command(command);

            base.EnterPutBlock(context);
        }
Exemplo n.º 4
0
            public bool UpdateQuotes(string account, string denominator)
            {
                var assetsList = _bus.QueryAsync(new AssetPairsInfoQuery()).Result;
                var asset      = assetsList.Assets.SingleOrDefault(a => a.AssetId == denominator);

                if (asset == null)
                {
                    throw new InvalidOperationException($"Asset {denominator} not registered");
                }

                var txList = _queries.TransactionInfos(account);

                foreach (var t in txList)
                {
                    var fordom        = AssetPair.Fordom(t.Quantity.Denominator, asset);
                    var assetPairInfo = _coreQueries.AssetPairInfo(fordom);
                    if (!assetPairInfo.QuoteDates.Any(d => d.InUtc().Year == t.Date.InUtc().Year&& d.InUtc().Month == t.Date.InUtc().Month&& d.InUtc().Day == t.Date.InUtc().Day))
                    {
                        _bus.Command(new RetroactiveCommand <UpdateQuote>(new UpdateQuote(fordom), t.Date.InUtc().LocalDateTime.Date.AtMidnight().InUtc().ToInstant())).Wait();
                    }
                }

                return(true);
            }
Exemplo n.º 5
0
 public static Task CommandToDomain <T>(this IBus bus, T message) where T : DemoCommand
 {
     return(bus.Command(DomainEndpoint, message));
 }