Exemplo n.º 1
0
        private void SendMessage(UserMessage userMessage)
        {
            if (_lastTransaction != _lastCommitedTransaction)
            {
                throw new InvalidOperationException("Can't send new transaction before previos was not confirmed");
            }

            Log("Sending new {0}", userMessage);
            var transaction = _transactionFactory.Create(User, _lastTransaction?.Signature ?? HashValue.Empty, userMessage);
            var message     = new NewTransactionMessage(UserNode, transaction);

            _messageBus.Push(message);
        }
        public async Task PublishAsync(IPaymentRequestTransaction transaction)
        {
            var message = new NewTransactionMessage
            {
                Id            = transaction.TransactionId,
                AssetId       = transaction.AssetId,
                Amount        = transaction.Amount,
                Confirmations = transaction.Confirmations,
                BlockId       = transaction.BlockId,
                Blockchain    = Enum.Parse <BlockchainType>(transaction.Blockchain.ToString()),
                //todo
                DueDate = transaction.DueDate ?? DateTime.UtcNow.AddDays(1)
            };

            _log.Info("Publishing new transaction message", message);

            await _publisher.ProduceAsync(message);
        }
Exemplo n.º 3
0
        private async Task ProcessMessageAsync(NewTransactionMessage arg)
        {
            _log.Info("Got a message about new transaction", arg.ToDetails());

            await _transactionsCache.SetItemAsync(new TransactionState
            {
                Transaction = new BcnTransaction
                {
                    Id            = arg.Id,
                    Amount        = arg.Amount,
                    Confirmations = arg.Confirmations,
                    BlockId       = arg.BlockId,
                    Blockchain    = Enum.Parse <BlockchainType>(arg.Blockchain.ToString()),
                    AssetId       = arg.AssetId
                },
                DueDate = arg.DueDate
            });
        }
Exemplo n.º 4
0
        public async Task PublishAsync(IPaymentRequestTransaction transaction)
        {
            var message = new NewTransactionMessage
            {
                Id            = transaction.TransactionId,
                AssetId       = transaction.AssetId,
                Amount        = transaction.Amount,
                Confirmations = transaction.Confirmations,
                BlockId       = transaction.BlockId,
                Blockchain    = Enum.Parse <BlockchainType>(transaction.Blockchain.ToString()),
                DueDate       = transaction.DueDate
            };

            await _log.WriteInfoAsync(nameof(TransactionPublisher), nameof(PublishAsync), message.ToJson(),
                                      "Publishing new transaction message");

            await _publisher.ProduceAsync(message);
        }
Exemplo n.º 5
0
        protected virtual void HandleAutoSend(MessageHeader rp, MemoryStream ms)
        {
            switch (rp.Operation)
            {
            case NetOperationType.Error:
                ByteString buffer = new byte[rp.DataLength];
                ms.Read(buffer, 0, rp.DataLength);
                break;

            case NetOperationType.NewBlock:
                NewBlockRequest response = new NewBlockRequest(ms, rp);
                OnNewBlock(response);
                break;

            case NetOperationType.AddOperations:
                lock (transactionLock)
                {
                    var newTransaction = new NewTransactionMessage(ms, rp);
                    OnNewTransaction(newTransaction);
                    break;
                }
            }
        }
Exemplo n.º 6
0
 public NewTransactionEventArgs(NewTransactionMessage transaction)
 {
     Transaction = transaction;
 }
Exemplo n.º 7
0
 protected virtual void OnNewTransaction(NewTransactionMessage newTransaction)
 {
     NewTransaction?.Invoke(this, new NewTransactionEventArgs(newTransaction));
 }