Пример #1
0
        private static String AddTableToAPI(UInt64 sb, UInt64 bb)
        {
            Console.WriteLine("Adds a table to mock api under carols address");

            Models.Contracts.Table table = new Models.Contracts.Table(2, 10)
            {
                SmallBlind    = sb,
                BigBlind      = bb,
                HashAlgorithm = "SHA256"
            };

            Models.Messages.AddTableRequest message = new Models.Messages.AddTableRequest();

            //message.BitcoinAddress = carol.ToString();
            //message.Signature = alice_secret.PrivateKey.SignMessage(message.Id.ToString());

            IRequest request = new Models.Messages.RPCRequest()
            {
                Method = "AddTableRequest"
            };

            request.Params = message;

            String        json           = JsonConvert.SerializeObject(message);
            StringContent requestContent = new StringContent(json, Encoding.UTF8, "application/json");
            String        url            = String.Format("{0}tables", API_URL);

            String response = Post(requestContent, url);

            return(response);
        }
Пример #2
0
        /// <summary>
        /// Add a player to the stub api.
        /// </summary>
        public static void AddPlayer(String url)
        {
            Models.Messages.AddPlayerRequest message = new Models.Messages.AddPlayerRequest();
            message.BitcoinAddress = carol.ToString();
            message.Player         = new TexasHoldemPlayer()
            {
                BitcoinAddress = carol.ToString(),
                IPAddress      = "localhost"
            };

            //message.Signature = alice_secret.PrivateKey.SignMessage(message.Id.ToString());

            IRequest request = new Models.Messages.RPCRequest()
            {
                Method = "AddPlayerRequest"
            };

            request.Params = message;
            //request.Signature = alice_secret.PrivateKey.SignMessage(JsonConvert.SerializeObject(request));

            String        json           = JsonConvert.SerializeObject(request);
            StringContent requestContent = new StringContent(json, Encoding.UTF8, "application/json");

            using (HttpClient httpClient = new HttpClient())
            {
                using (HttpResponseMessage responseMessage = httpClient.PostAsync(url, requestContent).Result)
                {
                    if (responseMessage.IsSuccessStatusCode)
                    {
                        String responseContent = responseMessage.Content.ReadAsStringAsync().Result;
                        Console.WriteLine(responseContent);
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
        }