Exemple #1
0
        public static KzMinerId Parse(KzScript scriptPub)
        {
            var m     = (KzMinerId)null;
            var count = -1;

            foreach (var op in scriptPub.Decode())
            {
                count++;
                switch (count)
                {
                case 0: if (op.Code != KzOpcode.OP_0)
                    {
                        goto fail;
                    }
                    break;

                case 1: if (op.Code != KzOpcode.OP_RETURN)
                    {
                        goto fail;
                    }
                    break;

                case 2: if (op.Code != KzOpcode.OP_PUSH4 || op.Data.AsUInt32BigEndian() != _ProtocolPrefix)
                    {
                        goto fail;
                    }
                    m = new KzMinerId();
                    break;

                case 3: m._StaticJson = op.GetDataBytes().ToUTF8(); break;

                case 4: m._StaticSig = op.GetDataBytes(); break;

                case 5: m._DynamicJson = op.GetDataBytes().ToUTF8(); break;

                case 6: m._DynamicSig = op.GetDataBytes(); break;

                default: break;     // Ignore additional ops.
                }
            }
            if (m._StaticJson == null || m._StaticSig == null)
            {
                goto fail;
            }

            m._Static = JsonConvert.DeserializeObject <MinerIdStatic>(m._StaticJson);

            if (!m.Verify())
            {
                goto fail;
            }

            return(m);

fail:
            return(null);
        }
Exemple #2
0
 /// <summary>
 /// Decode a script segment and convert the Ops to builder BOps.
 /// </summary>
 /// <param name="script"></param>
 /// <returns>Sequence of builder BOps</returns>
 public static IEnumerable <KzBOp> ToBOps(this KzScript script) => script.Decode().Cast <KzBOp>();
Exemple #3
0
 /// <summary>
 /// Decode a script segment and convert the Ops to builder BOps.
 /// </summary>
 /// <param name="script"></param>
 /// <returns>Sequence of builder BOps</returns>
 public static IEnumerable <KzBOp> ToBOps(this KzScript script) => script.Decode().Select(o => new KzBOp(o));