From 25ab35d0db9936ec048b9c4fd498d664e3c17a2d Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 24 Nov 2022 18:00:19 +0800 Subject: [PATCH] Enable clang-format on existing code (#1593) * 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 --- src/masternodes/.clang-format | 225 ++ src/masternodes/accounts.cpp | 73 +- src/masternodes/accounts.h | 82 +- src/masternodes/accountshistory.cpp | 138 +- src/masternodes/accountshistory.h | 92 +- src/masternodes/anchors.cpp | 604 ++-- src/masternodes/anchors.h | 399 ++- src/masternodes/auctionhistory.cpp | 18 +- src/masternodes/auctionhistory.h | 23 +- src/masternodes/balances.h | 77 +- src/masternodes/communityaccounttypes.h | 19 +- src/masternodes/factory.h | 24 +- src/masternodes/govvariables/attributes.cpp | 1186 ++++---- src/masternodes/govvariables/attributes.h | 372 +-- .../govvariables/icx_takerfee_per_btc.cpp | 24 +- .../govvariables/icx_takerfee_per_btc.h | 23 +- .../govvariables/loan_daily_reward.cpp | 24 +- .../govvariables/loan_daily_reward.h | 23 +- .../govvariables/loan_liquidation_penalty.cpp | 24 +- .../govvariables/loan_liquidation_penalty.h | 23 +- src/masternodes/govvariables/loan_splits.cpp | 39 +- src/masternodes/govvariables/loan_splits.h | 23 +- .../govvariables/lp_daily_dfi_reward.cpp | 24 +- .../govvariables/lp_daily_dfi_reward.h | 23 +- src/masternodes/govvariables/lp_splits.cpp | 43 +- src/masternodes/govvariables/lp_splits.h | 25 +- .../govvariables/oracle_block_interval.cpp | 24 +- .../govvariables/oracle_block_interval.h | 23 +- .../govvariables/oracle_deviation.cpp | 24 +- .../govvariables/oracle_deviation.h | 23 +- src/masternodes/gv.cpp | 35 +- src/masternodes/gv.h | 64 +- src/masternodes/icxorder.cpp | 290 +- src/masternodes/icxorder.h | 400 +-- src/masternodes/incentivefunding.cpp | 25 +- src/masternodes/incentivefunding.h | 39 +- src/masternodes/loan.cpp | 353 ++- src/masternodes/loan.h | 322 ++- src/masternodes/masternodes.cpp | 712 +++-- src/masternodes/masternodes.h | 383 +-- src/masternodes/mn_checks.cpp | 2471 +++++++++-------- src/masternodes/mn_checks.h | 438 +-- src/masternodes/mn_rpc.h | 65 +- src/masternodes/oracles.cpp | 116 +- src/masternodes/oracles.h | 90 +- src/masternodes/poolpairs.cpp | 392 +-- src/masternodes/poolpairs.h | 211 +- src/masternodes/proposals.cpp | 155 +- src/masternodes/proposals.h | 90 +- src/masternodes/res.h | 65 +- src/masternodes/rpc_customtx.cpp | 272 +- src/masternodes/rpc_poolpair.cpp | 1125 ++++---- src/masternodes/skipped_txs.cpp | 9 +- src/masternodes/tokens.cpp | 128 +- src/masternodes/tokens.h | 149 +- src/masternodes/undo.h | 26 +- src/masternodes/undos.cpp | 13 +- src/masternodes/undos.h | 17 +- src/masternodes/vault.cpp | 93 +- src/masternodes/vault.h | 116 +- src/masternodes/vaulthistory.cpp | 53 +- src/masternodes/vaulthistory.h | 88 +- test/lint/lint-logs.sh | 3 +- 63 files changed, 6599 insertions(+), 5953 deletions(-) create mode 100644 src/masternodes/.clang-format diff --git a/src/masternodes/.clang-format b/src/masternodes/.clang-format new file mode 100644 index 0000000000..6e988cfb1c --- /dev/null +++ b/src/masternodes/.clang-format @@ -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: '^' + 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 +... diff --git a/src/masternodes/accounts.cpp b/src/masternodes/accounts.cpp index 3e578d026a..0d36ca9d61 100644 --- a/src/masternodes/accounts.cpp +++ b/src/masternodes/accounts.cpp @@ -4,15 +4,16 @@ #include -void CAccountsView::ForEachBalance(std::function callback, BalanceKey const & start) -{ - ForEach([&callback] (BalanceKey const & key, CAmount val) { - return callback(key.owner, CTokenAmount{key.tokenID, val}); - }, start); +void CAccountsView::ForEachBalance(std::function callback, + const BalanceKey &start) { + ForEach( + [&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(BalanceKey{owner, tokenID}, val); if (ok) { @@ -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(BalanceKey{owner, amount.nTokenId}, amount.nValue); } else { @@ -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; @@ -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; @@ -79,28 +75,23 @@ Res CAccountsView::SubBalances(CScript const & owner, CBalances const & balances return Res::Ok(); } -void CAccountsView::ForEachAccount(std::function callback, CScript const & start) -{ - ForEach([&callback] (CScript const & owner, CLazySerialize) { - return callback(owner); - }, start); +void CAccountsView::ForEachAccount(std::function callback, const CScript &start) { + ForEach( + [&callback](const CScript &owner, CLazySerialize) { return callback(owner); }, start); } -Res CAccountsView::UpdateBalancesHeight(CScript const & owner, uint32_t height) -{ +Res CAccountsView::UpdateBalancesHeight(const CScript &owner, uint32_t height) { WriteBy(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(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(key, futures)) { return Res::Err("Failed to store futures"); } @@ -108,13 +99,13 @@ Res CAccountsView::StoreFuturesUserValues(const CFuturesUserKey& key, const CFut return Res::Ok(); } -void CAccountsView::ForEachFuturesUserValues(std::function callback, const CFuturesUserKey& start) -{ +void CAccountsView::ForEachFuturesUserValues( + std::function callback, + const CFuturesUserKey &start) { ForEach(callback, start); } -Res CAccountsView::EraseFuturesUserValues(const CFuturesUserKey& key) -{ +Res CAccountsView::EraseFuturesUserValues(const CFuturesUserKey &key) { if (!EraseBy(key)) { return Res::Err("Failed to erase futures"); } @@ -122,8 +113,7 @@ Res CAccountsView::EraseFuturesUserValues(const CFuturesUserKey& key) return Res::Ok(); } -Res CAccountsView::StoreFuturesDUSD(const CFuturesUserKey& key, const CAmount& amount) -{ +Res CAccountsView::StoreFuturesDUSD(const CFuturesUserKey &key, const CAmount &amount) { if (!WriteBy(key, amount)) { return Res::Err("Failed to store futures"); } @@ -131,13 +121,12 @@ Res CAccountsView::StoreFuturesDUSD(const CFuturesUserKey& key, const CAmount& a return Res::Ok(); } -void CAccountsView::ForEachFuturesDUSD(std::function callback, const CFuturesUserKey& start) -{ +void CAccountsView::ForEachFuturesDUSD(std::function callback, + const CFuturesUserKey &start) { ForEach(callback, start); } -Res CAccountsView::EraseFuturesDUSD(const CFuturesUserKey& key) -{ +Res CAccountsView::EraseFuturesDUSD(const CFuturesUserKey &key) { if (!EraseBy(key)) { return Res::Err("Failed to erase futures"); } diff --git a/src/masternodes/accounts.h b/src/masternodes/accounts.h index 54d1a8a100..5502657fda 100644 --- a/src/masternodes/accounts.h +++ b/src/masternodes/accounts.h @@ -5,10 +5,10 @@ #ifndef DEFI_MASTERNODES_ACCOUNTS_H #define DEFI_MASTERNODES_ACCOUNTS_H +#include #include -#include #include -#include +#include #include