Beispiel #1
0
        public static Block ParseJson(string json)
        {
            var   formatter = new BlockExplorerFormatter();
            var   block     = JObject.Parse(json);
            var   txs       = (JArray)block["tx"];
            Block blk       = new Block();

            blk.Header.Bits           = new Target((uint)block["bits"]);
            blk.Header.BlockTime      = Utils.UnixTimeToDateTime((uint)block["time"]);
            blk.Header.Nonce          = (uint)block["nonce"];
            blk.Header.Version        = (int)block["ver"];
            blk.Header.HashPrevBlock  = uint256.Parse((string)block["prev_block"]);
            blk.Header.HashMerkleRoot = uint256.Parse((string)block["mrkl_root"]);
            foreach (var tx in txs)
            {
                blk.AddTransaction(formatter.Parse((JObject)tx));
            }
            return(blk);
        }
Beispiel #2
0
        static private RawFormatter GetFormatter(RawFormat rawFormat, Network network)
        {
            RawFormatter formatter = null;

            switch (rawFormat)
            {
            case RawFormat.Satoshi:
                formatter = new SatoshiFormatter();
                break;

            case RawFormat.BlockExplorer:
                formatter = new BlockExplorerFormatter();
                break;

            default:
                throw new NotSupportedException(rawFormat.ToString());
            }
            formatter.Network = network ?? formatter.Network;
            return(formatter);
        }