Ejemplo n.º 1
0
        public bool TryParseScript(ref SequenceReader <byte> r, IKzBlockParser bp, bool withoutLength = false)
        {
            var length = r.Remaining;

            if (!withoutLength && !r.TryReadVarint(out length))
            {
                goto fail;
            }

            bp.ScriptStart(this, r.Consumed);

            if (r.Remaining < length)
            {
                goto fail;
            }

            _script = r.Sequence.Slice(r.Position, length);
            r.Advance(length);

            bp.ScriptParsed(this, r.Consumed);

            return(true);

fail:
            return(false);
        }
Ejemplo n.º 2
0
        public bool TryParseTransaction(ref SequenceReader <byte> r, IKzBlockParser bp)
        {
            var offset = r.Consumed;
            var start  = r.Position;

            if (!r.TryReadLittleEndian(out _version))
            {
                goto fail;
            }
            if (!r.TryReadVarint(out long countIn))
            {
                goto fail;
            }

            bp.TxStart(this, offset);

            _vin = new KzTxIn[countIn];
            for (var i = 0L; i < countIn; i++)
            {
                ref var txin = ref _vin[i];
                if (!txin.TryParseTxIn(ref r, bp))
                {
                    goto fail;
                }
            }
Ejemplo n.º 3
0
        public bool TryParseTxIn(ref SequenceReader<byte> r, IKzBlockParser bp)
        {
            if (!_prevout.TryReadOutPoint(ref r)) goto fail;

            bp.TxInStart(this, r.Consumed);

            if (!_scriptSig.TryParseScript(ref r, bp)) goto fail;
            if (!r.TryReadLittleEndian(out _sequence)) goto fail;

            bp.TxInParsed(this, r.Consumed);

            return true;
            fail:
            return false;
        }
Ejemplo n.º 4
0
        public bool TryParseBlock(ref ReadOnlySequence <byte> ros, int height, IKzBlockParser bp)
        {
            var r = new SequenceReader <byte>(ros);

            if (!TryParseBlock(ref r, height, bp))
            {
                goto fail;
            }

            ros = ros.Slice(r.Consumed);

            return(true);

fail:
            return(false);
        }
Ejemplo n.º 5
0
        public bool TryParseBlock(ref SequenceReader <byte> r, int height, IKzBlockParser bp)
        {
            var offset = r.Consumed;

            if (!TryReadBlockHeader(ref r))
            {
                goto fail;
            }

            Height = height;

            bp.BlockStart(this, offset);

            if (!r.TryReadVarint(out long count))
            {
                goto fail;
            }

            _txs = new KzTransaction[count];

            for (var i = 0L; i < count; i++)
            {
                var t = new KzTransaction();
                _txs[i] = t;
                if (!t.TryParseTransaction(ref r, bp))
                {
                    goto fail;
                }
            }

            if (!VerifyMerkleRoot())
            {
                goto fail;
            }

            bp.BlockParsed(this, r.Consumed);

            return(true);

fail:
            return(false);
        }
Ejemplo n.º 6
0
        public bool TryParseTxOut(ref SequenceReader <byte> r, IKzBlockParser bp)
        {
            if (!r.TryReadLittleEndian(out _value))
            {
                goto fail;
            }

            bp.TxOutStart(this, r.Consumed);

            if (!_scriptPub.TryParseScript(ref r, bp))
            {
                goto fail;
            }

            bp.TxOutParsed(this, r.Consumed);

            return(true);

fail:
            return(false);
        }