Example #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"));
        }
Example #3
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);
        }
        public override async Task <Transaction> ExecuteAsync(IClient client)
        {
            var ethGetTransactionByHash = new EthGetTransactionByHash(client);

            return(await ethGetTransactionByHash.SendRequestAsync(Settings.GetTransactionHash()));
        }
Example #5
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");
 }