-
Notifications
You must be signed in to change notification settings - Fork 683
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
Check units when issuing assets #249
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,28 +239,52 @@ bool CNewAsset::IsValid(std::string& strError, CAssetsCache& assetCache, bool fC | |
} | ||
} | ||
|
||
if (!IsAssetNameValid(std::string(strName))) | ||
if (!IsAssetNameValid(std::string(strName))) { | ||
strError = "Invalid parameter: asset_name must only consist of valid characters and have a size between 3 and 30 characters. See help for more details."; | ||
return false; | ||
} | ||
|
||
if (IsAssetNameAnOwner(std::string(strName))) | ||
if (IsAssetNameAnOwner(std::string(strName))) { | ||
strError = "Invalid parameters: asset_name can't have a '!' at the end of it. See help for more details."; | ||
return false; | ||
} | ||
|
||
if (nAmount <= 0) | ||
strError = "Invalid parameter: asset amount can't be equal to or less than zero."; | ||
if (nAmount <= 0) { | ||
strError = "Invalid parameter: asset amount can't be equal to or less than zero."; | ||
return false; | ||
} | ||
|
||
if (units < 0 || units > 8) | ||
strError = "Invalid parameter: units must be between 0-8."; | ||
if (nAmount > MAX_MONEY) { | ||
strError = "Invalid parameter: asset amount greater than max."; | ||
return false; | ||
} | ||
|
||
if (nReissuable != 0 && nReissuable != 1) | ||
strError = "Invalid parameter: reissuable must be 0 or 1"; | ||
if (units < 0 || units > 8) { | ||
strError = "Invalid parameter: units must be between 0-8."; | ||
return false; | ||
} | ||
|
||
if (nHasIPFS != 0 && nHasIPFS != 1) | ||
strError = "Invalid parameter: has_ipfs must be 0 or 1."; | ||
if (!CheckAmountWithUnits(nAmount, units)) { | ||
strError = "bad-txns-transfer-asset-amount-not-match-units"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
return false; | ||
} | ||
|
||
if (nHasIPFS && strIPFSHash.size() != 34) | ||
strError = "Invalid parameter: ipfs_hash must be 34 bytes."; | ||
if (nReissuable != 0 && nReissuable != 1) { | ||
strError = "Invalid parameter: reissuable must be 0 or 1"; | ||
return false; | ||
} | ||
|
||
return strError == ""; | ||
if (nHasIPFS != 0 && nHasIPFS != 1) { | ||
strError = "Invalid parameter: has_ipfs must be 0 or 1."; | ||
return false; | ||
} | ||
|
||
if (nHasIPFS && strIPFSHash.size() != 34) { | ||
strError = "Invalid parameter: ipfs_hash must be 34 bytes."; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
CNewAsset::CNewAsset(const CNewAsset& asset) | ||
|
@@ -696,7 +720,7 @@ bool CReissueAsset::IsValid(std::string &strError, CAssetsCache& assetCache) con | |
return false; | ||
} | ||
|
||
if (nAmount % int64_t(pow(10, (MAX_UNIT - asset.units))) != 0) { | ||
if (!CheckAmountWithUnits(nAmount, asset.units)) { | ||
strError = "Unable to reissue asset: amount must be divisable by the smaller unit assigned to the asset"; | ||
return false; | ||
} | ||
|
@@ -2472,4 +2496,10 @@ bool VerifyWalletHasAsset(const std::string& asset_name, std::pair<int, std::str | |
|
||
pairError = std::make_pair(RPC_INVALID_REQUEST, strprintf("Wallet doesn't have asset: %s", asset_name)); | ||
return false; | ||
} | ||
|
||
// Return true if the amount is valid with the units passed in | ||
bool CheckAmountWithUnits(const CAmount& nAmount, const uint8_t nUnits) | ||
{ | ||
return nAmount % int64_t(pow(10, (MAX_UNIT - nUnits))) == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could put MAX_MONEY into strError