public TransactionOutpoint(TransactionOutpoint outpoint) { ContractsCommon.NotNull(outpoint, "outpoint"); _sourceTransactionHash = outpoint._sourceTransactionHash; _outputSequenceNumber = outpoint._outputSequenceNumber; }
protected override void Deserialize(System.IO.Stream stream) { SourceTransactionHash = new Hash256(stream); OutputSequenceNumber = ReadInt32(stream); Freeze(); }
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; }
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); }
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; }
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); }
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; }
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(); }
public static void AssertThatHashMatches(BitcoinObject bitObj, Hash256 expectedHash) { Assert.AreEqual(expectedHash, bitObj.Hash256); }
public void ExpectedHashSize() { var hash = new Hash256(); Assert.AreEqual(32, hash.HashByteSize); Assert.AreEqual(hash.HashByteSize, hash.SerializedByteSize); }
public void ByteArrayContruction(byte[] hashBytes) { var hash = new Hash256(hashBytes); var roundTrip = hash.Bytes; Assert.AreElementsEqual(hashBytes, roundTrip); }
public void DefaultConstruction() { var hash = new Hash256(); Assert.AreEqual(Hash256.Empty, hash); Assert.AreElementsEqual(Hash256.Empty.Bytes, hash.Bytes); }
public void VerifyTransactionHash( Hash256 txHash, Transaction tx) { BitcoinObjectTest.AssertThatHashMatches(tx, txHash); }
public static Hash256 Create(byte[] hashBytes) { Hash256 hash256 = new Hash256(hashBytes); return hash256; }