Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: 108abhishek on January 07, 2018, 05:57:10 PM



Title: Reading Bitcoin code
Post by: 108abhishek on January 07, 2018, 05:57:10 PM
I have started reading bitcoin code, I know it's too late. But does not matter for me, I want to learn.
I have basic knowlege of c++.
My main question is what is the flow ? like it start from wallet code or some other file.

The code is so huge, I am lost. I can't figure it out from where the application is started.
Can any one help me?
Just like if I wanted to develop from scratch, then which part or function should I develop first and then slowly others.


Thank you!!


Title: Re: Reading Bitcoin code
Post by: DannyHamilton on January 07, 2018, 07:10:28 PM
This is probably a good place to start:
https://github.com/bitcoin/bitcoin/blob/master/src/bitcoind.cpp#L188

Code:
int main(int argc, char* argv[])


Title: Re: Reading Bitcoin code
Post by: boogersguy on January 08, 2018, 08:21:44 PM
This is probably a good place to start:
https://github.com/bitcoin/bitcoin/blob/master/src/bitcoind.cpp#L188

Code:
int main(int argc, char* argv[])

Lol.  I couldn't help laugh  a little . 

You can also jump to AppInitMain() in the "init.cpp" file. Here are some notes I took once when walking through the code:

Code:
AppInitMain()  		// init.cpp
 - Creates the service queue thread (CScheduler::serviceQueue()) which runs "forever" until interrupted and adds it
   to the "threadGroup" (a boost::thread_group which was created in AppInit() in bitcoind.cpp)
   - Inside serviceQueue(), it's a big while-loop, which essentially dequeues and calls the next task in the queue:
         Function f = taskQueue.begin()->second;  // "second" is like the 2nd thing in a tuple, which is a function call.
         // .. other stuff
         f();  // call the actual function