public static StratisTransaction ParseJson(string tx) { JObject obj = JObject.Parse(tx); StratisTransaction stratTx = new StratisTransaction(Stratis.StratisConsensusFactory.Instance); DeserializeFromJson(obj, ref stratTx); return(stratTx); }
private static void DeserializeFromJson(JObject json, ref StratisTransaction tx) { tx.Version = json.Value <uint>("version"); tx.Time = json.Value <uint>("time"); tx.LockTime = json.Value <uint>("locktime"); var vin = json.Value <JArray>("vin"); for (int i = 0; i < vin.Count; i++) { var jsonIn = (JObject)vin[i]; var txin = new TxIn(); var script = jsonIn.Value <JObject>("scriptSig"); if (script != null) { txin.ScriptSig = new Script(Encoders.Hex.DecodeData(script.Value <string>("hex"))); txin.PrevOut.Hash = uint256.Parse(jsonIn.Value <string>("txid")); txin.PrevOut.N = jsonIn.Value <uint>("vout"); } else { txin.ScriptSig = new Script(Encoders.Hex.DecodeData(jsonIn.Value <string>("coinbase"))); } txin.Sequence = jsonIn.Value <uint>("sequence"); tx.Inputs.Add(txin); } var vout = json.Value <JArray>("vout"); for (int i = 0; i < vout.Count; i++) { var jsonOut = (JObject)vout[i]; var txout = new TxOut() { Value = Money.Coins(jsonOut.Value <decimal>("value")) }; tx.Outputs.Add(txout); var script = jsonOut.Value <JObject>("scriptPubKey"); txout.ScriptPubKey = new Script(Encoders.Hex.DecodeData(script.Value <string>("hex"))); } }