Beispiel #1
0
        ///<summary>
        ///Inserisce nell'hashtable un nuovo indirizzo a un dato UTXO, salvandolo poi a tale indirizzo
        ///</summary>
        public void SetTransactionPath(UTXO utxo)
        {
            string appDataFolder  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string specificFolder = Path.Combine(appDataFolder, "Blockchain\\UTXODB");
            string filename       = specificFolder + "\\" + utxo.TxHash + ".json";

            if (Directory.Exists(specificFolder))
            {
                File.WriteAllText(filename, utxo.Serialize());
            }
            else
            {
                Directory.CreateDirectory(specificFolder);
                File.WriteAllText(filename, utxo.Serialize());
            }
            foreach (Output output in utxo.Output)
            {
                SetTransactionPath(output.PubKeyHash, filename);
            }
        }
Beispiel #2
0
        public Transaction(double amount, string hashReceiver, RSACryptoServiceProvider csp, bool testing) //costruttore per testing
        {
            this.outputs = new Output[] { new Output(amount, hashReceiver) };
            this.PubKey  = RSA.ExportPubKey(csp);
            this.inputs  = this.GetEnoughInputs();                                //forse vanno anche controllate le firme ma non penso
            this.Hash    = Utilities.SHA2Hash(JsonConvert.SerializeObject(this)); //Calcolo l'hash di questa transazione inizializzata fino a questo punto, esso farà da txId
            RSA.HashSignTransaction(this, csp);                                   //firmo la transazione fino a questo punto
            string appDataFolder  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string specificFolder = Path.Combine(appDataFolder, "Blockchain\\UTXODB");
            UTXO   utxo           = new UTXO(this.Hash, this.outputs);

            if (Directory.Exists(specificFolder))
            {
                File.WriteAllText(specificFolder + "\\" + this.Hash + ".json", utxo.Serialize());
            }
            else
            {
                Directory.CreateDirectory(specificFolder);
                File.WriteAllText(specificFolder + "\\" + this.Hash + ".json", utxo.Serialize());
            }
            //CPeers.Instance.DoRequest(ERequest.SendTransaction, this); TODO : implementa richiesta di invio transazione
        }
Beispiel #3
0
        public CoinbaseTransaction(RSACryptoServiceProvider csp, bool testing)//Costruttore da usare SOLO per testing
        {
            this.inputs  = null;
            this.outputs = new Output[] { new Output(50, Utilities.Base64SHA2Hash(RSA.ExportPubKey(csp))) };
            this.PubKey  = RSA.ExportPubKey(csp);
            this.Hash    = Utilities.SHA2Hash(JsonConvert.SerializeObject(this));
            RSA.HashSignTransaction(this, csp);

            //Salva transazione su disco
            string appDataFolder  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string specificFolder = Path.Combine(appDataFolder, "Blockchain\\UTXODB");
            UTXO   utxo           = new UTXO(this.Hash, this.outputs);

            if (Directory.Exists(specificFolder))
            {
                File.WriteAllText(specificFolder + "\\" + this.Hash + ".json", utxo.Serialize());
            }
            else
            {
                Directory.CreateDirectory(specificFolder);
                File.WriteAllText(specificFolder + "\\" + this.Hash + ".json", utxo.Serialize());
            }
        }