public ActionResult <PurchaseAccountRequest> StartPurchaseAccount([FromBody] PurchaseAccountRequest data)
 {
     try
     {
         MicroCoin.Transactions.TransferTransaction transaction = PurchaseAccountRequestToTransaction(data);
         data.Hash = (Hash)transaction.GetHash();
         return(Ok(data));
     }
     catch (MicroCoinRPCException e)
     {
         return(this.HandlerError(e));
     }
     catch (Exception e)
     {
         return(StatusCode(500, new MicroCoinError(ErrorCode.UnknownError, e.Message, "")));
     }
 }
 public ActionResult <TransactionRequest> StartTransaction([FromBody] TransactionRequest data)
 {
     try
     {
         MicroCoin.Transactions.TransferTransaction transaction = TransactionRequestToTransaction(data);
         Hash hash = transaction.GetHash();
         data.Hash = hash;
         return(Ok(data));
     }
     catch (MicroCoinRPCException e)
     {
         return(this.HandlerError(e));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.BadRequest, new MicroCoinError(ErrorCode.UnknownError, e.Message, "")));
     }
 }
        public async Task <IActionResult> CommitPurchaseAccount([FromBody] PurchaseAccountRequest data)
        {
            MicroCoin.Transactions.TransferTransaction transaction = null;
            try
            {
                transaction = PurchaseAccountRequestToTransaction(data);
            }
            catch (MicroCoinRPCException e)
            {
                return(this.HandlerError(e));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new MicroCoinError(ErrorCode.UnknownError, e.Message, "")));
            }
            Hash hash = transaction.GetHash();

            if (data.Signature != null)
            {
                transaction.Signature = new ECSignature
                {
                    R = (Hash)data.Signature.R.PadLeft(64, '0'),
                    S = (Hash)data.Signature.S.PadLeft(64, '0')
                };
                if (Utils.ValidateSignature(hash, transaction.Signature, transaction.AccountKey))
                {
                    using (var ms = new MemoryStream())
                    {
                        using (BinaryWriter bw = new BinaryWriter(ms, System.Text.Encoding.Default, true))
                        {
                            bw.Write(1);
                            bw.Write(6);
                        }
                        transaction.SaveToStream(ms);
                        ms.Position = 0;
                        Hash h    = ms.ToArray();
                        var  resp = await client.ExecuteOperationsAsync(h);

                        if (resp.Count() > 0 && resp.First().Errors == null)
                        {
                            var r  = resp.First();
                            var tr = new PurchaseAccount
                            {
                                FounderAccount = (uint)r.Account,
                                AccountNumber  = (uint)r.DestAccount,
                                Type           = r.Type.ToString(),
                                SubType        = r.SubType.ToString(),
                                Fee            = r.Fee,
                                Confirmations  = r.Maturation,
                                OpHash         = r.Ophash,
                                Balance        = r.Balance
                            };
                            return(Ok(tr));
                        }
                        else
                        {
                            return(BadRequest(new MicroCoinError(ErrorCode.InvalidOperation,
                                                                 resp.Count() > 0 ? resp.First().Errors : "Invalid transaction",
                                                                 "Your transaction is invalid"
                                                                 )));
                        }
                    }
                }
                else
                {
                    return(StatusCode(403, MicroCoinError.Error(ErrorCode.InvalidSignature)));
                }
            }
            return(BadRequest("Missing signature"));
        }