From 4d931e389fc0e6c4b9dcc862dedf24ba9f85502f Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 13:55:06 +0800 Subject: [PATCH 1/2] Reverts of Require in Sub/Add Balances --- src/masternodes/balances.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/masternodes/balances.h b/src/masternodes/balances.h index d369d092d2..5fda30ed89 100644 --- a/src/masternodes/balances.h +++ b/src/masternodes/balances.h @@ -57,9 +57,11 @@ struct CBalances { } Res SubBalances(const TAmounts &other) { - for (const auto &[tokenId, amount] : other) - Require(Sub(CTokenAmount{tokenId, amount})); - + for (const auto &[tokenId, amount] : other) { + if (auto res = Sub(CTokenAmount{tokenId, amount}); !res) { + return res; + } + } return Res::Ok(); } @@ -75,9 +77,11 @@ struct CBalances { } Res AddBalances(const TAmounts &other) { - for (const auto &[tokenId, amount] : other) - Require(Add(CTokenAmount{tokenId, amount})); - + for (const auto &[tokenId, amount] : other) { + if (auto res = Add(CTokenAmount{tokenId, amount}); !res) { + return res; + } + } return Res::Ok(); } From 6849d6e35c8371832a81cb7ab27d87a9c00845e7 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 13:58:46 +0800 Subject: [PATCH 2/2] Revert ifs on Add/Sub --- src/masternodes/balances.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/masternodes/balances.h b/src/masternodes/balances.h index 5fda30ed89..49b1c0c0a2 100644 --- a/src/masternodes/balances.h +++ b/src/masternodes/balances.h @@ -18,7 +18,9 @@ struct CBalances { return Res::Ok(); } auto current = CTokenAmount{amount.nTokenId, balances[amount.nTokenId]}; - Require(current.Add(amount.nValue)); + if (auto res = current.Add(amount.nValue); !res) { + return res; + } if (current.nValue == 0) { balances.erase(amount.nTokenId); } else { @@ -32,7 +34,9 @@ struct CBalances { return Res::Ok(); } auto current = CTokenAmount{amount.nTokenId, balances[amount.nTokenId]}; - Require(current.Sub(amount.nValue)); + if (auto res = current.Sub(amount.nValue); !res) { + return res; + } if (current.nValue == 0) { balances.erase(amount.nTokenId);