From the course: Blockchain Programming in iOS Using Swift

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Adding blocks to the blockchain

Adding blocks to the blockchain

- [Instructor] Hello and welcome back. In our excitement for the last lecture, we totally forgot to add the block to the blockchain. So if I go ahead and print out the block, so lets say, blockchain.numberofblocks.count, you will see that instead of showing us two blocks, it's going to tell us that there's only one block in the blockchain. Which is obviously the genesis block, which is necessary for the blockchain to be initialize. We'll see that the block that we received, or mined, is not in the blockchain, because the getNextBlock function never really adds the block to the blockchain. You will see that it simply creates a block, and it returns you the block without adding it to the blockchain. So what we have to do is finally call the blockchain.add function, so addBlock, passing in the block. Now the addBlock function, in this case, is a private function, so let's go over here and make it non-private, so that we can call it, and that's pretty much it! That one line of code, and…

Contents