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); }
public Task Send(NewTransactionEvent transactionEvent) { if (Clients.Length == 0) { return(Task.CompletedTask); } return(Task.WhenAll(Clients.Select(c => c.Send(transactionEvent)))); }
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); }
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); })); }
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); }
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); }
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); })); }