public void Test_Server_Rollback() { RestClientLib.RestClient client = new RestClientLib.RestClient(); //send request to the BlockChain Server string url = $"{rootUrl}/test/rollback"; string result = client.Get(url); }
public void Test_End() { RestClientLib.RestClient client = new RestClientLib.RestClient(); //send request to the BlockChain Server string url = $"{rootUrl}/test/end?{TestId}"; string result = client.Get(url); }
public void Test_Start(string TestId) { this.TestId = TestId; RestClientLib.RestClient client = new RestClientLib.RestClient(); //send request to the BlockChain Server string url = $"{rootUrl}/test/start?{TestId}"; string result = client.Get(url); }
//Sends a chain request to the BlockChain server (asks the server to return a list of BlockChain objects) public string chain() { RestClientLib.RestClient client = new RestClientLib.RestClient(); //send the Get request string url = rootUrl + "/chain"; string json = client.Get(url); //display the results (json) return(json); }
//Sends a mine reqest to the BlockChain server public string mine(string address) { RestClientLib.RestClient client = new RestClientLib.RestClient(); //build the request url and send the Get request string url = rootUrl + "/Mine?" + address; string json = client.Get(url); //deserialize the result into the Mine object var json_serializer = new JavaScriptSerializer(); Mine result = json_serializer.Deserialize <Mine>(json); return(string.Format("Index={0}, Message={1}, proof={2}, PreviousHash={3}", result.Index, result.Message, result.Proof, result.PreviousHash)); }
//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); }
public string PendingTransactions() { RestClientLib.RestClient client = new RestClientLib.RestClient(); //send the Get request string url = rootUrl + "/pending"; string json = client.Get(url); //deserialize the list of transactions retured from the server var json_serializer = new JavaScriptSerializer(); List <Transaction> txList = json_serializer.Deserialize <List <Transaction> >(json); StringBuilder b = new StringBuilder(); //output each transaction returned to the console foreach (Transaction tx in txList) { b.AppendLine(tx.ToString()); } return(b.ToString()); }
//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(); }
public void Test_Server_Miner_Stop() { RestClientLib.RestClient client = new RestClientLib.RestClient(); string url = $"{rootUrl}/test/miner/stop"; string result = client.Get(url); }
public void Test_Server_Miner_Start(string address) { RestClientLib.RestClient client = new RestClientLib.RestClient(); string url = $"{rootUrl}/test/miner/start?{address}"; string result = client.Get(url); }