Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CustomTxType FromString method #1180

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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