node-blockchain icon indicating copy to clipboard operation
node-blockchain copied to clipboard

A confused point about function "mine"

Open jie170601 opened this issue 4 years ago • 0 comments

It's a good project for me who want to learn the block chain.But there's a confused point that I can't figure out,the function "mine" seems no meanings when we use the addBlock.It does not reflect the relationship between mining and block.Then I think the return value of "mine" should be nonce+solution,and assign the return value to the nonce of block.


mine(nonce: number) {
    ...
    return nonce+solution;
    ...
 }

addBlock(transaction: Transaction, senderPublicKey: string, signature: Buffer) {
    ...
    if (isValid) {
      const newBlock = new Block(this.lastBlock.hash, transaction);
      newBlock.nonce = this.mine(newBlock.nonce);
      this.chain.push(newBlock);
    }
    ....
}


jie170601 avatar Aug 07 '21 01:08 jie170601