code/part-one/mining.js
/**
   * This method takes a private key, and uses it to create a new transaction
   * rewarding the owner of the key. This transaction should be combined with
   * the pending transactions and included in a new block on the chain.
   *
   * Note:
   *   Only certain hashes are valid for blocks now! In order for a block to be
   *   valid it must have a hash that starts with as many zeros as the
   *   the blockchain's difficulty. You'll have to keep trying nonces until you
   *   find one that works!
   *
   * Hint:
   *   Don't forget to clear your pending transactions after you're done.
   */
This method takes a private key, and uses it to create a new transaction
rewarding the owner of the key. This transaction should be combined with
the pending transactions and included in a new block on the chain.

Only certain hashes are valid for blocks now. In order for a block to be
valid it must have a hash that starts with as many zeros as the
the blockchain's difficulty. You'll have to keep trying nonces until you
find one that works!

Don't forget to clear your pending transactions after you're done.
This method takes a private key and uses it to create a new transaction rewarding the owner of the key . This transaction should be combined with the pending transactions and included in a new block on the chain . Only certain hashes are valid for blocks now . In order for a block to be valid it must have a hash that starts with as many zeros as the the blockchain ' s difficulty . You ' ll have to keep trying nonces until you find one that works! Don ' t forget to clear your pending transactions after you ' re done .
mine(privateKey) {
    const rewardTransaction = new MineableTransaction(privateKey, null, this.reward);
    const transactions = this._pendingTransactions.concat(rewardTransaction);
    const newBlock = new MineableBlock(transactions, this.getHeadBlock().hash);
    this._pendingTransactions = [];
    let nonce = 0;
    do {
      newBlock.calculateHash(nonce);
      nonce++;
    } while (!_validHash(newBlock, this.difficulty))
    this.blocks.push(newBlock);
  }
mine ( privateKey ) { const rewardTransaction = new MineableTransaction ( privateKey , null , this . reward ) ; const transactions = this . _pendingTransactions . concat ( rewardTransaction ) ; const newBlock = new MineableBlock ( transactions , this . getHeadBlock ( ) . hash ) ; this . _pendingTransactions = [ ] ; let nonce = 0 ; do { newBlock . calculateHash ( nonce ) ; nonce ++ ; } while ( ! _validHash ( newBlock , this . difficulty ) ) this . blocks . push ( newBlock ) ; }
This method takes a private key, and uses it to create a new transaction
 rewarding the owner of the key.
This method takes a private key and uses it to create a new transaction rewarding the owner of the key .
// fixed set of transactions, trying to snapshot a block (new transactions may be incoming for next block) // valid block hash! add to chain