Exemplo n.º 1
0
        public byte[] CalculateBlockDataHash()
        {
            var blockData = new
            {
                index        = this.Index,
                transactions = this.Transactions.Select(t => new
                {
                    from                = t.From,
                    to                  = t.To,
                    value               = t.Value,
                    fee                 = t.Fee,
                    dateCreated         = t.DateCreated,
                    data                = t.Data,
                    senderPubKey        = t.SenderPubKey,
                    transactionDataHash = t.TransactionDataHash,
                    senderSignature     = t.SenderSignature,
                    minedInBlockIndex   = t.MinedInBlockIndex,
                    transferSuccessful  = t.TransferSuccessful,
                }),
                difficulty    = this.Difficulty,
                prevBlockHash = this.PrevBlockHash,
                minedBy       = this.MinedBy
            };

            var tranDataJSON = JsonConvert.SerializeObject(blockData);

            return(CryptoUtils.CalcSHA256(tranDataJSON));
        }
        public void CalculateDataHash()
        {
            var tranData = new
            {
                from         = this.From,
                to           = this.To,
                value        = this.Value,
                fee          = this.Fee,
                dateCreated  = this.DateCreated, // test if that is null
                data         = this.Data,
                senderPubKey = this.SenderPubKey
            };

            var tranDataJson = JsonConvert.SerializeObject(tranData);

            this.TransactionDataHash = CryptoUtils.CalcSHA256(tranDataJson);
        }
Exemplo n.º 3
0
        public byte[] CalculateBlockHash()
        {
            var data = string.Format("{0}|{1}|{2}", CryptoUtils.BytesToHex(this.BlockDataHash), this.DateCreated, this.Nonce);

            return(CryptoUtils.CalcSHA256(data));
        }