conradoqg / naivecoin

A cryptocurrency implementation in less than 1500 lines of code
Apache License 2.0
1.22k stars 319 forks source link

Coin limitation? #29

Closed neurofluxation closed 6 years ago

neurofluxation commented 6 years ago

Hey there,

Love the code, just wondered whether they was a way to implement a maximum coin total? So a hardcoded total number of coins that are available before the mining has to stop?

demenvil commented 6 years ago

you can count the number of blocks to have the number of pieces and in the config file to fix the maximum of coins to generate. then if max == number of pieces (counted) then reward == 0 finally something in the genre

neurofluxation commented 6 years ago

@demenvil. Awesome, thanks. Final question (promise), where would I go about saving additional data into the blockchain (such as a JSON stringified object)?

conradoqg commented 6 years ago

I think you will only need to add a new property to the transaction model.

neurofluxation commented 6 years ago

hmm, I think I understand - so say, the client "wallet" updated some data client-side and wanted to send it back over to the block chain - how would I retrieve the data from the client in the node server to save? Would I have to create a transaction?

Perhaps I'm misunderstanding though :)

Thanks for the quick response!

neurofluxation commented 6 years ago

So... New data -> JSON'd -> Sent to Node -> Save in block chain transaction

Is that correct? I'm not sure how to send to (and pick up data from) the node server though :(

conradoqg commented 6 years ago

First, you will need to study the source-code and add a field to the transaction model that will receive a JSON/Object data. So after implementing this, the idea is that through a transaction you can store some data in the blockchain. Then, to retrieve this data, you need to get the transaction inside the blockchain.

Was I able to explain?

Best

neurofluxation commented 6 years ago

@conradoqg - Yeah that makes sense :) I figured it out - Thank you!