コード例 #1
0
        public static String encryptReqXml(String rsaPrivateKey, String strDesKey, SortedDictionary <String, String> dic)
        {
            XmlDocument xmldoc = sortedDictionary2AllXml(dic);
            String      smlStr = ConvertXmlToString(xmldoc);

            String sha256SourceSignString = SHAUtil.encryptSHA256(smlStr);

            System.Diagnostics.Debug.WriteLine("xml摘要:" + sha256SourceSignString);
            byte[] encyptBytes = RSACoder.encryptByPrivateKey(sha256SourceSignString, rsaPrivateKey);
            String sign        = Convert.ToBase64String(encyptBytes, Base64FormattingOptions.InsertLineBreaks);
            String data        = smlStr.Replace("</jdpay>", "<sign>" + sign + "</sign></jdpay>");

            System.Diagnostics.Debug.WriteLine("封装后:" + data);
            byte[] key     = Convert.FromBase64String(strDesKey);
            String encrypt = Des3.Des3EncryptECB(key, data);

            System.Diagnostics.Debug.WriteLine("3DES后:" + encrypt);
            encrypt = Convert.ToBase64String(Encoding.UTF8.GetBytes(encrypt));
            System.Diagnostics.Debug.WriteLine("base64后:" + encrypt);
            SortedDictionary <String, String> reqdic = new SortedDictionary <string, string>();

            reqdic.AddOrReplace("version", dic.getVaule("version"));
            reqdic.AddOrReplace("merchant", dic.getVaule("merchant"));
            reqdic.AddOrReplace("encrypt", encrypt);

            XmlDocument reqXml = new XmlDocument();

            sortedDictionary2Xml(reqXml, reqdic);
            String reqXmlStr = ConvertXmlToString(reqXml);

            System.Diagnostics.Debug.WriteLine("请求xml:" + reqXmlStr);
            return(reqXmlStr);
        }
コード例 #2
0
        static public void sendTransaction(string address, IxiNumber amount)
        {
            Node.getBalance();

            if (Node.balance.balance < amount)
            {
                Console.WriteLine("Insufficient funds.\n");
                return;
            }

            SortedDictionary <byte[], IxiNumber> to_list = new SortedDictionary <byte[], IxiNumber>(new ByteArrayComparer());

            IxiNumber fee = ConsensusConfig.transactionPrice;

            byte[] from   = IxianHandler.getWalletStorage().getPrimaryAddress();
            byte[] pubKey = IxianHandler.getWalletStorage().getPrimaryPublicKey();
            to_list.AddOrReplace(Base58Check.Base58CheckEncoding.DecodePlain(address), amount);
            Transaction transaction = new Transaction((int)Transaction.Type.Normal, fee, to_list, from, null, pubKey, IxianHandler.getHighestKnownNetworkBlockHeight());

            if (IxianHandler.addTransaction(transaction, true))
            {
                Console.WriteLine("Sending transaction, txid: {0}\n", Transaction.txIdV8ToLegacy(transaction.id));
            }
            else
            {
                Console.WriteLine("Could not send transaction\n");
            }
        }
コード例 #3
0
        public SortedDictionary <byte[], IxiNumber> getToListAsArray()
        {
            if (_cachedToListArray.Count > 0)
            {
                return(_cachedToListArray);
            }

            _cachedToListArray.Clear();
            string[] split_str  = toList.Split(new string[] { "||" }, StringSplitOptions.None);
            int      to_counter = 0;

            foreach (string s1 in split_str)
            {
                to_counter++;
                if (to_counter == 1)
                {
                    continue;
                }

                string[] split_to = s1.Split(new string[] { ":" }, StringSplitOptions.None);
                if (split_to.Length < 2)
                {
                    continue;
                }
                byte[]    address = Base58Check.Base58CheckEncoding.DecodePlain(split_to[0]);
                IxiNumber amount  = new IxiNumber(new BigInteger(Convert.FromBase64String(split_to[1])));
                _cachedToListArray.AddOrReplace(address, amount);
            }

            return(_cachedToListArray);
        }
コード例 #4
0
        public WalletSend2Page(string[] addresses_with_amounts)
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

            // Go through each entry
            foreach (string address_and_amount in addresses_with_amounts)
            {
                if (address_and_amount.Length < 1)
                {
                    continue;
                }

                // Extract the address and amount
                string[] asplit = address_and_amount.Split(new string[] { ":" }, StringSplitOptions.None);
                if (asplit.Count() < 2)
                {
                    continue;
                }

                string address = asplit[0];
                string amount  = asplit[1];

                byte[] _address = Base58Check.Base58CheckEncoding.DecodePlain(address);
                if (Address.validateChecksum(_address) == false)
                {
                    DisplayAlert("Invalid address checksum", "Please make sure you typed the address correctly.", "OK");
                    return;
                }
                string[] amount_split = amount.Split(new string[] { "." }, StringSplitOptions.None);
                if (amount_split.Length > 2)
                {
                    DisplayAlert("SPIXI", "Please type a correct decimal amount.", "OK");
                    return;
                }

                IxiNumber _amount = amount;

                if (_amount < (long)0)
                {
                    DisplayAlert("SPIXI", "Please type a positive amount.", "OK");
                    return;
                }

                to_list.AddOrReplace(_address, _amount);
                totalAmount = totalAmount + _amount;
            }

            // Load the platform specific home page url
            var source = new UrlWebViewSource();

            source.Url     = string.Format("{0}html/wallet_send_2.html", DependencyService.Get <IBaseUrl>().Get());
            webView.Source = source;
        }
コード例 #5
0
        public WalletSend2Page(string[] addresses_with_amounts)
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

            // Go through each entry
            foreach (string address_and_amount in addresses_with_amounts)
            {
                if (address_and_amount.Length < 1)
                {
                    continue;
                }

                // Extract the address and amount
                string[] asplit = address_and_amount.Split(new string[] { ":" }, StringSplitOptions.None);
                if (asplit.Count() < 2)
                {
                    continue;
                }

                string address = asplit[0];
                string amount  = asplit[1];

                byte[] _address = Base58Check.Base58CheckEncoding.DecodePlain(address);
                if (Address.validateChecksum(_address) == false)
                {
                    displaySpixiAlert(SpixiLocalization._SL("global-invalid-address-title"), SpixiLocalization._SL("global-invalid-address-text"), SpixiLocalization._SL("global-dialog-ok"));
                    return;
                }
                string[] amount_split = amount.Split(new string[] { "." }, StringSplitOptions.None);
                if (amount_split.Length > 2)
                {
                    displaySpixiAlert(SpixiLocalization._SL("wallet-error-amount-title"), SpixiLocalization._SL("wallet-error-amountdecimal-text"), SpixiLocalization._SL("global-dialog-ok"));
                    return;
                }

                IxiNumber _amount = amount;

                if (_amount < (long)0)
                {
                    displaySpixiAlert(SpixiLocalization._SL("wallet-error-amount-title"), SpixiLocalization._SL("wallet-error-amount-text"), SpixiLocalization._SL("global-dialog-ok"));
                    return;
                }

                to_list.AddOrReplace(_address, _amount);
                totalAmount = totalAmount + _amount;
            }

            loadPage(webView, "wallet_send_2.html");
        }
コード例 #6
0
        private void sendPayment(string ethaddress, IxiNumber amount)
        {
            IxiNumber fee = ConsensusConfig.transactionPrice;

            byte[] from   = IxianHandler.getWalletStorage().getPrimaryAddress();
            byte[] pubKey = IxianHandler.getWalletStorage().getPrimaryPublicKey();


            byte[] _address = Base58Check.Base58CheckEncoding.DecodePlain(Config.bridgeAddress);
            to_list.AddOrReplace(_address, amount);

            byte[] _txdata = Encoding.ASCII.GetBytes(ethaddress);

            transaction = new Transaction((int)Transaction.Type.Normal, fee, to_list, from, _txdata, pubKey, IxianHandler.getHighestKnownNetworkBlockHeight());

            IxiNumber total_amount = transaction.amount + transaction.fee;

            if (Node.balance.balance < total_amount)
            {
                displaySpixiAlert(SpixiLocalization._SL("wallet-error-balance-title"), string.Format(SpixiLocalization._SL("wallet-error-balance-text"), total_amount.ToString(), Node.balance.balance.ToString()), SpixiLocalization._SL("global-dialog-ok"));
                Navigation.PopAsync(Config.defaultXamarinAnimations);
                return;
            }

            Logging.info("Preparing to send payment");

            Logging.info("Broadcasting tx");

            IxianHandler.addTransaction(transaction, true);
            Logging.info("Adding to cache");

            // Add the unconfirmed transaction to the cache
            TransactionCache.addUnconfirmedTransaction(transaction);


            Navigation.PushAsync(new WIXISentPage(transaction), Config.defaultXamarinAnimations);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: DefiDax/BinanceDex
        public static async Task SingleStream()
        {
            #region IoC, logging, configuration setup

            _height = 0;
            _locker = new object();

            IConfigurationRoot configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                                               .AddJsonFile("appsettings.json", true, false)
                                               .Build();

            ServiceProvider services = new ServiceCollection().AddLogging(builder => builder.SetMinimumLevel(LogLevel.Trace)
                                                                          .AddFile(configuration.GetSection("Logging:File")))
                                       .AddDexApi(configuration)
                                       .AddDexWebSockets(configuration)
                                       .AddAutoMapperConfiguration()
                                       .BuildServiceProvider();
            #endregion

            #region Options

            // Choose the symbol you want to track, the limit of the cache and the interval you want to track.
            const string symbol = @"OWT-303_BNB";
            const int    limit  = 30;
            const CandleStickInterval interval = CandleStickInterval.Minutes_1;

            #endregion

            // Get Services
            IBinanceDexApi        api                  = services.GetService <IBinanceDexApi>();
            IMapper               objectMapper         = services.GetService <IMapper>();
            ICandleStickWebSocket candleStickWebSocket = services.GetService <ICandleStickWebSocket>();


            // Get initial kline history from API and print to console
            IEnumerable <CandleStick> candles = await api.GetCandleSticksAsync(new GetCandleStickOptions { Symbol = symbol, Interval = interval, Limit = limit });

            Display(candles);


            // Storing the history in a sorted dictionary which we'll use as a cache when using the websockets
            Dictionary <long, CandleStick>       csTemp           = candles.ToDictionary(candleStick => candleStick.OpenTime, candleStick => candleStick);
            SortedDictionary <long, CandleStick> candleStickCache = new SortedDictionary <long, CandleStick>(csTemp, new ReverseComparer <long>());


            // Configuring the websocket
            candleStickWebSocket.OnDisconnect        += (sender, eventArgs) => Console.WriteLine("Disconnected");
            candleStickWebSocket.OnCandleStickUpdate += (sender, update) =>
            {
                // Using a lock to avoid competing for the console window
                lock (_locker)
                {
                    // In case data arrives out of order, check event height is > previous height
                    if (update.EventHeight < _height)
                    {
                        return;
                    }

                    _height = update.EventHeight;

                    // Update our cache
                    candleStickCache.AddOrReplace(update.CandleStick.OpenTime, objectMapper.Map <CandleStick>(update.CandleStick));

                    // Remove old candles as new ones arrive, maintaining the buffer specified in the `limit` const
                    if (candleStickCache.Count > limit)
                    {
                        candleStickCache.Skip(limit)
                        .ToList()
                        .ForEach(c => candleStickCache.Remove(c.Key));
                    }

                    // Print to console
                    Display(candleStickCache.Select(x => x.Value).Reverse());
                }
            };

            candleStickWebSocket.Connect();
            candleStickWebSocket.Subscribe(symbol, interval);
            await Console.In.ReadLineAsync();

            candleStickWebSocket.UnsubscribeAll();
            candleStickWebSocket.Close();
            candleStickWebSocket.Dispose();
        }
コード例 #8
0
 public void AddOrReplaceAlias(CommandEvaluationContext context, string name, string text)
 {
     _aliases.AddOrReplace(name, text);
 }