Ejemplo n.º 1
0
        public TransactionInput ThawTree()
        {
            ContractsCommon.IsThawed(Contract.Result <TransactionInput>().Source);
            ContractsCommon.IsThawed(Contract.Result <TransactionInput>().Script);

            return(new TransactionInput(this, true));
        }
Ejemplo n.º 2
0
        public Transaction ThawTree()
        {
            ContractsCommon.IsThawed(Contract.Result <Transaction>().TransactionInputs);
            ContractsCommon.IsThawed(Contract.Result <Transaction>().TransactionOutputs);

            return(new Transaction(this, true));
        }
        protected static short ReadInt16(Stream stream)
        {
            ContractsCommon.NotNull(stream, "stream");
            int value = stream.ReadByte() | (stream.ReadByte() << 8);

            return((short)value);
        }
Ejemplo n.º 4
0
            public Hash160 Ripemd160(byte[] buffer)
            {
                ContractsCommon.NotNull(buffer, "buffer");
                ContractsCommon.ResultIsNonNull <Hash160>();

                return(default(Hash160));
            }
Ejemplo n.º 5
0
        protected Hash(byte[] hash)
        {
            ContractsCommon.NotNull(hash, "hash");
            Contract.Assert(hash.Length == HashByteSize);

            _bytes = (byte[])hash.Clone();
        }
Ejemplo n.º 6
0
            public Hash256 Hash256(byte[] buffer)
            {
                ContractsCommon.NotNull(buffer, "buffer");
                ContractsCommon.ResultIsNonNull <Hash256>();

                return(default(Hash256));
            }
 protected sealed override void Deserialize(Stream stream)
 {
     ContractsCommon.NotFrozen(this);
     ContractsCommon.NotNull(stream, "stream");
     //Contract.Requires<ArgumentOutOfRangeException>(length <= stream.Length, "length");
     //Contract.Requires<ArgumentOutOfRangeException>(stream.Position + length <= stream.Length, "length");
 }
        public static void Serialize(Stream stream, BitcoinSerializable obj)
        {
            ContractsCommon.NotNull(stream, "stream");
            ContractsCommon.NotNull(obj, "obj");

            obj.Serialize(stream);
        }
Ejemplo n.º 9
0
        public TransactionOutpoint(TransactionOutpoint outpoint)
        {
            ContractsCommon.NotNull(outpoint, "outpoint");

            _sourceTransactionHash = outpoint._sourceTransactionHash;
            _outputSequenceNumber  = outpoint._outputSequenceNumber;
        }
Ejemplo n.º 10
0
 protected static void WriteBytes(Stream stream, byte[] buffer, int offset, int length)
 {
     ContractsCommon.CanWriteToStream(stream, BufferOperations.UINT8_SIZE * length);
     ContractsCommon.NotNull(buffer, "buffer");
     ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, length);
     stream.Write(buffer, offset, length);
 }
Ejemplo n.º 11
0
        public Block(Block block, bool thawChildren)
        {
            ContractsCommon.NotNull(block, "block");
            Contract.Ensures(this.Version == block.Version);
            Contract.Ensures(this.PreviousBlockHash == block.PreviousBlockHash);
            Contract.Ensures(this.Timestamp == block.Timestamp);
            Contract.Ensures(this.DifficultyBits == block.DifficultyBits);
            Contract.Ensures(this.Nonce == block.Nonce);
            Contract.Ensures(this.Transactions.SequencedEquals(block.Transactions));
            Contract.Ensures(this.MerkleRoot == block.MerkleRoot);
            ContractsCommon.ChildrenThawed(Transactions, thawChildren);

            this._version           = block._version;
            this._previousBlockHash = block._previousBlockHash;
            this._timestamp         = block._timestamp;
            this._difficultyBits    = block._difficultyBits;
            this._nonce             = block._nonce;
            if (block._merkleTree != null)
            {
                var tree = new ArrayList <Hash256>(block._merkleTree.Count);
                tree.AddAll(block._merkleTree);
                this._merkleTree = new GuardedList <Hash256>(tree);
            }

            var transactions = new HashedArrayList <Transaction>(block.Transactions.Count);

            transactions.AddAll(FreezableExtensions.ThawChildren(block.Transactions, thawChildren));
            transactions.CollectionChanged += InvalidateMerkleTree;
            this.Transactions = transactions;
        }
Ejemplo n.º 12
0
        private void InvalidateMerkleTree(object sender)
        {
            ContractsCommon.NotFrozen(this);

            _merkleTree = null;
            InvalidateBitcoinHashes();
        }
Ejemplo n.º 13
0
            public bool VerifyHash(byte[] hash, byte[] signature)
            {
                ContractsCommon.NotNull(hash, "hash");
                ContractsCommon.NotNull(signature, "signature");

                return(default(bool));
            }
Ejemplo n.º 14
0
        protected static void Write(Stream stream, short value)
        {
            ContractsCommon.CanWriteToStream(stream, BufferOperations.UINT16_SIZE);
            var bytes = BitConverter.GetBytes(value);

            stream.Write(bytes, 0, bytes.Length);
        }
Ejemplo n.º 15
0
        public static T Peek <T>(this IStack <T> stack, int depth)
        {
            ContractsCommon.NotNull(stack, "stack");
            ContractsCommon.ValidOffset(0, stack.Count, depth, "depth");

            return(stack[stack.Count - depth - 1]);
        }
Ejemplo n.º 16
0
            public int ResultCount(ExecutionContext context)
            {
                ContractsCommon.NotNull(context, "context");
                Contract.Ensures(Contract.Result <int>() >= 0);

                return(default(int));
            }
Ejemplo n.º 17
0
            public byte[] RetreivePrivateKey()
            {
                Contract.Requires(HasPrivateKey);
                ContractsCommon.ResultIsNonNull <byte[]>();

                return(default(byte[]));
            }
Ejemplo n.º 18
0
        public static IList <Hash256> CalculateMerkleTree(SCG.IEnumerable <Transaction> transactions)
        {
            ContractsCommon.NotNull(transactions, "transactions");
            Contract.Requires(Contract.ForAll(transactions, tx => tx != null));
            ContractsCommon.ResultIsNonNull <IList <Hash256> >();

            var tree = new ArrayList <Hash256>();

            foreach (var trans in transactions)
            {
                tree.Add(trans.Hash256);
            }
            int j = 0;

            for (int size = tree.Count; size > 1; size = (size + 1) / 2)
            {
                for (int i = 0; i < size; i += 2)
                {
                    int i2 = Math.Min(i + 1, size - 1);
                    tree.Add(CryptoFunctionProviderFactory.Default.Hash256(tree[j + i].Bytes, tree[j + i2].Bytes));
                }
                j += size;
            }
            return(new GuardedList <Hash256>(tree));
        }
Ejemplo n.º 19
0
        public TransactionOutput(TransactionOutput txOut, bool thawChildren)
        {
            ContractsCommon.NotNull(txOut, "txOut");
            ContractsCommon.ChildThawed(Script, thawChildren);

            _value  = txOut._value;
            _script = FreezableExtensions.ThawChild(txOut._script, thawChildren);
        }
Ejemplo n.º 20
0
            public T ThawTree()
            {
                ContractsCommon.ResultIsNonNull <T>();
                ContractsCommon.IsThawed(Contract.Result <T>());
                Contract.Ensures(IsFrozen == Contract.OldValue(IsFrozen));

                return(default(T));
            }
Ejemplo n.º 21
0
            public byte[] SignHash(byte[] hash)
            {
                Contract.Requires(HasPrivateKey);
                ContractsCommon.NotNull(hash, "hash");
                ContractsCommon.ResultIsNonNull <byte[]>();

                return(default(byte[]));
            }
Ejemplo n.º 22
0
            public Hash160 Sha1(byte[] buffer, int offset, int length)
            {
                ContractsCommon.NotNull(buffer, "buffer");
                ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, length);
                ContractsCommon.ResultIsNonNull <Hash160>();

                return(default(Hash160));
            }
Ejemplo n.º 23
0
        public ECDsaBouncyCastle(byte[] encodedPublicKey)
        {
            ContractsCommon.NotNull(encodedPublicKey, "encodedPublicKey");

            var secp256k1 = SecP256k1;

            _publicKey = new ECPublicKeyParameters(secp256k1.Curve.DecodePoint(encodedPublicKey), secp256k1);
        }
Ejemplo n.º 24
0
        protected BitcoinSerializable(Stream stream)
        {
            ContractsCommon.NotNull(stream, "stream");
            //Contract.Requires<ArgumentOutOfRangeException>(length <= stream.Length, "length");
            //Contract.Requires<ArgumentOutOfRangeException>(stream.Position + length <= stream.Length, "length");

            this.Deserialize(stream);
        }
Ejemplo n.º 25
0
        public Script Subscript(int offset, int length)
        {
            ContractsCommon.ValidOffsetLength(0, Atoms.Count, offset, length);

            var script = new Script();

            script.Atoms.AddAll(this.Atoms.Skip(offset).Take(length));
            return(script);
        }
Ejemplo n.º 26
0
        public byte this[int index]
        {
            get
            {
                ContractsCommon.ValidIndex(0, _bytes.Length, index);

                return(_bytes[index]);
            }
        }
Ejemplo n.º 27
0
        public static BitcoinSerializable DeserializeFromStream <T>(Stream stream) where T : BitcoinSerializable, new()
        {
            ContractsCommon.NotNull(stream, "stream");

            var ooze = new T();

            ooze.Deserialize(stream);
            return(ooze);
        }
Ejemplo n.º 28
0
        protected override byte[] BuildBitcoinHashByteArray()
        {
            ContractsCommon.ResultIsNonNull <byte[]>();

            var ms = new MemoryStream();

            this.SerializeHeader(ms);
            return(ms.ToArray());
        }
Ejemplo n.º 29
0
        public void SerializeToBuffer(byte[] buffer, int offset)
        {
            ContractsCommon.NotNull(buffer, "buffer");
            ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, this.SerializedByteSize, "offset", "offset");

            var stream = new MemoryStream(buffer, offset, buffer.Length - offset);

            this.Serialize(stream);
        }
Ejemplo n.º 30
0
        public Script Subscript(int offset)
        {
            ContractsCommon.ValidOffset(0, Atoms.Count, offset);

            var script = new Script();

            script.Atoms.AddAll(this.Atoms.Skip(offset));
            return(script);
        }