public ActionResult <Transaction> CommitTransaction([FromBody] TransactionRequest data) { var transaction = TransactionRequestToTransaction(data); Hash hash = transaction.GetHash(); if (data.Signature != null) { transaction.Signature = new ECSignature() { R = (Hash)data.Signature.R.ToUpper().PadLeft(64, '0'), S = (Hash)data.Signature.S.ToUpper().PadLeft(64, '0') }; var b = Utils.ValidateSignature(hash, transaction.Signature, transaction.AccountKey); if (!b) { return(StatusCode(403, MicroCoinError.Error(ErrorCode.InvalidSignature))); } using (var ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms, System.Text.Encoding.Default, true)) { bw.Write(1); bw.Write(1); } transaction.SaveToStream(ms); ms.Position = 0; Hash h = ms.ToArray(); var resp = client.ExecuteOperations(h); if (resp.First().Errors == null) { var op = resp.First(); var tr = new Transaction { Amount = op.Amount, Balance = op.Balance, Confirmations = op.Maturation.HasValue ? op.Maturation.Value : 0, Fee = op.Fee, OpHash = op.Ophash, Sender = op.SenderAccount, Target = op.DestAccount, Payload = new ByteString(op.PayLoad), Signer = (uint)op.SignerAccount, SubType = op.SubType.ToString(), Type = op.Type.ToString() }; return(Ok(tr)); } else { return(BadRequest(new MicroCoinError(ErrorCode.InvalidData, resp.First().Errors, "Check your data"))); } } } return(BadRequest(new MicroCoinError(ErrorCode.InvalidData, "Missing signature", "Please sign your transaction hash"))); }
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")); }