//Sends a create Transaction request to the BlockChain server public void Transfer(Transaction t) { //serialize the Transaction object string json = JsonConvert.SerializeObject(t); //build the request url string url = rootUrl + "/transfer"; //send the request via the REST Client RestClientLib.RestClient client = new RestClientLib.RestClient(); string jsonResult = client.Post(url, json); Console.WriteLine(jsonResult); }
//sends a Balance request to the BlockChain server //A list of adresses fromt he client wallet is sent public void Wallet_Balance() { var json_serializer = new JavaScriptSerializer(); //serialize the list of addresses from the client wallet List <string> addressList = _wallet.WalletEntries.Select(x => x.address).ToList(); string addresses = json_serializer.Serialize(addressList); RestClientLib.RestClient client = new RestClientLib.RestClient(); //send request to the BlockChain Server string url = rootUrl + "/balance"; string jsonResult = client.Post(url, addresses); //deserialize the list of balances returned List <Output> balances = json_serializer.Deserialize <List <Output> >(jsonResult); //update the wallet entry balance for each address returned foreach (Output o in balances) { WalletLib.WalletEntry we = _wallet.WalletEntries.Where(x => x.address == o.address).FirstOrDefault(); if (we != null) { if (o.amount < 0) { we.amount = 0; } else { we.amount = o.amount; } } } //save the wallet Wallet_Save(); }