Beispiel #1
0
        public async Task <ActionResult <SubmitTransactionResponseViewModel> > SubmitTxsRawAsync(
            [FromQuery] string callbackUrl,
            [FromQuery] string callbackEncryption,
            [FromQuery] string callbackToken,
            [FromQuery] bool merkleProof,
            [FromQuery] bool dsCheck
            )
        {
            if (!IdentityProviderStore.GetUserAndIssuer(User, Request.Headers, out var identity))
            {
                return(Unauthorized("Incorrectly formatted token"));
            }
            // callbackUrl is validated as part of domainObject - no special validation here
            byte[] data;
            using (var ms = new MemoryStream())
            {
                await Request.Body.CopyToAsync(ms);

                data = ms.ToArray();
            }

            byte[][] transactionAsBytes;
            try
            {
                // This is not very efficient, since we will reparse bytes into NBitcoin.Transaction later again
                transactionAsBytes = HelperTools.ParseTransactionsIntoBytes(data);
            }
            catch (Exception)
            {
                var problemDetail = ProblemDetailsFactory.CreateProblemDetails(HttpContext, (int)HttpStatusCode.BadRequest);
                problemDetail.Title = "Unable to parse incoming stream of transactions";
                return(BadRequest(problemDetail));
            }

            var request = transactionAsBytes.Select(

                t =>
                new SubmitTransaction
            {
                RawTx              = t,
                CallbackUrl        = callbackUrl,
                CallbackEncryption = callbackEncryption,
                CallbackToken      = callbackToken,
                MerkleProof        = merkleProof,
                DsCheck            = dsCheck
            }).ToArray();

            var result =
                new SubmitTransactionsResponseViewModel(
                    await mapi.SubmitTransactionsAsync(request, identity));

            return(await SignIfRequiredAsync(result, result.MinerId));
        }