示例#1
0
        public async Task <TransactionReceiptResponse> GetTransactionReceipt(IEnumerable <byte> txId)
        {
            if (txId == null)
            {
                throw new ArgumentNullException(nameof(txId));
            }


            var httpClient = _httpClientFactory.BuildClient();
            var jParams    = new JArray();

            jParams.Add(txId.ToHexString());
            var jObj = new JObject();

            jObj.Add("id", Guid.NewGuid().ToString());
            jObj.Add("method", Constants.RpcOperations.GetTransactionReceipt);
            jObj.Add("params", jParams);
            var content = new StringContent(jObj.ToString(), System.Text.Encoding.UTF8, ContentType);
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                Content    = content,
                RequestUri = GetUri()
            };

            var response = await httpClient.SendAsync(request).ConfigureAwait(false);

            var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            string errorCode = null;
            var    jsonObj   = JObject.Parse(json);

            if (TryGetError(jsonObj, out errorCode))
            {
                throw new RpcException(errorCode);
            }

            var r = jsonObj.GetValue("result").ToString();

            if (string.IsNullOrWhiteSpace(r))
            {
                return(null);
            }

            var resultObj = JObject.Parse(r);
            var result    = new TransactionReceiptResponse
            {
                TransactionHash = resultObj.GetValue("transactionHash").ToString(),
                ContractAddress = resultObj.GetValue("contractAddress").ToString()
            };

            return(result);
        }
示例#2
0
        /// <summary>
        /// Get Receipt Proof
        /// </summary>
        /// <param name="transactionId"></param>
        /// <returns></returns>
        public async Task <TransactionReceiptResponse> GetReceiptProof(string transactionId)
        {
            if (!String.IsNullOrEmpty(SyncerUrl))
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(SyncerUrl);
                    HttpResponseMessage response = await client.GetAsync($"tx/{transactionId}/receipt/proof");

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string contentString = await response.Content.ReadAsStringAsync();

                        TransactionReceiptResponse receiptProofResponse = JsonConvert.DeserializeObject <TransactionReceiptResponse>(contentString);
                        return(receiptProofResponse);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"Could not fetch the Receipt Proof from the syncer URL because {ex.Message}");
                }
            }
            else
            {
                try
                {
                    EthGetTransactionReceipt transactionByHash = ParentWeb3.Eth.Transactions.GetTransactionReceipt;
                    TransactionReceipt       tx = await transactionByHash.SendRequestAsync(transactionId);

                    TransactionReceiptResponse transactionReceiptResponse = new TransactionReceiptResponse()
                    {
                        Value = tx
                    };

                    return(transactionReceiptResponse);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Could not fetch te receipt proof because {ex.Message}");
                }
            }


            return(null);
        }