/// <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 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); }