Esempio n. 1
0
        public IActionResult New(string sender, string recipient, double amount)
        {
            try
            {
                Console.WriteLine("Post: New Transaction...");
                if (string.IsNullOrEmpty(sender) || string.IsNullOrEmpty(recipient))
                {
                    Response.StatusCode = 400;
                    return(Json("Missing values"));
                }
                else
                {
                    var requestData = new PipeRequest
                    {
                        Type  = "newTransaction",
                        Value = JsonConvert.SerializeObject(new Transaction {
                            Sender    = sender,
                            Recipient = recipient,
                            Amount    = amount
                        })
                    };

                    Response.StatusCode = 201;
                    return(Json(service.RunClientPipe(JsonConvert.SerializeObject(requestData))));
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return(Json($"ERROR: {ex.Message}"));
            }
        }
Esempio n. 2
0
        public IActionResult Register(string address, string identifier)
        {
            try
            {
                if (!string.IsNullOrEmpty(address) && !string.IsNullOrEmpty(identifier))
                {
                    Console.WriteLine("Post: add new Node...");

                    var newNode = new Node
                    {
                        Address    = address,
                        Identifier = identifier
                    };

                    var requestData = new PipeRequest
                    {
                        Type  = "registerNode",
                        Value = JsonConvert.SerializeObject(newNode)
                    };

                    Response.StatusCode = 201;
                    var result = service.RunClientPipe(JsonConvert.SerializeObject(requestData));
                    return(Json(JsonConvert.DeserializeObject <Node>(result)));
                }
                else
                {
                    Response.StatusCode = 400;
                    return(Json("Missing values"));
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return(Json($"ERROR: {ex.Message}"));
            }
        }
Esempio n. 3
0
        public IActionResult Chain()
        {
            try
            {
                Console.WriteLine("Get: Full Chain...");
                var requestData = new PipeRequest
                {
                    Type  = "fullChain",
                    Value = string.Empty
                };

                Response.StatusCode = 200;
                var pipeResult = service.RunClientPipe(JsonConvert.SerializeObject(requestData));
                var result     = JsonConvert.DeserializeObject <Chain>(pipeResult);
                return(Json(result));
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return(Json($"ERROR: {ex.Message}"));
            }
        }