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 Mar 31, 2022
1 parent 35ad71b commit 30b4d46
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,65 @@ std::string ToString(CustomTxType type) {
return "None";
}

CustomTxType FromString(const std::string& str) {
static const std::map<std::string, CustomTxType> customTxTypeMap {
{ "CreateMasternode", CustomTxType::CreateMasternode },
{ "ResignMasternode", CustomTxType::ResignMasternode },
{ "SetForcedRewardAddress", CustomTxType::SetForcedRewardAddress },
{ "RemForcedRewardAddress", CustomTxType::RemForcedRewardAddress },
{ "UpdateMasternode", CustomTxType::UpdateMasternode },
{ "CreateToken", CustomTxType::CreateToken },
{ "UpdateToken", CustomTxType::UpdateToken },
{ "UpdateTokenAny", CustomTxType::UpdateTokenAny },
{ "MintToken", CustomTxType::MintToken },
{ "CreatePoolPair", CustomTxType::CreatePoolPair },
{ "UpdatePoolPair", CustomTxType::UpdatePoolPair },
{ "PoolSwap", CustomTxType::PoolSwap },
{ "AddPoolLiquidity", CustomTxType::AddPoolLiquidity },
{ "RemovePoolLiquidity", CustomTxType::RemovePoolLiquidity },
{ "UtxosToAccount", CustomTxType::UtxosToAccount },
{ "AccountToUtxos", CustomTxType::AccountToUtxos },
{ "AccountToAccount", CustomTxType::AccountToAccount },
{ "AnyAccountsToAccounts", CustomTxType::AnyAccountsToAccounts },
{ "SmartContract", CustomTxType::SmartContract },
{ "DFIP2203", CustomTxType::DFIP2203 },
{ "SetGovVariable", CustomTxType::SetGovVariable },
{ "SetGovVariableHeight", CustomTxType::SetGovVariableHeight },
{ "AppointOracle", CustomTxType::AppointOracle },
{ "RemoveOracleAppoint", CustomTxType::RemoveOracleAppoint },
{ "UpdateOracleAppoint", CustomTxType::UpdateOracleAppoint },
{ "SetOracleData", CustomTxType::SetOracleData },
{ "AutoAuth", CustomTxType::AutoAuthPrep },
{ "ICXCreateOrder", CustomTxType::ICXCreateOrder },
{ "ICXMakeOffer", CustomTxType::ICXMakeOffer },
{ "ICXSubmitDFCHTLC", CustomTxType::ICXSubmitDFCHTLC },
{ "ICXSubmitEXTHTLC", CustomTxType::ICXSubmitEXTHTLC },
{ "ICXClaimDFCHTLC", CustomTxType::ICXClaimDFCHTLC },
{ "ICXCloseOrder", CustomTxType::ICXCloseOrder },
{ "ICXCloseOffer", CustomTxType::ICXCloseOffer },
{ "SetLoanCollateralToken", CustomTxType::SetLoanCollateralToken },
{ "SetLoanToken", CustomTxType::SetLoanToken },
{ "UpdateLoanToken", CustomTxType::UpdateLoanToken },
{ "LoanScheme", CustomTxType::LoanScheme },
{ "DefaultLoanScheme", CustomTxType::DefaultLoanScheme },
{ "DestroyLoanScheme", CustomTxType::DestroyLoanScheme },
{ "Vault", CustomTxType::Vault },
{ "CloseVault", CustomTxType::CloseVault },
{ "UpdateVault", CustomTxType::UpdateVault },
{ "DepositToVault", CustomTxType::DepositToVault },
{ "WithdrawFromVault", CustomTxType::WithdrawFromVault },
{ "TakeLoan", CustomTxType::TakeLoan },
{ "PaybackLoan", CustomTxType::PaybackLoan },
{ "AuctionBid", CustomTxType::AuctionBid },
{ "FutureSwapExecution", CustomTxType::FutureSwapExecution },
{ "FutureSwapRefund", CustomTxType::FutureSwapRefund },
{ "Reject", CustomTxType::Reject },
{ "None", CustomTxType::None },
};
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 30b4d46

Please sign in to comment.