public async Task <int> CountGlobalTransactions() { int result = 0; string current = await blocks.ActualBlockGet(); if (current.Length != 0) { bool trigger = true; while (trigger) { byte[] temp = await blocks.SearchBlock(current); if (current.Length != 0) { Additional.Block block = new Additional.Block(); block = blocks.BlockDeSerialize(temp); result += block.transactions_count; if (block.previous == Blocks.first_block) { trigger = false; } current = block.previous; } else { trigger = false; } } } return(result); }
public async Task <List <Transaction> > GetTransactionsListToPublicKey(string wallet) { List <Transaction> transactions = new List <Transaction>(); try { Transaction temp_tran = new Transaction(); List <Transaction> black = new List <Transaction>(); string current = await blocks.ActualBlockGet(); int tst = Transactions.size_transaction; byte[] temp_transaction = new byte[tst]; Block temp = new Block(); bool trigger = true; if (current.Length != 0) { while (trigger) { byte[] data = await blocks.SearchBlock(current); temp = blocks.BlockDeSerialize(data); for (int i = 0; i < temp.transactions_count; i++) { Array.Copy(temp.transactions, i * tst, temp_transaction, 0, tst); temp_tran = ParseTMessage(temp_transaction); if (temp_tran.output.put == wallet) { transactions.Add(temp_tran); } } if (temp.previous == Blocks.first_block) { trigger = false; } current = temp.previous; } trigger = true; current = await blocks.ActualBlockGet(); while (trigger) { byte[] data = await blocks.SearchBlock(current); temp = blocks.BlockDeSerialize(data); for (int i = 0; i < temp.transactions_count; i++) { Array.Copy(temp.transactions, i * tst, temp_transaction, 0, tst); temp_tran = ParseTMessage(temp_transaction); foreach (Transaction trn in transactions) { if (temp_tran.input.put == trn.name) { black.Add(trn); } } } if (temp.previous == Blocks.first_block) { trigger = false; } current = temp.previous; } } List <string> local_list = new List <string>(); string path = filesystem.FSConfig.db_path; local_list = filesystem.GetFilesListFromDirectory(path); foreach (string local_el in local_list) { Transaction local = new Transaction(); byte[] local_by = new byte[0]; local_by = await filesystem.GetFromFileAsync(path + @"\" + local_el); local = ParseTMessage(local_by); foreach (Transaction trn in transactions) { if (local.input.put == trn.name) { black.Add(trn); } } } foreach (Transaction trn in black) { transactions.Remove(trn); } } catch (Exception ex) { window.WriteLine(ex.ToString()); } window.WriteLine("Found: " + transactions.Count); return(transactions); }