예제 #1
0
        public void Load(BinaryReader br)
        {
            mVersion = br.ReadUInt32();
            mTimestamp = br.ReadUInt32();

            int inputCount = br.ReadInt32();
            for (int i = 0; i < inputCount; i++)
            {
                TransactionInput ti = new TransactionInput();
                ti.mPrevOuptutHash = br.ReadBytes(32);
                ti.mPrevOutputIndex = br.ReadUInt32();

                int scriptLen = br.ReadInt32();
                ti.mScript = br.ReadBytes(scriptLen);
                ti.mSequence = br.ReadUInt32();
                mInputs.Add(ti);
            }

            int outputCount = br.ReadInt32();
            for (int i = 0; i < outputCount; i++)
            {
                TransactionOutput to = new TransactionOutput();
                to.mValue = br.ReadUInt64();
                to.mRealValue = (double)to.mValue / 1000000.0;

                int scriptLen = br.ReadInt32();
                to.mScript = br.ReadBytes(scriptLen);
            }

            mLockTime = br.ReadUInt32();
            int commentLen = br.ReadInt32();
            mComment = br.ReadBytes(commentLen);
        }
예제 #2
0
        public void Load(BinaryReader br)
        {
            mVersion   = br.ReadUInt32();
            mTimestamp = br.ReadUInt32();

            int inputCount = br.ReadInt32();

            for (int i = 0; i < inputCount; i++)
            {
                TransactionInput ti = new TransactionInput();
                ti.mPrevOuptutHash  = br.ReadBytes(32);
                ti.mPrevOutputIndex = br.ReadUInt32();

                int scriptLen = br.ReadInt32();
                ti.mScript   = br.ReadBytes(scriptLen);
                ti.mSequence = br.ReadUInt32();
                mInputs.Add(ti);
            }

            int outputCount = br.ReadInt32();

            for (int i = 0; i < outputCount; i++)
            {
                TransactionOutput to = new TransactionOutput();
                to.mValue     = br.ReadUInt64();
                to.mRealValue = (double)to.mValue / 1000000.0;

                int scriptLen = br.ReadInt32();
                to.mScript = br.ReadBytes(scriptLen);
            }

            mLockTime = br.ReadUInt32();
            int commentLen = br.ReadInt32();

            mComment = br.ReadBytes(commentLen);
        }
예제 #3
0
        public void HandleBlockPacket(NodeConnection from, byte[] payload)
        {
            MemoryStream stream = new MemoryStream(payload);
            BinaryReader br     = new BinaryReader(stream);

            uint version = br.ReadUInt32();

            byte[] prevBlock = br.ReadBytes(32);
            byte[] merkle    = br.ReadBytes(32);
            uint   time      = br.ReadUInt32();
            uint   bits      = br.ReadUInt32();
            uint   nonce     = br.ReadUInt32();
            ulong  txn       = Utils.ReadVarInt(br);

            BlockHeader h = new BlockHeader(version, prevBlock, merkle, time, bits, nonce);

            h.ComputeHash(mUseScryptHash);

            Block block = FindBlock(h.mHash);

            if (block == null)
            {
                // Create a new block
                string hash = Utils.ByteArrayToHexString(h.mHash);
                Console.WriteLine("does a new block ever get introduced this way!?? " + hash);
                return;
            }

            block.mTransactions.Clear();
            for (ulong j = 0; j < txn; j++)
            {
                Transaction tx = new Transaction();
                tx.mVersion = br.ReadUInt32();
                if (mTransactionTimeStamp)
                {
                    tx.mTimestamp = br.ReadUInt32();
                }

                ulong inCount = Utils.ReadVarInt(br);
                for (ulong k = 0; k < inCount; k++)
                {
                    TransactionInput ti = new TransactionInput();
                    ti.mPrevOuptutHash  = br.ReadBytes(32);
                    ti.mPrevOutputIndex = br.ReadUInt32();

                    ulong scriptLen = Utils.ReadVarInt(br);
                    ti.mScript = br.ReadBytes((int)scriptLen);

                    ti.mSequence = br.ReadUInt32();

                    tx.mInputs.Add(ti);
                }

                ulong outCount = Utils.ReadVarInt(br);
                for (ulong k = 0; k < outCount; k++)
                {
                    TransactionOutput to = new TransactionOutput();
                    to.mValue     = br.ReadUInt64();
                    to.mRealValue = (double)to.mValue / 1000000.0;

                    ulong scriptLen = Utils.ReadVarInt(br);
                    to.mScript = br.ReadBytes((int)scriptLen);

                    tx.mOutputs.Add(to);
                }
                tx.mLockTime = br.ReadUInt32();
                if (tx.mVersion > 1)
                {
                    ulong commentLen = Utils.ReadVarInt(br);
                    tx.mComment = br.ReadBytes((int)commentLen);
                }

                block.mTransactions.Add(tx);
            }
            br.Close();
        }
예제 #4
0
        public void HandleBlockPacket(NodeConnection from, byte[] payload)
        {
            MemoryStream stream = new MemoryStream(payload);
            BinaryReader br = new BinaryReader(stream);

            uint version = br.ReadUInt32();
            byte[] prevBlock = br.ReadBytes(32);
            byte[] merkle = br.ReadBytes(32);
            uint time = br.ReadUInt32();
            uint bits = br.ReadUInt32();
            uint nonce = br.ReadUInt32();
            ulong txn = Utils.ReadVarInt(br);

            BlockHeader h = new BlockHeader(version, prevBlock, merkle, time, bits, nonce);
            h.ComputeHash(mUseScryptHash);

            Block block = FindBlock(h.mHash);
            if (block == null)
            {
                // Create a new block
                string hash = Utils.ByteArrayToHexString(h.mHash);
                Console.WriteLine("does a new block ever get introduced this way!?? " + hash);
                return;
            }

            block.mTransactions.Clear();
            for (ulong j = 0; j < txn; j++)
            {
                Transaction tx = new Transaction();
                tx.mVersion = br.ReadUInt32();
                if( mTransactionTimeStamp )
                    tx.mTimestamp = br.ReadUInt32();

                ulong inCount = Utils.ReadVarInt(br);
                for (ulong k = 0; k < inCount; k++)
                {
                    TransactionInput ti = new TransactionInput();
                    ti.mPrevOuptutHash = br.ReadBytes(32);
                    ti.mPrevOutputIndex = br.ReadUInt32();

                    ulong scriptLen = Utils.ReadVarInt(br);
                    ti.mScript = br.ReadBytes((int)scriptLen);

                    ti.mSequence = br.ReadUInt32();

                    tx.mInputs.Add(ti);
                }

                ulong outCount = Utils.ReadVarInt(br);
                for (ulong k = 0; k < outCount; k++)
                {
                    TransactionOutput to = new TransactionOutput();
                    to.mValue = br.ReadUInt64();
                    to.mRealValue = (double)to.mValue / 1000000.0;

                    ulong scriptLen = Utils.ReadVarInt(br);
                    to.mScript = br.ReadBytes((int)scriptLen);

                    tx.mOutputs.Add(to);
                }
                tx.mLockTime = br.ReadUInt32();
                if (tx.mVersion > 1)
                {
                    ulong commentLen = Utils.ReadVarInt(br);
                    tx.mComment = br.ReadBytes((int)commentLen);
                }

                block.mTransactions.Add(tx);
            }
            br.Close();
        }