void CacheTransactions(List<Transaction> transactions, BlockData bd) { Debug.WriteLine("Caching at block: " + bd.height.ToString()); if (!Directory.Exists("Cache")) Directory.CreateDirectory("Cache"); FileStream fs = File.Create(DateTime.Now.Ticks.ToString() + ".cache"); BinaryWriter bw = new BinaryWriter(fs); bw.Write(bd.prev_block); bw.Write(transactions.Count); foreach (Transaction t in transactions) { bw.Write(t.Hash); if (t.Sources != null) { bw.Write(t.Sources.Length); foreach (MoneyPlace mp in t.Sources) { bw.Write(mp.Address); bw.Write(mp.Value); } } else { bw.Write((int)0); } bw.Write(t.Destinations.Length); foreach (MoneyPlace mp in t.Destinations) { bw.Write(mp.Address); bw.Write(mp.Value); } } bw.Close(); }
public FetchBlock(string blockHash) { _wc = new WebClient(); _wc.DownloadStringCompleted += _wc_DownloadStringCompleted; _result = null; _wc.DownloadStringAsync(new Uri(string.Format("https://blockchain.info/block-index/{0}?format=json", blockHash))); Debug.WriteLine("Fetching block: " + blockHash); }
private void _wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { _result = JsonConvert.DeserializeObject<BlockData>(e.Result); Debug.WriteLine("Finished block: ({0}){1}", _result.height.ToString(), _result.hash); }
private void _wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { _result = JsonConvert.DeserializeObject <BlockData>(e.Result); Debug.WriteLine("Finished block: ({0}){1}", _result.height.ToString(), _result.hash); }