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

Fix loan token flag for old token on split #1277

Merged
merged 1 commit into from
May 24, 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
7 changes: 5 additions & 2 deletions src/masternodes/tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Res CTokensView::RevertCreateToken(const uint256 & txid)
return Res::Ok();
}

Res CTokensView::UpdateToken(const CTokenImpl& newToken, bool isPreBayfront, const bool skipNameValidation)
Res CTokensView::UpdateToken(const CTokenImpl& newToken, bool isPreBayfront, const bool tokenSplitUpdate)
{
auto pair = GetTokenByCreationTx(newToken.creationTx);
if (!pair) {
Expand All @@ -152,7 +152,7 @@ Res CTokensView::UpdateToken(const CTokenImpl& newToken, bool isPreBayfront, con
oldToken.name = newToken.name;

// check new symbol correctness
if (!skipNameValidation) {
if (!tokenSplitUpdate) {
auto checkSymbolRes = newToken.IsValidSymbol();
if (!checkSymbolRes.ok) {
return checkSymbolRes;
Expand Down Expand Up @@ -186,6 +186,9 @@ Res CTokensView::UpdateToken(const CTokenImpl& newToken, bool isPreBayfront, con
if (!oldToken.IsFinalized() && newToken.IsFinalized()) // IsFinalized() itself was checked upthere (with Err)
oldToken.flags |= (uint8_t)CToken::TokenFlags::Finalized;

if (tokenSplitUpdate && oldToken.IsLoanToken() != newToken.IsLoanToken())
oldToken.flags ^= (uint8_t)CToken::TokenFlags::LoanToken;

if (oldToken.destructionHeight != newToken.destructionHeight) {
oldToken.destructionHeight = newToken.destructionHeight;
}
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CTokensView : public virtual CStorageView
Res CreateDFIToken();
ResVal<DCT_ID> CreateToken(CTokenImpl const & token, bool isPreBayfront = false);
Res RevertCreateToken(uint256 const & txid);
Res UpdateToken(CTokenImpl const & newToken, bool isPreBayfront = false, const bool skipNameValidation = false);
Res UpdateToken(CTokenImpl const & newToken, bool isPreBayfront = false, const bool tokenSplitUpdatea = false);

Res BayfrontFlagsCleanup();
Res AddMintedTokens(DCT_ID const & id, CAmount const & amount);
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4141,7 +4141,7 @@ void CChainState::ProcessTokenSplits(const CBlock& block, const CBlockIndex* pin
token->symbol += newTokenSuffix;
token->destructionHeight = pindex->nHeight;
token->destructionTx = pindex->GetBlockHash();
token->flags &= ~static_cast<uint8_t>(CToken::TokenFlags::Default);
token->flags &= ~(static_cast<uint8_t>(CToken::TokenFlags::Default) | static_cast<uint8_t>(CToken::TokenFlags::LoanToken));
token->flags |= static_cast<uint8_t>(CToken::TokenFlags::Finalized);

res = view.SubMintedTokens(oldTokenId, token->minted);
Expand Down
2 changes: 2 additions & 0 deletions test/functional/feature_token_split.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def check_token_split(self, token_id, token_symbol, token_suffix, multiplier, mi
assert_equal(result['mintable'], False)
assert_equal(result['tradeable'], False)
assert_equal(result['finalized'], True)
assert_equal(result['isLoanToken'], False)
assert_equal(result['destructionTx'], self.nodes[0].getbestblockhash())
assert_equal(result['destructionHeight'], self.nodes[0].getblockcount())

Expand Down Expand Up @@ -287,6 +288,7 @@ def check_token_split(self, token_id, token_symbol, token_suffix, multiplier, mi
assert_equal(result['mintable'], True)
assert_equal(result['tradeable'], True)
assert_equal(result['finalized'], False)
assert_equal(result['isLoanToken'], True)
assert_equal(result['creationTx'], self.nodes[0].getblock(self.nodes[0].getbestblockhash())['tx'][1])
assert_equal(result['creationHeight'], self.nodes[0].getblockcount())
assert_equal(result['destructionTx'], '0000000000000000000000000000000000000000000000000000000000000000')
Expand Down