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

Mint tokens rules adaptation #1568

Merged
merged 8 commits into from
Nov 15, 2022
Prev Previous commit
Fix logic
  • Loading branch information
Mixa84 committed Nov 15, 2022
commit ae262750ec5742d86611e8237fe0e9198c636476
30 changes: 16 additions & 14 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return Res::Err("token %s does not exist!", tokenId.ToString());

// only on REGTEST and when flag is supplied
bool anybodyCanMint = Params().NetworkIDString() != CBaseChainParams::REGTEST && !gArgs.GetArg("-regtest-minttoken-simulate-mainnet", false);
bool anybodyCanMint = (Params().NetworkIDString() != CBaseChainParams::REGTEST && !gArgs.GetArg("-regtest-minttoken-simulate-mainnet", false));

auto mintable = MintableToken(tokenId, *token, anybodyCanMint);

Expand All @@ -1313,20 +1313,19 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
auto res = mnview.AddBalance(*mintable.val, CTokenAmount{tokenId, amount});
if (!res)
return res;

return Res::Ok();
};

if (!mintable)
if (!mintable)
return std::move(mintable);

if (anybodyCanMint)
return mintTokensInternal(tokenId, amount);

if (height < static_cast<uint32_t>(consensus.GrandCentralHeight))
return mintTokensInternal(tokenId, amount);

if (!token->IsDAT() || HasFoundationAuth())
return mintTokensInternal(tokenId, amount);

if (anybodyCanMint || height < static_cast<uint32_t>(consensus.GrandCentralHeight) || !token->IsDAT() || HasFoundationAuth())
{
auto res = mintTokensInternal(tokenId, amount);
if (!res) return res;
continue;
}

auto attributes = mnview.GetAttributes();
assert(attributes);
Expand All @@ -1337,10 +1336,12 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor

if (!attributes->GetValue(enableKey, false) || members.empty()) {
const Coin& auth = coins.AccessCoin(COutPoint(token->creationTx, 1)); // always n=1 output
if (!HasAuth(auth.out.scriptPubKey))
if (!HasAuth(auth.out.scriptPubKey))
return Res::Err("You are not a foundation member or token owner and cannot mint this token!");

return mintTokensInternal(tokenId, amount);
auto res = mintTokensInternal(tokenId, amount);
if (!res) return res;
continue;
}

mintable.ok = false;
Expand Down Expand Up @@ -1423,7 +1424,8 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!saved)
return saved;

return mintTokensInternal(tokenId, amount);
auto minted = mintTokensInternal(tokenId, amount);
if (!minted) return minted;
}

return Res::Ok();
Expand Down