BitShares Forum

Main => Technical Support => Topic started by: Victor118 on March 27, 2018, 03:48:36 pm

Title: Understand the Bitshares-core code
Post by: Victor118 on March 27, 2018, 03:48:36 pm
Hello, I am a Java / Javascript developer.
I would like to understand the code of Bitshares core.
Is there any documentation?
When I look at the code I do not understand, obviously I have to learn C ++ (it's in progress).

I would like to understand where is the code that determines the code to execute according to the type of transaction?

For example:
 what is the called method sequence when a limit order creation transaction is transferred to the blockchain?
What code is executed when a witness add new price feed for a smart asset and the margin call logic ?
...etc
Sorry for my bad English and these noob questions !!
Title: Re: Understand the Bitshares-core code
Post by: xeroc on March 27, 2018, 06:14:51 pm
Look for 'limit_order_create_operation' it has a validator, an evaluator and an apply-er that tells you what is going on.
Title: Re: Understand the Bitshares-core code
Post by: pc on March 27, 2018, 06:21:59 pm
Good questions.

You might want to start looking at database::_apply_transaction (in db_block.cpp). Like all core code, this is in the libraries/chain module.
A few levels deeper you will see that for every blockchain operation there is an evaluator. Evaluators are grouped together in files, e. g. market_evaluator.cpp contains all evaluators for market-related operations.

It's a bit difficult to follow the execution paths. because some of the logic is hidden in static_variant objects that use the visitor pattern to find the relevant code for the specific object inside the static_variant. I'd suggest to skip over the static_variant stuff when reading the code, it's a bit tricky to understand.

Being a C programmer turned Java programmer turned C++ programmer myself, I'd like to warn you about a few traps. C++ reads almost like Java, but there are a few significant differences:

* Destructors are important in C++
* By default, methods are called by-value, not by-reference.
* Method lookup works differently in C++, in particular wrt overloaded methods.