public BitReader(byte[] data, int bitCount) { var writer = new BitWriter(); writer.Write(data, bitCount); this.array = writer.ToBitArray(); }
// serialization implementation #region IBitcoinSerializable Members public void ReadWrite(BitcoinStream stream) { stream.ReadWrite(ref this._TransactionCount); stream.ReadWrite(ref this._Hashes); byte[] vBytes = null; if (!stream.Serializing) { stream.ReadWriteAsVarString(ref vBytes); var writer = new BitWriter(); for (int p = 0; p < vBytes.Length * 8; p++) { writer.Write((vBytes[p / 8] & (1 << (p % 8))) != 0); } this._Flags = writer.ToBitArray(); } else { vBytes = new byte[(this._Flags.Length + 7) / 8]; for (int p = 0; p < this._Flags.Length; p++) { vBytes[p / 8] |= (byte)(ToByte(this._Flags.Get(p)) << (p % 8)); } stream.ReadWriteAsVarString(ref vBytes); } }
public PartialMerkleTree(uint256[] vTxid, bool[] vMatch) { if (vMatch.Length != vTxid.Length) { throw new ArgumentException("The size of the array of txid and matches is different"); } this.TransactionCount = (uint)vTxid.Length; MerkleNode root = MerkleNode.GetRoot(vTxid); var flags = new BitWriter(); MarkNodes(root, vMatch); BuildCore(root, flags); this.Flags = flags.ToBitArray(); }
/// <summary> /// Remove superflous branches /// </summary> /// <param name="transaction"></param> /// <returns></returns> public PartialMerkleTree Trim(params uint256[] matchedTransactions) { var trimmed = new PartialMerkleTree(); trimmed.TransactionCount = this.TransactionCount; MerkleNode root = GetMerkleRoot(); foreach (MerkleNode leaf in root.GetLeafs()) { MarkToTop(leaf, false); } var flags = new BitWriter(); foreach (MerkleNode leaf in root.GetLeafs().Where(l => matchedTransactions.Contains(l.Hash))) { MarkToTop(leaf, true); } trimmed.BuildCore(root, flags); trimmed.Flags = flags.ToBitArray(); return(trimmed); }
// serialization implementation #region IBitcoinSerializable Members public void ReadWrite(BitcoinStream stream) { stream.ReadWrite(ref _TransactionCount); stream.ReadWrite(ref _Hashes); byte[] vBytes = null; if(!stream.Serializing) { stream.ReadWriteAsVarString(ref vBytes); BitWriter writer = new BitWriter(); for(int p = 0 ; p < vBytes.Length * 8 ; p++) writer.Write((vBytes[p / 8] & (1 << (p % 8))) != 0); _Flags = writer.ToBitArray(); } else { vBytes = new byte[(_Flags.Length + 7) / 8]; for(int p = 0 ; p < _Flags.Length ; p++) vBytes[p / 8] |= (byte)(ToByte(_Flags.Get(p)) << (p % 8)); stream.ReadWriteAsVarString(ref vBytes); } }
public BitReader(byte[] data, int bitCount) { BitWriter writer = new BitWriter(); writer.Write(data, bitCount); array = writer.ToBitArray(); }
public PartialMerkleTree(uint256[] vTxid, bool[] vMatch) { if(vMatch.Length != vTxid.Length) throw new ArgumentException("The size of the array of txid and matches is different"); TransactionCount = (uint)vTxid.Length; MerkleNode root = MerkleNode.GetRoot(vTxid); BitWriter flags = new BitWriter(); MarkNodes(root, vMatch); BuildCore(root, flags); Flags = flags.ToBitArray(); }
/// <summary> /// Remove superflous branches /// </summary> /// <param name="transaction"></param> /// <returns></returns> public PartialMerkleTree Trim(params uint256[] matchedTransactions) { PartialMerkleTree trimmed = new PartialMerkleTree(); trimmed.TransactionCount = TransactionCount; var root = GetMerkleRoot(); foreach(var leaf in root.GetLeafs()) { MarkToTop(leaf, false); } BitWriter flags = new BitWriter(); foreach(var leaf in root.GetLeafs().Where(l => matchedTransactions.Contains(l.Hash))) { MarkToTop(leaf, true); } trimmed.BuildCore(root, flags); trimmed.Flags = flags.ToBitArray(); return trimmed; }