Exemplo n.º 1
0
        public PartialBlock FromBytes(byte[] b)
        {
            byte[][] pieces = Help.Separate(b, membSep);

            Height = BitConverter.ToInt32(pieces[0], 0);

            MerkleProof.FromBytes(pieces[1]);

            if (pieces[2].Length != 0)
            {
                foreach (byte[] tx in Help.Separate(pieces[2], txSep))
                {
                    Transactions.Add(new Transaction(tx));
                }
            }

            return(this);
        }
Exemplo n.º 2
0
        public byte[] ToBytes()
        {
            var merkleProof = MerkleProof.ToBytes();

            byte[] transactions = null;
            if (Transactions.Count > 0)
            {
                transactions = Transactions.First().ToBytes();
                foreach (var tx in Transactions.Skip(1))
                {
                    transactions = transactions.Concat(txSep).Concat(tx.ToBytes()).ToArray();
                }
            }
            var ret = BitConverter.GetBytes(Height).Concat(membSep).Concat(merkleProof).Concat(membSep).ToArray();

            if (transactions == null)
            {
                return(ret);
            }
            else
            {
                return(ret.Concat(transactions).ToArray());
            }
        }
Exemplo n.º 3
0
 public static byte[] Hash(object obj)
 {
     return(MerkleProof.MerkleHashSummary(obj, new MerkleHashCalculator(new CryptoSystem())).MerkleHash);
 }