コード例 #1
0
            public static BitcoinplusTransaction ParseJson(string tx)
            {
                JObject obj = JObject.Parse(tx);
                BitcoinplusTransaction bxcTx = new BitcoinplusTransaction(Bitcoinplus.BitcoinplusConsensusFactory.Instance);

                DeserializeFromJson(obj, ref bxcTx);

                return(bxcTx);
            }
コード例 #2
0
            private static void DeserializeFromJson(JObject json, ref BitcoinplusTransaction tx)
            {
                tx.Version  = (uint)json.GetValue("version");
                tx.Time     = (uint)json.GetValue("time");
                tx.LockTime = (uint)json.GetValue("locktime");

                var vin = (JArray)json.GetValue("vin");

                for (int i = 0; i < vin.Count; i++)
                {
                    var jsonIn = (JObject)vin[i];
                    var txin   = new TxIn();
                    tx.Inputs.Add(txin);

                    var script = (JObject)jsonIn.GetValue("scriptSig");
                    if (script != null)
                    {
                        txin.ScriptSig    = new Script(Encoders.Hex.DecodeData((string)script.GetValue("hex")));
                        txin.PrevOut.Hash = uint256.Parse((string)jsonIn.GetValue("txid"));
                        txin.PrevOut.N    = (uint)jsonIn.GetValue("vout");
                    }
                    else
                    {
                        var coinbase = (string)jsonIn.GetValue("coinbase");
                        txin.ScriptSig = new Script(Encoders.Hex.DecodeData(coinbase));
                    }

                    txin.Sequence = (uint)jsonIn.GetValue("sequence");
                }

                var vout = (JArray)json.GetValue("vout");

                for (int i = 0; i < vout.Count; i++)
                {
                    var jsonOut = (JObject)vout[i];
                    var txout   = new TxOut();
                    tx.Outputs.Add(txout);

                    var btc      = (decimal)jsonOut.GetValue("value");
                    var satoshis = btc * Money.COIN;
                    txout.Value = new Money((long)(satoshis));

                    var script = (JObject)jsonOut.GetValue("scriptPubKey");
                    txout.ScriptPubKey = new Script(Encoders.Hex.DecodeData((string)script.GetValue("hex")));
                }
            }