Ejemplo n.º 1
0
        //1.生成一个新区块
        /// <summary>
        /// 生成一个新区块
        /// </summary>
        /// <param name="data">交易数据</param>
        /// <param name="height">区块的高度</param>
        /// <param name="prevBlockHash">上一个区块的hash</param>
        /// <returns></returns>
        public Block(Transaction[] data, long height, byte[] prevBlockHash)
        {
            //创建区块
            Height        = height;
            PrevBlockHash = prevBlockHash;
            Txs           = data;
            Timestamp     = Utils.GetTimeStamp();
            Nonce         = 0;
            // 调用工作量证明的方法并且返回有效的Hash和Nonce
            var pow = new ProofOfWork(this);

            var(hash, nonce) = pow.Run();

            this.Hash  = hash;
            this.Nonce = nonce;
        }
Ejemplo n.º 2
0
        //1.生成一个新区块
        /// <summary>
        /// 生成一个新区块
        /// </summary>
        /// <param name="data">交易数据</param>
        /// <param name="height">区块的高度</param>
        /// <param name="prevBlockHash">上一个区块的hash</param>
        /// <returns></returns>
        public Block(string data, long height, byte[] prevBlockHash)
        {
            //创建区块
            Height        = height;
            PrevBlockHash = prevBlockHash;
            Data          = Encoding.Default.GetBytes(data);
            Timestamp     = Utils.GetTimeStamp();
            Nonce         = 0;
            // 调用工作量证明的方法并且返回有效的Hash和Nonce
            var pow = new ProofOfWork(this);

            var(hash, nonce) = pow.Run();

            this.Hash  = hash;
            this.Nonce = nonce;
        }