private static void OnPaymentConfirmed(string CurrencyCode, string Address, double Amount, string TXID, int Timestamp)
 {
     using (DBEntities dbe = new DBEntities())
     {
         dbe.Addresses.Remove(dbe.Addresses.SingleOrDefault(a => a.Address == Address));
         dbe.SaveChanges();
     }
     Addresses.Remove(Address);
     SeenAddresses.Remove(Address);
     RabbitMessenger.Send($@"{{""jsonrpc"": ""2.0"", ""method"": ""TransactionConfirmed"", ""params"": {{""CurrencyCode"":""{CurrencyCode}"",""Address"":""{Address}"",""Amount"":""{Amount}"",""TXID"":""{TXID}"",""Time"":""{Timestamp}"" }} }}");
 }
        private static void OnGetNewAddress(int InvoiceID, string XPUB)
        {
            Network network = Network.Main;

            switch (CurrencyName)
            {
            case "LTC": network = NBitcoin.Altcoins.Litecoin.Instance.Mainnet; break;
            }

            var newAddress = "";

            using (DBEntities dbe = new DBEntities())
            {
                XpubAddressIndex lastIndex = dbe.XpubAddressIndex.SingleOrDefault(x => x.Xpub == XPUB);

                if (lastIndex == null)
                {
                    lastIndex = new XpubAddressIndex()
                    {
                        Xpub = XPUB, Index = -1
                    };
                    dbe.XpubAddressIndex.Add(lastIndex);
                }

                try {
                    if (Regex.IsMatch(XPUB, "^(ypub|Mtub|Ltub)"))
                    {
                        newAddress = GetAddressFromYPUB(XPUB, (uint)lastIndex.Index + 1, network);
                    }
                    else
                    {
                        newAddress = GetAddressFromXPUB(XPUB, (uint)lastIndex.Index + 1, network);
                    }
                }
                catch (Exception e) {
                    ravenClient.Capture(new SentryEvent(e));
                    return;
                }

                lastIndex.Index++;
                Addresses.Add(newAddress);

                dbe.Addresses.Add(new AddressCache()
                {
                    Address = newAddress, Currency = CurrencyName
                });
                dbe.SaveChanges();
            }

            string message = $@"{{""jsonrpc"": ""2.0"", ""method"": ""SetAddress"", ""params"": {{""InvoiceID"":{InvoiceID},""CurrencyCode"":""{CurrencyName}"",""Address"":""{newAddress}"" }} }}";

            try {
                RabbitMessenger.Send(message);
            }
            catch (Exception e) {
                Exception ex = new Exception($"Unable to send message to RabbitMQ - {message}", e);
                ravenClient.Capture(new SentryEvent(ex));
                throw e;
            }
            try {
                _currency.ImportAddress(newAddress);
            }
            catch (Exception e) {
                Exception ex = new Exception($"Unable to import {CurrencyName} address - {newAddress}", e);
                ravenClient.Capture(new SentryEvent(ex));
                throw e;
            }
        }
        private static void OnPaymentSeen(string CurrencyCode, string Address, double Amount, string TXID, int Timestamp)

        {
            SeenAddresses.Add(Address, TXID);
            RabbitMessenger.Send($@"{{""jsonrpc"": ""2.0"", ""method"": ""TransactionSeen"", ""params"": {{""CurrencyCode"":""{CurrencyCode}"",""Address"":""{Address}"",""Amount"":""{Amount}"",""TXID"":""{TXID}"",""Time"":""{Timestamp}"" }} }}");
        }