コード例 #1
0
        /// <summary>
        /// The method is used to broadcast the transaction over the blockchain using the account of the user
        /// </summary>
        /// <param name="contentdata">the transaction generated by the operations</param>
        /// <param name="privateKey">private key of the user</param>
        /// <typeparam name="T">type of the transaction's json body</typeparam>
        /// <returns> transaction response data</returns>
        protected TransactionResponse StartBroadcasting <T>(T contentdata, string privateKey)
        {
            var trans = new Transaction(Config);
            var key   = new Key(Config);
            TransactionResponse finalResponse;

            try
            {
                //ask for token symbol each time a transaction is performed
                //todo:next build append a parameter as "CurrencySymbol" in each transaction functions to calculate the charges.

                var fees = trans.CalculateFee(contentdata, "SPHTX");

                var feeAddedOperation = trans.AddFee(contentdata, fees.result);

                var transresponse = trans.CreateSimpleTransaction(feeAddedOperation.Result);
                if (transresponse == null)
                {
                    return(null);
                }

                var aboutresponse = trans.About();
                if (aboutresponse == null)
                {
                    return(null);
                }

                var transaction = JsonConvert.SerializeObject(transresponse.Result);
                var digest      = key.GetTransactionDigestServer(transresponse);

                var signature = key.SignDigest(digest.result, privateKey, new byte[130]);
                var response  = key.AddSignatureServer(transresponse, signature);
                finalResponse = trans.BroadcastTransaction(response);
            }
            catch (Exception ex)
            {
                _logger.WriteError($"Message:{ex.Message} | StackTrace:{ex.StackTrace}");
                throw;
            }

            return(finalResponse);
        }