public void ClientManager(object o) { this.maxthread--; TcpClient tcpClient = (TcpClient)o; NetworkStream clientStream = tcpClient.GetStream(); if (!Epicoin.PeerList.Contains(((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString())) { Epicoin.PeerList.Add(((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString()); } byte[] buffer = new byte[8096]; clientStream.Read(buffer, 0, buffer.Length); List <string> address = Serialyze.UnserializeStringList(Encoding.Default.GetString(buffer)); for (int i = 0; i < address.Count; i++) { if (Epicoin.PeerList.Contains(address[i])) { Epicoin.PeerList.Add(address[i]); } } clientStream.Close(); tcpClient.Close(); this.maxthread++; return; }
private void GetData(byte[] data) { DataTransaction dataTransaction = Serialyze.UnserializeDataTransaction(Encoding.Default.GetString(data)); //Console.WriteLine("[ST] Analyse transaction"); string PubKeySender = dataTransaction.PubKey; string SenderAddress = dataTransaction.EncodeFromAddress; //Rsa.Decrypt(PubKeySender, dataTransaction.EncodeFromAddress); string ToAddress = dataTransaction.ToAddress; // Rsa.Decrypt(PubKeySender, dataTransaction.ToAddress); string Amount = dataTransaction.Amount; //Rsa.Decrypt(PubKeySender, dataTransaction.Amount); int Amountint; try { Amountint = int.Parse(Amount); } catch (Exception e) { return; } if (Amountint <= 0) { return; } if (Hash.CpuGenerate(PubKeySender) != SenderAddress) { return; } Transaction newTransaction = new Transaction(SenderAddress, ToAddress, Amountint); this.Coin.AddTransaction(newTransaction); }
public byte[] SendBlock(long time) { DataMine dataMine = new DataMine(this.difficulty, this.BlockToMine, this.Worker.Address[0], time); byte[] datasend = Encoding.Default.GetBytes(Serialyze.Serialize(dataMine)); return(datasend); }
public static void ImportChain() { if (File.Exists(Epicoin.blockchainfile)) { string chain = File.ReadAllText(Epicoin.blockchainfile); Blockchain.Blockchain c = Serialyze.UnserializeBlockchain(chain); Coin = c; } }
public static void ImportWallet() { if (File.Exists(Epicoin.walletfile)) { string wa = File.ReadAllText(Epicoin.walletfile); Wallet w = Serialyze.UnserializeWallet(wa); Wallet = w; } }
public static void ExportChain() { string chain = Serialyze.Serialize(Coin); try { File.WriteAllText(Epicoin.blockchainfile, chain); } catch (Exception) { } }
public static void ImportChain() { if (!File.Exists(Epicoin.Blockchainfile)) { return; } string chain = File.ReadAllText(Epicoin.Blockchainfile); Blockchain.Blockchain c = Serialyze.Unserialize <Blockchain.Blockchain>(chain); Coin = c; }
public static void ImportWallet() { if (!File.Exists(Epicoin.Walletfile)) { return; } string wa = File.ReadAllText(Epicoin.Walletfile); Wallet w = Serialyze.Unserialize <Wallet>(wa); Wallet = w; }
private void GetBlockchain(byte[] data) { string msgdata = Encoding.Default.GetString(data); try { this.chain = Serialyze.UnserializeBlockchain(msgdata); } catch { this.Reset(); } }
private Blockchain GetBlockchain(byte[] data) { string msgdata = Encoding.Default.GetString(data); try { return(Serialyze.UnserializeBlockchain(msgdata)); } catch { return(null); } }
private byte[] GenData() { DataMine dataMine; byte[] datasend; if (this.Coin.BlockToMines.Count != 0) { dataMine = new DataMine(this.Coin.Difficulty, this.Coin.BlockToMines[0], null); datasend = Encoding.Default.GetBytes(Serialyze.Serialize(dataMine)); } else { dataMine = new DataMine(this.Coin.Difficulty, null, null); datasend = Encoding.Default.GetBytes(Serialyze.Serialize(dataMine)); } return(datasend); }
public void GetBlock(byte[] data) { try { string msgdata = Encoding.Default.GetString(data); var datamine = Serialyze.UnserializeDataMine(msgdata); this.BlockToMine = null; this.difficulty = datamine.difficulty; if (datamine.block != null) { this.BlockToMine = new Block(datamine.block.Index, datamine.block.Timestamp, datamine.block.Data, datamine.block.PreviousHash); this.log.Write("[CM] Block received"); Console.WriteLine("[CM] Block received"); } } catch { return; } }
public void Send() { int timeout = 1000; byte[] datasend = Encoding.Default.GetBytes(Serialyze.Serialize(DataTrans)); bool send = false; this.Init(); while (IsConnected(this._tcpClient) && Epicoin.Continue && !send && timeout >= 0 && !this.error) { Stream stm = this._tcpClient.GetStream(); stm.Write(datasend, 0, datasend.Length); send = true; stm.Close(); timeout--; } this._tcpClient.Close(); if (timeout < 0) { this.error = true; } this.DataTrans = null; return; }
public string Export() { string wallet = Serialyze.Serialize(this); return(wallet); }
public ClientPeer(int port, List <string> peerList) : base("", port) { this.peerList = peerList; this.data = Encoding.Default.GetBytes(Serialyze.Serialize(peerList)); }
private bool AnalyzeMine(byte[] data) { DataMine dataMine; try { dataMine = Serialyze.UnserializeDataMine(Encoding.Default.GetString(data)); } catch (Exception e) { return(false); } //Console.WriteLine("[SM] Analyse bloc mined"); if (dataMine == null) { return(false); } if (dataMine.block == null) { return(false); } if (dataMine.block.Data == null) { return(false); } if (this.Coin.BlockToMines[0].Index != dataMine.block.Index) { return(false); } if (this.Coin.BlockToMines[0].Timestamp != dataMine.block.Timestamp) { return(false); } try { for (int i = 0; i < Block.nb_trans; i++) { if (this.Coin.BlockToMines[0].Data[i].Amount != dataMine.block.Data[i].Amount) { return(false); } if (this.Coin.BlockToMines[0].Data[i].FromAddress != dataMine.block.Data[i].FromAddress) { return(false); } if (this.Coin.BlockToMines[0].Data[i].ToAddress != dataMine.block.Data[i].ToAddress) { return(false); } if (this.Coin.BlockToMines[0].Data[i].Timestamp != dataMine.block.Data[i].Timestamp) { return(false); } } } catch (Exception e) { return(false); } if (this.Coin.BlockToMines[0].PreviousHash != dataMine.block.PreviousHash) { return(false); } return(this.Coin.NetworkMinePendingTransaction(dataMine.address, dataMine.block, dataMine.timemining)); }
public ClientSyncChain(int port, Blockchain chain) : base("", port) { this.data = Encoding.Default.GetBytes(Serialyze.Serialize(chain)); }
private byte[] GenData() { return(Encoding.Default.GetBytes(Serialyze.Serialize(this.Coin))); }