Esempio n. 1
0
 private Block()
 {
     this.index        = 1;
     this.timestamp    = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
     this.proof        = new ProofOfWork(1);
     this.previousHash = Sha256Hash.Of("Genesis");
     this.transactions = new List <Transaction>();
 }
Esempio n. 2
0
        public virtual bool Verify(ProofOfWork lastProof)
        {
            if (lastProof == null)
            {
                throw new InvalidOperationException("Last proof must not be null");
            }

            return(Sha256Hash
                   .Of($"{lastProof.Value}{Value}")
                   .StartsWith("0000"));
        }
Esempio n. 3
0
        public Sha256Hash Hash()
        {
            var properties = new {
                Index,
                Timestamp,
                Proof,
                PreviousHash,
                Transactions
            };

            return(Sha256Hash.Of(properties.AsJson()));
        }
Esempio n. 4
0
 public bool IsGenesisBlock()
 {
     return(Index == 1 &&
            PreviousHash == Sha256Hash.Of("Genesis") &&
            Proof == new ProofOfWork(1));
 }