Esempio n. 1
0
        /// <summary>
        /// Get transaction object using txId from Matic chain.
        /// </summary>
        /// <param name="transactionId">must be valid tx id</param>
        /// <returns></returns>
        public async Task <Transaction> GetTx(string transactionId)
        {
            if (SyncerUrl != null)
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(SyncerUrl);
                    HttpResponseMessage response = await client.GetAsync($"tx/{transactionId}");

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

                        TransactionResponse transactionResponse = JsonConvert.DeserializeObject <TransactionResponse>(contentString);
                        Transaction         txn = JsonConvert.DeserializeObject <Transaction>(transactionResponse.Reciept);
                        return(txn);
                    }
                }catch (Exception ex)
                {
                    //ignore the error
                }
            }
            EthGetTransactionByHash transactionByHash = ParentWeb3.Eth.Transactions.GetTransactionByHash;
            Transaction             tx = await transactionByHash.SendRequestAsync(transactionId);

            return(tx);
        }
        public async Task <object> ExecuteTestAsync(IClient client)
        {
            var ethGetTransactionByHash = new EthGetTransactionByHash(client);

            return
                (await
                 ethGetTransactionByHash.SendRequestAsync(
                     "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"));
        }
 public EthApiTransactionsService(IClient client) : base(client)
 {
     Call        = new EthCall(client);
     EstimateGas = new EthEstimateGas(client);
     GetTransactionByBlockHashAndIndex   = new EthGetTransactionByBlockHashAndIndex(client);
     GetTransactionByBlockNumberAndIndex = new EthGetTransactionByBlockNumberAndIndex(client);
     GetTransactionByHash  = new EthGetTransactionByHash(client);
     GetTransactionCount   = new EthGetTransactionCount(client);
     GetTransactionReceipt = new EthGetTransactionReceipt(client);
     SendRawTransaction    = new EthSendRawTransaction(client);
     SendTransaction       = new EthSendTransaction(client);
 }
 public EthTransactionsService(IClient client) : base(client)
 {
     Call = new EthCall(client);
     EstimateGas = new EthEstimateGas(client);
     GetTransactionByBlockHashAndIndex = new EthGetTransactionByBlockHashAndIndex(client);
     GetTransactionByBlockNumberAndIndex = new EthGetTransactionByBlockNumberAndIndex(client);
     GetTransactionByHash = new EthGetTransactionByHash(client);
     GetTransactionCount = new EthGetTransactionCount(client);
     GetTransactionReceipt = new EthGetTransactionReceipt(client);
     SendRawTransaction = new EthSendRawTransaction(client);
     SendTransaction = new EthSendTransaction(client);
 }
Esempio n. 5
0
        /// <summary>
        /// Get Transaction Proof
        /// </summary>
        /// <param name="trancationId"></param>
        /// <returns></returns>
        public async Task <TransactionProofResponse> GetTxProof(string transactionId)
        {
            if (!String.IsNullOrEmpty(SyncerUrl))
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(SyncerUrl);
                    HttpResponseMessage response = await client.GetAsync($"tx/{transactionId}/proof");

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

                        TransactionProofResponse transactionProofResponse = JsonConvert.DeserializeObject <TransactionProofResponse>(contentString);
                        return(transactionProofResponse);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"There was an error fetching the TX proof from the syncer url because {ex.Message}");
                }
            }
            else
            {
                try
                {
                    EthGetTransactionByHash transactionByHash = ParentWeb3.Eth.Transactions.GetTransactionByHash;
                    Transaction             tx = await transactionByHash.SendRequestAsync(transactionId);

                    TransactionProofResponse transactionProofResponse = new TransactionProofResponse()
                    {
                        Value = tx
                    };

                    return(transactionProofResponse);
                }catch (Exception ex)
                {
                    throw new Exception($"There was an error fething the txProof because {ex.Message}");
                }
            }

            return(null);
        }
Esempio n. 6
0
        static async Task <string> GetTransactions(BigInteger timespan)
        {
            var web3 = new Web3("http://127.0.0.1:7545");

            //testing with the ethereum /truffle example from the petshop tutorial
            var json     = JObject.Load(new JsonTextReader(new StreamReader(System.IO.File.OpenRead(orderSystemJson))));
            var abi      = json["abi"].ToString();
            var bytecode = json["bytecode"].ToString();
            var ganacheOrderSystemContractAddress = json["networks"]["5777"]["address"].ToString();

            var unlockAccountResult = await web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, senderPassword, 1200).ConfigureAwait(false);

            var unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - timespan;

            var transactionsByHash = new EthGetTransactionByHash(web3.Client);
            //var theresult = await transactionsByHash.SendRequestAsync(senderAddress);
            var abiMap = GetABIFunctionMap(json["abi"]);

            var arrayOfTransactions = new List <EthTransaction>();
            var maxBlockNumber      = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();

            var LastMaxBlockNumber = maxBlockNumber;

            long txTotalCount = 0;

            for (ulong blockNumber = 0; blockNumber <= LastMaxBlockNumber.Value; blockNumber++)
            {
                var blockParameter = new Nethereum.RPC.Eth.DTOs.BlockParameter(blockNumber);
                var block          = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(blockParameter);

                var trans   = block.Transactions;
                int txCount = trans.Length;
                txTotalCount += txCount;


                foreach (var tx in trans)
                {
                    try
                    {
                        var bn        = tx.BlockNumber.Value;
                        var transHash = tx.TransactionHash;
                        var ti        = tx.TransactionIndex.Value;
                        var nc        = tx.Nonce.Value;
                        var from      = tx.From;

                        var rpt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transHash);

                        var status = rpt.Status.Value;

                        var to = tx.To;
                        if (to == null)
                        {
                            to = "to:NULL";
                        }

                        var v  = tx.Value.Value;
                        var g  = tx.Gas.Value;
                        var gp = tx.GasPrice.Value;
                        Console.WriteLine(transHash.ToString() + " " + ti.ToString() + " " + nc.ToString() + " " + from.ToString() + " " + to.ToString() + " " + v.ToString() + " " + g.ToString() + " " + gp.ToString());
                        if (rpt.Logs.Count > 0)
                        {
                            foreach (var rp in rpt.Logs)
                            {
                                var tpic = rp["topics"];
                                Console.WriteLine("logs : " + tpic[0].ToString());
                                string funcVal = string.Empty;

                                abiMap.TryGetValue(tpic[0].ToString(), out funcVal);
                                if (funcVal != null)
                                {
                                    arrayOfTransactions.Add(new EthTransaction(block.Number.Value.ToString(), transHash, funcVal, from));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ScanTxExample.Tx:\t" + ex.ToString());
                        if (ex.InnerException != null)
                        {
                            Console.WriteLine("ScanTxExample.Tx:\t" + ex.InnerException.ToString());
                        }
                    }
                }
                Console.WriteLine();
            }
            return(JsonConvert.SerializeObject(arrayOfTransactions));
        }
        public override async Task <Transaction> ExecuteAsync(IClient client)
        {
            var ethGetTransactionByHash = new EthGetTransactionByHash(client);

            return(await ethGetTransactionByHash.SendRequestAsync(Settings.GetTransactionHash()));
        }
Esempio n. 8
0
        public async Task <string> WithdrawLocally(string transactionId, MaticTransactionOptions options)
        {
            EthGetTransactionByHash ethGetTransactionByHash = web3.Eth.Transactions.GetTransactionByHash;
            Transaction             withdrawTransaction     = await ethGetTransactionByHash.SendRequestAsync(transactionId);

            EthGetTransactionReceipt ethGetTransactionReceipt = web3.Eth.Transactions.GetTransactionReceipt;
            TransactionReceipt       withdrawReceipt          = await ethGetTransactionReceipt.SendRequestAsync(transactionId);

            EthGetBlockWithTransactionsByNumber ethGetBlockWithTransactionsByNumber = web3.Eth.Blocks.GetBlockWithTransactionsByNumber;
            BlockWithTransactions withdrawBlock = await ethGetBlockWithTransactionsByNumber.SendRequestAsync(withdrawReceipt.BlockNumber);


            //Draft Withdraw Object
            DraftWithdrawObject withdrawObject = new DraftWithdrawObject()
            {
                TxId    = transactionId,
                Block   = withdrawBlock,
                Tx      = withdrawTransaction,
                Receipt = withdrawReceipt
            };

            //Get Transaction Proof
            TransactionProofResponse transactionProof = await  GetTxProof(withdrawObject.Tx, withdrawObject.Block);

            //Get Receipt Proof
            TransactionProofResponse receiptProof = await GetReceiptProof(withdrawObject.Receipt, withdrawObject.Block, web3);

            //Get Current Header Block
            HexBigInteger currentHeaderBlock = await maticRootChainContract.CurrenctHeaderBlock();

            //Get the Header
            Header header = await maticRootChainContract.HeaderBlock(new HexBigInteger(currentHeaderBlock.Value - 1));

            HexBigInteger headerNumber = new HexBigInteger(currentHeaderBlock.Value - 1);
            int           start        = header.Start;
            int           end          = header.End;

            Header headers = await GetHeaders(start, end, web3);

            MerkleTree tree = new MerkleTree(headers);

            string blockHeader = GetBlockHeader(withdrawObject.Block);

            string headerProof = await tree.GetProof(blockHeader);

            WithdrawBurntTokensModel withdrawBurntTokensModel = new WithdrawBurntTokensModel()
            {
                HeaderNumber   = headerNumber,
                HeaderProof    = "",
                BlockNumber    = withdrawObject.Block.Number,
                BlockTimeStamp = withdrawObject.Block.Timestamp,
                TxRoot         = withdrawObject.Block.TransactionsRoot,
                ReceiptRoot    = withdrawObject.Block.ReceiptsRoot,
                Path           = receiptProof.Path,
                TxBytes        = withdrawObject.Tx.ToString(),
                TxProof        = transactionProof.ParentNodes,
                ReceiptBytes   = withdrawObject.Receipt.ToString(),
                ReceiptProof   = receiptProof.ParentNodes
            };

            string withdrawTxObject = await maticWithrawalManagerContract.WithdrawBurntTokens(withdrawBurntTokensModel, options);

            return(withdrawTxObject);
        }
 public async Task<dynamic> ExecuteTestAsync(RpcClient client)
 {
     var ethGetTransactionByHash = new EthGetTransactionByHash(client);
     return await ethGetTransactionByHash.SendRequestAsync( "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238");
 }