Example #1
0
        Task IBrokerClient.Send(NewTransactionEvent transactionEvent)
        {
            CheckAndOpenConnection();

            string jsonMsg = transactionEvent.ToJson(Networks.GetFromCryptoCode(transactionEvent.CryptoCode).JsonSerializerSettings);
            var    body    = Encoding.UTF8.GetBytes(jsonMsg);

            var conf       = (transactionEvent.BlockId == null ? "unconfirmed" : "confirmed");
            var routingKey = $"transactions.{transactionEvent.CryptoCode}.{conf}";

            string msgIdHash = HashMessageId($"{transactionEvent.TrackedSource}-{transactionEvent.TransactionData.Transaction.GetHash()}-{(transactionEvent.TransactionData.BlockId?.ToString() ?? string.Empty)}");

            ValidateMessageId(msgIdHash);

            IBasicProperties props = Channel.CreateBasicProperties();

            props.MessageId   = msgIdHash;
            props.ContentType = typeof(NewTransactionEvent).ToString();
            props.Headers     = new Dictionary <string, object>();
            props.Headers.Add("CryptoCode", transactionEvent.CryptoCode);

            Channel.BasicPublish(
                exchange: NewTransactionExchange,
                routingKey: routingKey,
                basicProperties: props,
                body: body);

            return(Task.CompletedTask);
        }
Example #2
0
 public Task Send(NewTransactionEvent transactionEvent)
 {
     if (Clients.Length == 0)
     {
         return(Task.CompletedTask);
     }
     return(Task.WhenAll(Clients.Select(c => c.Send(transactionEvent))));
 }
Example #3
0
        public static NewTransactionEvent SetMatch(this NewTransactionEvent evt, TrackedTransaction match)
        {
            evt.TrackedSource = match.TrackedSource;
            var derivation = (match.TrackedSource as DerivationSchemeTrackedSource)?.DerivationStrategy;

            evt.Outputs.AddRange(match.GetReceivedOutputs(evt.TrackedSource));
            evt.DerivationStrategy = derivation;
            return(evt);
        }
Example #4
0
 public override IEnumerable <(MatchedOutput matchedOutput, OutPoint outPoint)> GetValidOutputs(
     NewTransactionEvent evtOutputs)
 {
     return(evtOutputs.Outputs.Where(output =>
                                     output.Value is AssetMoney assetMoney && assetMoney.AssetId == AssetId).Select(output =>
     {
         var outpoint = new OutPoint(evtOutputs.TransactionData.TransactionHash, output.Index);
         return (output, outpoint);
     }));
 }
Example #5
0
        public async Task Send(NewTransactionEvent transactionEvent)
        {
            string jsonMsg = transactionEvent.ToJson(SerializerSettings);
            var    bytes   = UTF8.GetBytes(jsonMsg);
            var    message = new Message(bytes);

            message.MessageId   = $"{transactionEvent.DerivationStrategy.GetHash()}-{transactionEvent.TransactionData.Transaction.GetHash()}-{(transactionEvent.TransactionData.BlockId?.ToString() ?? string.Empty)}).ToString()";
            message.ContentType = transactionEvent.GetType().ToString();
            await Client.SendAsync(message);
        }
        public JournaledAccountGrainState Apply(NewTransactionEvent @event)
        {
            Balance -= @event.Amount;

            _transactions.Add(new Transaction
            {
                Amount      = @event.Amount,
                BookingDate = @event.BookingDate
            });

            return(this);
        }
Example #7
0
        public async Task Send(NewTransactionEvent transactionEvent)
        {
            string jsonMsg   = transactionEvent.ToJson(SerializerSettings);
            var    bytes     = UTF8.GetBytes(jsonMsg);
            var    message   = new Message(bytes);
            string msgIdHash = HashMessageId($"{transactionEvent.TrackedSource}-{transactionEvent.TransactionData.Transaction.GetHash()}-{(transactionEvent.TransactionData.BlockId?.ToString() ?? string.Empty)}");

            ValidateMessageId(msgIdHash);
            message.MessageId   = msgIdHash;
            message.ContentType = transactionEvent.GetType().ToString();
            await Client.SendAsync(message);
        }
Example #8
0
 public virtual IEnumerable <(MatchedOutput matchedOutput, OutPoint outPoint)> GetValidOutputs(NewTransactionEvent evtOutputs)
 {
     return(evtOutputs.Outputs.Select(output =>
     {
         var outpoint = new OutPoint(evtOutputs.TransactionData.TransactionHash, output.Index);
         return (output, outpoint);
     }));
 }