From d709878eff5c57c6ba5904e43100897f432bb77b Mon Sep 17 00:00:00 2001 From: Coding Enthusiast Date: Fri, 23 Apr 2021 08:47:08 +0430 Subject: [PATCH] Add a new Tranasction ctor using tx hex --- .../Blockchain/Transactions/Transaction.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Src/Autarkysoft.Bitcoin/Blockchain/Transactions/Transaction.cs b/Src/Autarkysoft.Bitcoin/Blockchain/Transactions/Transaction.cs index 1fea5bca..680ec088 100644 --- a/Src/Autarkysoft.Bitcoin/Blockchain/Transactions/Transaction.cs +++ b/Src/Autarkysoft.Bitcoin/Blockchain/Transactions/Transaction.cs @@ -48,6 +48,21 @@ public Transaction(int ver, TxIn[] txIns, TxOut[] txOuts, LockTime lt, Witness[] WitnessList = witnesses; } + /// + /// Initializes a new instance of using hexadecimal string representation of the transaction. + /// + /// + /// Transaction data in hexadecimal format + public Transaction(string hex) + { + byte[] data = Base16.Decode(hex); + var stream = new FastStreamReader(data); + if (!TryDeserialize(stream, out string error)) + { + throw new ArgumentException(error); + } + } + private const int MaxTxSize = 4_000_000;