Esempio n. 1
0
        static Mining.Merkle AsMerkle(string hex)
        {
            var res = new Mining.Merkle();

            HexHelp.DecodeInto(res.blob, hex);
            return(res);
        }
Esempio n. 2
0
        static public Notification.NewJob MiningNotify(object?evargs)
        {
            if (null == evargs)
            {
                throw new MissingRequiredException("mining.notify: no payload given");
            }
            if (evargs is not JArray concrete)
            {
                throw new MissingRequiredException("mining.notify: payload must be an array");
            }
            if (concrete.Count != 9 && concrete.Count != 10)
            {
                throw new BadParseException("mining.notify: element count mismatch, won't be able to parse");
            }

            var getTrie = concrete.Count == 10;

            byte[]? trie = null;
            var index          = 0;
            var jobid          = concrete[index++].Value <string>();
            var prevHashHexstr = concrete[index++].Value <string>();

            if (getTrie)
            {
                var triestr = concrete[index++].Value <string>();
                trie = HexHelp.DecodeHex(triestr);
            }
            var coinbaseFirst  = concrete[index++].Value <string>();
            var coinBaseSecond = concrete[index++].Value <string>();
            var merkles        = concrete[index++] as JArray ?? throw new BadParseException("mining.notify: merkles must be an array");
            var version        = HexHelp.DecodeHex(concrete[index++].Value <string>());
            var nbits          = HexHelp.DecodeHex(concrete[index++].Value <string>());
            var ntime          = HexHelp.DecodeHex(concrete[index++].Value <string>());
            var flush          = concrete[index++].Value <bool>();

            var cbFirst = HexHelp.DecodeHex(coinbaseFirst);
            var cbTail  = HexHelp.DecodeHex(coinBaseSecond);
            var res     = new Notification.NewJob(jobid, version, trie, cbFirst, cbTail, nbits, ntime, flush);

            HexHelp.DecodeInto(res.prevBlock.blob, prevHashHexstr);
            var decodedMerkles = merkles.Select(el => AsMerkle(el));

            res.merkles.AddRange(decodedMerkles);
            return(res);
        }