public void Generate(byte[] privateKey)
        {
            var account  = new Neo.Wallets.KeyPair(privateKey);
            var contract = Neo.SmartContract.Contract.CreateSignatureContract(account.PublicKey);
            var address  = contract.Address;
            var wif      = account.Export();

            File.AppendAllText("export.txt", $"{address}\t{wif}\r\n", Encoding.Default);

            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
            QrCode    qrCode    = qrEncoder.Encode(wif);

            int w = (int)Math.Sqrt(qrCode.Matrix.InternalArray.Length);

            bool[,] qr = Zoom(qrCode.Matrix.InternalArray, 10, w);
            w          = (int)Math.Sqrt(qr.Length);

            byte[] data = new byte[qr.Length];

            for (int j = 0; j < w; j++)
            {
                for (int i = 0; i < w; i++)
                {
                    data[j * w + i] = (byte)(qr[i, j] ? 0 : 255);
                }
            }
            var dpi = 144;

            BitmapSource  qrBitSource   = BitmapSource.Create(w, w, dpi, dpi, PixelFormats.Gray8, null, data, w);
            DrawingVisual drawingVisual = new DrawingVisual();

            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), new Pen(new SolidColorBrush(Colors.White), 0), new Rect(new Point(0, 0), new Size(1000, 1000)));
                drawingContext.DrawText(
                    new FormattedText(
                        address,
                        System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                        new Typeface(new FontFamily("微软雅黑"), FontStyles.Normal, FontWeights.Regular, FontStretches.Normal),
                        9, new SolidColorBrush(Colors.Black)
                        ),
                    new Point(30, 10));

                //图片-二维码
                drawingContext.DrawImage(qrBitSource, new Rect(new Point(30, 30), new Size(200, 200)));
            }
            try
            {
                RenderTargetBitmap bmp = new RenderTargetBitmap(390, 390, dpi, dpi, PixelFormats.Pbgra32);
                bmp.Render(drawingVisual);
                //canvas1.Children.Add(new Image());
                //(canvas1.Children[0] as Image).Source = bmp;
                var fileName = $"code/{address}.jpg";
                Save(bmp, fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void Generate(byte[] privateKey)
        {
            var account  = new Neo.Wallets.KeyPair(privateKey);
            var contract = Neo.SmartContract.Contract.CreateSignatureContract(account.PublicKey);
            var address  = contract.Address;

            if (startWith.Any(p => address.StartsWith(p)) || contains.Any(p => address.Contains(p)) || endWith.Any(p => address.EndsWith(p)))
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                {
                    goodAddresses.Add(new GoodAddress()
                    {
                        Address    = contract.Address,
                        Privatekey = account.Export()
                    });
                    File.AppendAllText("goodAddress.txt", $"{contract.Address}\t{account.Export()}\r\n");
                });
            }
            var length = contract.Address.Sum(p => p.Length());

            if (length < goodLength || contract.Address.Count(p => p >= 'A' && p <= 'Z') < uppercase)
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                {
                    goodAddresses.Add(new GoodAddress()
                    {
                        Address    = contract.Address,
                        Privatekey = account.Export()
                    });
                    File.AppendAllText("goodAddress.txt", $"{contract.Address}\t{account.Export()}\r\n");
                });
            }
        }
Ejemplo n.º 3
0
        public static string SeedToWIF(byte[] seed, int coinType)
        {
            if (seed == null)
            {
                throw new ArgumentNullException(nameof(seed));
            }
            var account = new Neo.Wallets.KeyPair(SeedToPrivateKey(seed, coinType));

            return(account.Export());
        }