Skip to content

Commit

Permalink
Add CustomTxType FromString method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Apr 1, 2022
1 parent 35ad71b commit 773a205
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ std::string ToString(CustomTxType type) {
return "None";
}

CustomTxType FromString(const std::string& str) {
static const auto customTxTypeMap = []() {
std::map<std::string, CustomTxType> generatedMap;
for (auto i = 0u; i < 256; i++) {
auto txType = static_cast<CustomTxType>(i);
generatedMap.emplace(ToString(txType), txType);
}
return generatedMap;
}();
auto type = customTxTypeMap.find(str);
return type == customTxTypeMap.end() ? CustomTxType::None : type->second;
}

static ResVal<CBalances> BurntTokens(CTransaction const & tx) {
CBalances balances;
for (const auto& out : tx.vout) {
Expand Down
1 change: 1 addition & 0 deletions src/masternodes/mn_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ inline CustomTxType CustomTxCodeToType(uint8_t ch) {
}

std::string ToString(CustomTxType type);
CustomTxType FromString(const std::string& str);

// it's disabled after Dakota height
inline bool NotAllowedToFail(CustomTxType txType, int height) {
Expand Down
2 changes: 2 additions & 0 deletions src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,8 @@ UniValue listaccounthistory(const JSONRPCRequest& request) {
const auto str = optionsObj["txtype"].get_str();
if (str.size() == 1) {
txType = CustomTxCodeToType(str[0]);
} else {
txType = FromString(str);
}
}
if (!optionsObj["limit"].isNull()) {
Expand Down
2 changes: 2 additions & 0 deletions test/functional/rpc_listaccounthistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def run_test(self):
result = self.nodes[1].listaccounthistory()
assert_equal(result, [])

assert_equal(self.nodes[0].listaccounthistory('all', {"txtype": "MintToken"}), self.nodes[0].listaccounthistory('all', {"txtype": "M"}))

# REVERTING:
#========================
self.start_node(2)
Expand Down

0 comments on commit 773a205

Please sign in to comment.