Ejemplo n.º 1
0
        public static void NewKey(string privateKey, string publicKey, string address, string type)
        {
            float amount = 0;

            if (type == "first")
            {
                amount = 100;
            }

            XDocument doc     = XDocument.Load(filePath);
            XElement  element = doc.Element("UserInfo").Element("Keys");
            XElement  key     = new XElement("Key");

            key.Add(new XElement("DateCreated", DateTime.Now.ToLongDateString()));
            key.Add(new XElement("PrivateKey", privateKey));
            key.Add(new XElement("PublicKey", publicKey));
            key.Add(new XElement("Address", address));
            key.Add(new XElement("TransactionId", CryptoCurrency.ByteArrayToString(CryptoCurrency.StringToSha256(publicKey))));

            key.Add(new XElement("Index", element.Elements("Key").Count().ToString()));

            List <XAttribute> attribute = new List <XAttribute>()
            {
                new XAttribute("type", type),
                new XAttribute("amount", amount.ToString()),
                new XAttribute("isConfirm", "false"),
                new XAttribute("unSpend", "true")
            };

            key.Element("Address").Add(attribute);
            element.Add(key);
            doc.Save(filePath);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Normal transaction. If return invalid then the transaction is not possible
        /// </summary>
        public Transaction(List <Output> outputs)
        {
            float total = 0;

            foreach (Output output in outputs)
            {
                total += output.Amount;
            }

            float[]      change     = new float[] { 0 };
            Span <float> changeSpan = change.AsSpan();
            List <Input> inputs     = XmlManager.GetTotal(total, change);



            if (change[0] == 0)
            {
                Inputs  = inputs;
                Outputs = outputs;
                Type    = "normal";
            }
            else
            {
                byte[] privateKey   = CryptoCurrency.Hash32Byte();
                byte[] publicKey    = CryptoCurrency.GetPublicKey(privateKey);
                string address      = CryptoCurrency.Sha1(publicKey);
                Output changeOutput = new Output(address, CryptoCurrency.ByteArrayToIntArray(publicKey), change[0]);
                Type = "change";
                XmlManager.NewKey(CryptoCurrency.ByteArrayToString(privateKey), CryptoCurrency.ByteArrayToString(publicKey), address, "change");
                outputs.Add(changeOutput);
                Inputs  = inputs;
                Outputs = outputs;
                Type    = "normal";
            }
        }
Ejemplo n.º 3
0
        private void NewAddress(object sender, RoutedEventArgs e)
        {
            byte[] privateKey = CryptoCurrency.Hash32Byte();
            byte[] publicKey  = CryptoCurrency.GetPublicKey(privateKey);
            string address    = CryptoCurrency.Sha1(publicKey);

            XmlManager.NewKey(CryptoCurrency.ByteArrayToString(privateKey), CryptoCurrency.ByteArrayToString(publicKey), address, "normal");
            NewKeyWindow newKeyWindow = new NewKeyWindow(address, CryptoCurrency.ByteArrayToString(publicKey));

            newKeyWindow.Show();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// First transaction amount given is 100 coin
        /// </summary>
        public Transaction()
        {
            byte[] privateKey = CryptoCurrency.Hash32Byte();
            byte[] publicKey  = CryptoCurrency.GetPublicKey(privateKey);
            string address    = CryptoCurrency.Sha1(publicKey);

            Inputs  = null;
            Outputs = new List <Output>()
            {
                new Output(address, CryptoCurrency.ByteArrayToIntArray(publicKey), 100)
            };
            Type = "first";
            XmlManager.NewKey(CryptoCurrency.ByteArrayToString(privateKey), CryptoCurrency.ByteArrayToString(publicKey), address, "first");
        }