Skip to content

Commit

Permalink
update bp count update proposal commit 2
Browse files Browse the repository at this point in the history
  • Loading branch information
yehuan authored and yehuan committed Feb 23, 2020
2 parents 014e0c8 + e831369 commit c09b095
Show file tree
Hide file tree
Showing 34 changed files with 817 additions and 417 deletions.
76 changes: 0 additions & 76 deletions docs/coding.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,3 @@
Coding
====================

## General Naming Convention

|Type|Naming Convention| Examples |
|--|--|--|
|functions| Pascal case | ```GetAccountBalance```, ```OperateBalance``` |
|global variables| All small cases, starting with ```g_```.| ```g_cs_main```|
|local variables| Camel case | ```freeAmount```, ```delegateVotes```|
|classes| Pascal case, starting with ```C``` |```CCDPStakeTx``` |
delegate|class fields| All small case, using ```_``` to connect words| ```tx_uid```, ```free_amount``` |
|constants| All capital letters, using ```_``` to connect words| ```ASSET_RISK_FEE_RATIO```|


## Container Type Naming Postfix/Prefix
|Category |Type | Examples|
|--|--|--|
| Container| Array | variables |
| Container| List | variables |
| Container| Vector | variables |
| Container| Map | variableMap |
| Container| Set | variableSet |
| pointer | |pVariable |
| shared pointer | |spVariable |

## Code Structure
- Commons
- Tx
- Persistence
- Smart Contract Engine

## Coding Style

- Please be consistent with the existing coding style.

Block style:

bool Function(char* psz, int n)
{
// Comment summarising what this section of code does
for (int i = 0; i < n; i++)
{
// When something fails, return early
if (!Something())
return false;
...
}

// Success return is usually at the end
return true;
}

- ANSI/Allman block style
- 4 space indenting, no tabs
- No extra spaces inside parenthesis; please don't do ( this )
- No space after function names, one space after if, for and while

Variable names begin with the type in lowercase, like nSomeVariable.
Please don't put the first word of the variable name in lowercase like
someVariable.

Common types:

n integer number: short, unsigned short, int, unsigned int, int64, uint64, sometimes char if used as a number
d double, float
f flag
hash uint256
p pointer or array, one p for each level of indirection
psz pointer to null terminated string
str string object
v vector or similar list objects
map map or multimap
set set or multiset
bn CBigNum

Doxygen comments
-----------------

Expand Down
1 change: 1 addition & 0 deletions src/commons/leb128.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class CFixedLeb128 {

bool IsEmpty() const { return value == 0; }
void SetEmpty() { value = 0; }
string ToString() const { return std::to_string(value); }

bool operator==(I i) { return value == i; }
bool operator<(I i) { return value < i; }
Expand Down
2 changes: 2 additions & 0 deletions src/commons/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ class CVarIntValue {

void SetEmpty() { n = 0; }
friend bool operator<(const CVarIntValue& c1 ,const CVarIntValue& c2) { return c1.n < c2.n; }

string ToString() const { return std::to_string(n); }
};

template<typename I>
Expand Down
13 changes: 13 additions & 0 deletions src/entities/asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ class CBaseAsset {
return nullptr;
}

string ToString() const {
return strprintf("symbol=%s", symbol) + ", " +
strprintf("owner_uid=%s", owner_uid.ToString()) + ", " +
strprintf("name=%s", name) + ", " +
strprintf("total_supply=%llu", total_supply) + ", " +
strprintf("mintable=%d", mintable);
}
};

class CAsset: public CBaseAsset {
Expand Down Expand Up @@ -195,6 +202,12 @@ class CAsset: public CBaseAsset {
max_order_amount = 0;
min_order_amount = 0;
}

string ToString() const {
return CBaseAsset::ToString()+ ", " +
strprintf("min_order_amount=%llu", min_order_amount) + ", " +
strprintf("min_order_amount=%llu", min_order_amount);
}
};

bool CheckCoinRange(const TokenSymbol &symbol, const int64_t amount);
Expand Down
6 changes: 6 additions & 0 deletions src/entities/cdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ class CCdpGlobalData {
total_owed_scoins = 0;
}

string ToString() const {
return strprintf("total_staked_assets=%llu", total_staked_assets) + ", " +
strprintf("total_owed_scoins=%llu", total_owed_scoins);

}

uint64_t GetCollateralRatio(const uint64_t assetPrice) const {
// If total owed scoins equal to zero, the global collateral ratio becomes infinite.
if (total_owed_scoins == 0) {
Expand Down
9 changes: 9 additions & 0 deletions src/entities/contract.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "commons/serialize.h"
#include "config/version.h"
#include "commons/util/util.h"

#include <string>

Expand Down Expand Up @@ -118,6 +119,14 @@ class CUniversalContract {
)

bool IsValid();

string ToString() const {
return strprintf("vm_type=%d", vm_type) + ", " +
strprintf("upgradable=%d", upgradable) + ", " +
strprintf("code=%s", code) + ", " +
strprintf("memo=%s", memo) + ", " +
strprintf("abi=%d", abi);
}
};

#endif // ENTITIES_CONTRACT_H
11 changes: 11 additions & 0 deletions src/entities/dexorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ struct DexOperatorDetail {
owner_regid.SetEmpty(); fee_receiver_regid.SetEmpty(); name = ""; portal_url = ""; maker_fee_ratio = 0;
taker_fee_ratio = 0; memo = "";
}

string ToString() const {
return strprintf("owner_regid=%s", owner_regid.ToString()) + ", " +
strprintf("fee_receiver_regid=%s", fee_receiver_regid.ToString()) + ", " +
strprintf("name=%s", name) + ", " +
strprintf("portal_url=%s", portal_url) + ", " +
strprintf("maker_fee_ratio=%llu", maker_fee_ratio) + ", " +
strprintf("taker_fee_ratio=%llu", taker_fee_ratio) + ", " +
strprintf("memo=%s", memo) + ", " +
strprintf("activated=%d", activated);
}
};

#endif //ENTITIES_DEX_ORDER_H
1 change: 1 addition & 0 deletions src/entities/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class CRegIDKey {

inline bool IsEmpty() const { return regid.IsEmpty(); }
void SetEmpty() { regid.SetEmpty(); }
string ToString() const { return regid.ToString(); }


bool operator==(const CRegIDKey &other) const { return this->regid == other.regid; }
Expand Down
8 changes: 8 additions & 0 deletions src/entities/receipt.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class CReceipt {
READWRITE(VARINT(coin_amount));
READWRITE_CONVERT(uint16_t, code);
)

string ToString() const {
return strprintf("from_uid=%s", from_uid.ToString()) + ", " +
strprintf("to_uid=%s", to_uid.ToString()) + ", " +
strprintf("coin_symbol=%s", coin_symbol) + ", " +
strprintf("coin_amount=%llu", coin_amount) + ", " +
strprintf("code=%s", GetReceiptCodeName(code));
}
};

#endif // ENTITIES_RECEIPT_H
Loading

0 comments on commit c09b095

Please sign in to comment.