Exemple #1
0
        public IActionResult Sign([FromBody] SignTransactionRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ErrorResponse("Validation error", ModelState)));
            }

            try
            {
                var txBytes  = HexUtil.ToByteArray(request.TransactionContext);
                var result   = _signingService.SignRawTransaction(request.Keys, txBytes);
                var response = new SignedTransactionResponse {
                    SignedTransaction = result
                };

                return(Ok(response));
            }

            catch (Exception e)
            {
                return(BadRequest(new ErrorResponse("SigningError")
                {
                    Errors =
                    {
                        { "message", new[] { e.Message } }
                    }
                }));
            }
        }
        public async Task <SignedTransactionResponse> SignTransactionAsync(IEnumerable <string> privateKeys, string transactionRaw)
        {
            string serializedRequest = Newtonsoft.Json.JsonConvert.SerializeObject(
                new SignRequest()
            {
                PrivateKeys = privateKeys, TransactionHex = transactionRaw
            });
            HttpResponseMessage message = await _httpClient.PostAsync($"{_signServiceUrl}/api/sign", new StringContent(serializedRequest));

            string serializedResponse = await message.Content.ReadAsStringAsync();

            SignedTransactionResponse response = await ConvertToOrThrow <SignedTransactionResponse>(serializedResponse);

            return(response);
        }
 /// <summary>
 /// Serialize currently generated transaction on to the blockchain with other transactions
 /// </summary>
 /// <param name="signedTx">Already signed transaction</param>
 /// <returns>object</returns>
 public SerializedTransaction SerializeTransaction(SignedTransactionResponse signedTx)
 {
     try
     {
         var reqname = CSharpToCpp.GetValue(MethodBase.GetCurrentMethod().Name);
         var @params = new ArrayList {
             signedTx
         };
         var result      = SendRequest(reqname, @params);
         var contentdata = JsonConvert.DeserializeObject <SerializedTransaction>(result);
         return(contentdata);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public async Task <string> SignTransactionAsync(IEnumerable <string> walletIds, string transactionRaw)
        {
            IEnumerable <IWallet> wallets = null;

            try
            {
                wallets = await walletIds.SelectAsync(async walletId =>
                {
                    IWallet wallet = await _walletRepository.GetWalletByPublicAddressAsync(walletId);

                    if (wallet == null)
                    {
                        throw new ClientSideException($"Wallet with id {walletId} does not exist in DB",
                                                      ClientSideException.ClientSideExceptionType.EntityDoesNotExist);
                    }

                    return(wallet);
                });
            }
            catch (AggregateException exc)
            {
                foreach (var exception in exc.InnerExceptions)
                {
                    if (exception is ClientSideException clientSideExc)
                    {
                        throw clientSideExc;
                    }
                }
            }
            catch (Exception exc)
            {
                throw;
            }

            IEnumerable <string> privateKeys = wallets.Select(wallet =>
            {
                string privateKey = _encryptionService.DecryptAesString(wallet.EncryptedPrivateKey, _passwordBytes);

                return(privateKey);
            });

            SignedTransactionResponse signedTransaction = await _internalSignServiceCaller.SignTransactionAsync(privateKeys, transactionRaw);

            return(signedTransaction.SignedTransaction);
        }
        /// <summary>
        /// Broadcasts transaction once it is created, helps to register Transactions on the Blockchain
        /// </summary>
        /// <param name="signedTx"></param>
        /// <returns>Returns Object with Transaction id and other details</returns>
        public TransactionResponse BroadcastTransaction(SignedTransactionResponse signedTx)
        {
            try
            {
                var reqname = CSharpToCpp.GetValue(MethodBase.GetCurrentMethod().Name);
                var @params = new ArrayList {
                    signedTx.result
                };
                var result      = SendRequest(reqname, @params);
                var contentdata = JsonConvert.DeserializeObject <TransactionResponse>(result);
                return(contentdata);
            }
            catch (Exception ex)
            {
                _logger.WriteError($"Message:{ex.Message} | StackTrace:{ex.StackTrace}");

                throw;
            }
        }
Exemple #6
0
        public IActionResult Sign([FromBody] SignTransactionRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ErrorResponse.Create("ValidationError").AddModelStateErrors(ModelState)));
            }

            try
            {
                var txBytes  = HexUtil.ToByteArray(request.TransactionContext);
                var result   = _signingService.SignRawTransaction(request.PrivateKeys.ToArray(), txBytes);
                var response = new SignedTransactionResponse {
                    SignedTransaction = result
                };

                return(Ok(response));
            }

            catch (Exception e)
            {
                return(BadRequest(ErrorResponse.Create("SigningError").AddModelError("message", e.Message)));
            }
        }