예제 #1
0
        /// <summary>
        /// Call a read-only method on a contract.
        /// </summary>
        /// <returns></returns>
        public async Task <string> ExecuteTransactionAsync(ExecuteTransactionDto input)
        {
            Transaction transaction;

            try
            {
                var byteArray = ByteArrayHelper.HexStringToByteArray(input.RawTransaction);
                transaction = Transaction.Parser.ParseFrom(byteArray);
            }
            catch (Exception e)
            {
                Logger.LogError(e, e.Message); //for debug
                throw new UserFriendlyException(Error.Message[Error.InvalidParams],
                                                Error.InvalidParams.ToString());
            }

            if (!transaction.VerifySignature())
            {
                throw new UserFriendlyException(Error.Message[Error.InvalidSignature],
                                                Error.InvalidSignature.ToString());
            }

            try
            {
                var response = await CallReadOnlyAsync(transaction);

                return(response?.ToHex());
            }
            catch (Exception e)
            {
                throw new UserFriendlyException(Error.Message[Error.InvalidTransaction],
                                                Error.InvalidTransaction.ToString(), e.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Call a read-only method of a contract.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <string> ExecuteTransactionAsync(ExecuteTransactionDto input)
        {
            var url        = GetRequestUrl(_baseUrl, "api/blockChain/executeTransaction");
            var parameters = new Dictionary <string, string>
            {
                { "RawTransaction", input.RawTransaction }
            };

            return(await _httpService.PostResponseAsync <string>(url, parameters));
        }