예제 #1
0
        public TransactionOutpoint(TransactionOutpoint outpoint)
        {
            ContractsCommon.NotNull(outpoint, "outpoint");

            _sourceTransactionHash = outpoint._sourceTransactionHash;
            _outputSequenceNumber  = outpoint._outputSequenceNumber;
        }
예제 #2
0
        protected override void Deserialize(System.IO.Stream stream)
        {
            SourceTransactionHash = new Hash256(stream);
            OutputSequenceNumber  = ReadInt32(stream);

            Freeze();
        }
예제 #3
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;
        }
예제 #4
0
 public void BigIntegerConstruction(BigInteger bi)
 {
     var biBytes = new byte[32];
     bi.ToByteArray().CopyTo(biBytes, 0);
     var hash = new Hash256(bi);
     Assert.AreElementsEqual(biBytes, hash.Bytes);
 }
예제 #5
0
        protected void InvalidateBitcoinHashes(object sender, EventArgs e)
        {
            ContractsCommon.NotFrozen(this);

            _hash256 = null;
            _hash160 = null;
            if (HashesInvalidated != null)
            {
                HashesInvalidated(this, EventArgs.Empty);
            }
        }
 /// <summary>A factory for xpdm.Bitcoin.Core.TransactionOutpoint instances</summary>
 public static TransactionOutpoint Create(Hash256 sourceHash, int outpointSequenceNumber, bool freeze)
 {
     TransactionOutpoint transactionOutpoint = new TransactionOutpoint
     {
         SourceTransactionHash = sourceHash,
         OutputSequenceNumber = outpointSequenceNumber,
     };
     if (freeze)
     {
         transactionOutpoint.Freeze();
     }
     return transactionOutpoint;
 }
예제 #7
0
        public static bool TryParse(string hashString, out Hash256 hash)
        {
            Contract.Ensures(Contract.Result <bool>() == true || Contract.ValueAtReturn(out hash) == default(Hash256));
            Contract.Ensures(Contract.Result <bool>() == false || Contract.ValueAtReturn(out hash) != null);

            try
            {
                hash = Parse(hashString);
                return(true);
            }
            catch (ArgumentException) { }
            catch (FormatException) { }
            catch (OverflowException) { }

            hash = default(Hash256);
            return(false);
        }
예제 #8
0
        public static bool TryParse(string hashString, out Hash256 hash)
        {
            Contract.Ensures(Contract.Result<bool>() == true || Contract.ValueAtReturn(out hash) == default(Hash256));
            Contract.Ensures(Contract.Result<bool>() == false || Contract.ValueAtReturn(out hash) != null);

            try
            {
                hash = Parse(hashString);
                return true;
            }
            catch (ArgumentException) { }
            catch (FormatException) { }
            catch (OverflowException) { }

            hash = default(Hash256);
            return false;
        }
예제 #9
0
        protected override void Deserialize(Stream stream)
        {
            Version           = ReadUInt32(stream);
            PreviousBlockHash = new Hash256(stream);
            new Hash256(stream); // Throw away the Merkle Root
            Timestamp      = ReadUInt32(stream);
            DifficultyBits = ReadUInt32(stream);
            Nonce          = ReadUInt32(stream);

            var transactionsArr = ReadVarArray <Transaction>(stream);
            var transactions    = new HashedArrayList <Transaction>(transactionsArr.Length);

            transactions.AddAll(transactionsArr);
            transactions.CollectionChanged += InvalidateMerkleTree;
            Transactions = transactions;

            Freeze();
        }
예제 #10
0
 public static void AssertThatHashMatches(BitcoinObject bitObj, Hash256 expectedHash)
 {
     Assert.AreEqual(expectedHash, bitObj.Hash256);
 }
예제 #11
0
 public void ExpectedHashSize()
 {
     var hash = new Hash256();
     Assert.AreEqual(32, hash.HashByteSize);
     Assert.AreEqual(hash.HashByteSize, hash.SerializedByteSize);
 }
예제 #12
0
 public void ByteArrayContruction(byte[] hashBytes)
 {
     var hash = new Hash256(hashBytes);
     var roundTrip = hash.Bytes;
     Assert.AreElementsEqual(hashBytes, roundTrip);
 }
예제 #13
0
 public void DefaultConstruction()
 {
     var hash = new Hash256();
     Assert.AreEqual(Hash256.Empty, hash);
     Assert.AreElementsEqual(Hash256.Empty.Bytes, hash.Bytes);
 }
예제 #14
0
 public void VerifyTransactionHash(
     Hash256 txHash,
     Transaction tx)
 {
     BitcoinObjectTest.AssertThatHashMatches(tx, txHash);
 }
예제 #15
0
 public static Hash256 Create(byte[] hashBytes)
 {
     Hash256 hash256 = new Hash256(hashBytes);
     return hash256;
 }