Skip to content

Commit

Permalink
Enable clang-format on existing code (#1593)
Browse files Browse the repository at this point in the history
* Add clang format 14

* Fix log lints to be more friendly to auto format

* Run clang-format-14 on src/masternodes

* masternodes.h: Add exception block

* Config update: AccessModifierOffset

* Update format
  • Loading branch information
prasannavl authored Nov 24, 2022
1 parent 32003b8 commit 25ab35d
Show file tree
Hide file tree
Showing 63 changed files with 6,599 additions and 5,953 deletions.
225 changes: 225 additions & 0 deletions src/masternodes/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
---
Language: Cpp
# BasedOnStyle: Chromium
# With changes on
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Left
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: Never
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...
73 changes: 31 additions & 42 deletions src/masternodes/accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

#include <masternodes/accounts.h>

void CAccountsView::ForEachBalance(std::function<bool(CScript const &, CTokenAmount const &)> callback, BalanceKey const & start)
{
ForEach<ByBalanceKey, BalanceKey, CAmount>([&callback] (BalanceKey const & key, CAmount val) {
return callback(key.owner, CTokenAmount{key.tokenID, val});
}, start);
void CAccountsView::ForEachBalance(std::function<bool(const CScript &, const CTokenAmount &)> callback,
const BalanceKey &start) {
ForEach<ByBalanceKey, BalanceKey, CAmount>(
[&callback](const BalanceKey &key, CAmount val) {
return callback(key.owner, CTokenAmount{key.tokenID, val});
},
start);
}

CTokenAmount CAccountsView::GetBalance(CScript const & owner, DCT_ID tokenID) const
{
CTokenAmount CAccountsView::GetBalance(const CScript &owner, DCT_ID tokenID) const {
CAmount val;
bool ok = ReadBy<ByBalanceKey>(BalanceKey{owner, tokenID}, val);
if (ok) {
Expand All @@ -21,8 +22,7 @@ CTokenAmount CAccountsView::GetBalance(CScript const & owner, DCT_ID tokenID) co
return CTokenAmount{tokenID, 0};
}

Res CAccountsView::SetBalance(CScript const & owner, CTokenAmount amount)
{
Res CAccountsView::SetBalance(const CScript &owner, CTokenAmount amount) {
if (amount.nValue != 0) {
WriteBy<ByBalanceKey>(BalanceKey{owner, amount.nTokenId}, amount.nValue);
} else {
Expand All @@ -31,35 +31,32 @@ Res CAccountsView::SetBalance(CScript const & owner, CTokenAmount amount)
return Res::Ok();
}

Res CAccountsView::AddBalance(CScript const & owner, CTokenAmount amount)
{
Res CAccountsView::AddBalance(const CScript &owner, CTokenAmount amount) {
if (amount.nValue == 0) {
return Res::Ok();
}
auto balance = GetBalance(owner, amount.nTokenId);
auto res = balance.Add(amount.nValue);
auto res = balance.Add(amount.nValue);
if (!res.ok) {
return res;
}
return SetBalance(owner, balance);
}

Res CAccountsView::SubBalance(CScript const & owner, CTokenAmount amount)
{
Res CAccountsView::SubBalance(const CScript &owner, CTokenAmount amount) {
if (amount.nValue == 0) {
return Res::Ok();
}
auto balance = GetBalance(owner, amount.nTokenId);
auto res = balance.Sub(amount.nValue);
auto res = balance.Sub(amount.nValue);
if (!res.ok) {
return res;
}
return SetBalance(owner, balance);
}

Res CAccountsView::AddBalances(CScript const & owner, CBalances const & balances)
{
for (const auto& kv : balances.balances) {
Res CAccountsView::AddBalances(const CScript &owner, const CBalances &balances) {
for (const auto &kv : balances.balances) {
auto res = AddBalance(owner, CTokenAmount{kv.first, kv.second});
if (!res.ok) {
return res;
Expand All @@ -68,9 +65,8 @@ Res CAccountsView::AddBalances(CScript const & owner, CBalances const & balances
return Res::Ok();
}

Res CAccountsView::SubBalances(CScript const & owner, CBalances const & balances)
{
for (const auto& kv : balances.balances) {
Res CAccountsView::SubBalances(const CScript &owner, const CBalances &balances) {
for (const auto &kv : balances.balances) {
auto res = SubBalance(owner, CTokenAmount{kv.first, kv.second});
if (!res.ok) {
return res;
Expand All @@ -79,65 +75,58 @@ Res CAccountsView::SubBalances(CScript const & owner, CBalances const & balances
return Res::Ok();
}

void CAccountsView::ForEachAccount(std::function<bool(CScript const &)> callback, CScript const & start)
{
ForEach<ByHeightKey, CScript, uint32_t>([&callback] (CScript const & owner, CLazySerialize<uint32_t>) {
return callback(owner);
}, start);
void CAccountsView::ForEachAccount(std::function<bool(const CScript &)> callback, const CScript &start) {
ForEach<ByHeightKey, CScript, uint32_t>(
[&callback](const CScript &owner, CLazySerialize<uint32_t>) { return callback(owner); }, start);
}

Res CAccountsView::UpdateBalancesHeight(CScript const & owner, uint32_t height)
{
Res CAccountsView::UpdateBalancesHeight(const CScript &owner, uint32_t height) {
WriteBy<ByHeightKey>(owner, height);
return Res::Ok();
}

uint32_t CAccountsView::GetBalancesHeight(CScript const & owner)
{
uint32_t CAccountsView::GetBalancesHeight(const CScript &owner) {
uint32_t height;
bool ok = ReadBy<ByHeightKey>(owner, height);
return ok ? height : 0;
}

Res CAccountsView::StoreFuturesUserValues(const CFuturesUserKey& key, const CFuturesUserValue& futures)
{
Res CAccountsView::StoreFuturesUserValues(const CFuturesUserKey &key, const CFuturesUserValue &futures) {
if (!WriteBy<ByFuturesSwapKey>(key, futures)) {
return Res::Err("Failed to store futures");
}

return Res::Ok();
}

void CAccountsView::ForEachFuturesUserValues(std::function<bool(const CFuturesUserKey&, const CFuturesUserValue&)> callback, const CFuturesUserKey& start)
{
void CAccountsView::ForEachFuturesUserValues(
std::function<bool(const CFuturesUserKey &, const CFuturesUserValue &)> callback,
const CFuturesUserKey &start) {
ForEach<ByFuturesSwapKey, CFuturesUserKey, CFuturesUserValue>(callback, start);
}

Res CAccountsView::EraseFuturesUserValues(const CFuturesUserKey& key)
{
Res CAccountsView::EraseFuturesUserValues(const CFuturesUserKey &key) {
if (!EraseBy<ByFuturesSwapKey>(key)) {
return Res::Err("Failed to erase futures");
}

return Res::Ok();
}

Res CAccountsView::StoreFuturesDUSD(const CFuturesUserKey& key, const CAmount& amount)
{
Res CAccountsView::StoreFuturesDUSD(const CFuturesUserKey &key, const CAmount &amount) {
if (!WriteBy<ByFuturesDUSDKey>(key, amount)) {
return Res::Err("Failed to store futures");
}

return Res::Ok();
}

void CAccountsView::ForEachFuturesDUSD(std::function<bool(const CFuturesUserKey&, const CAmount&)> callback, const CFuturesUserKey& start)
{
void CAccountsView::ForEachFuturesDUSD(std::function<bool(const CFuturesUserKey &, const CAmount &)> callback,
const CFuturesUserKey &start) {
ForEach<ByFuturesDUSDKey, CFuturesUserKey, CAmount>(callback, start);
}

Res CAccountsView::EraseFuturesDUSD(const CFuturesUserKey& key)
{
Res CAccountsView::EraseFuturesDUSD(const CFuturesUserKey &key) {
if (!EraseBy<ByFuturesDUSDKey>(key)) {
return Res::Err("Failed to erase futures");
}
Expand Down
Loading

0 comments on commit 25ab35d

Please sign in to comment.