forked from PIVX-Project/PIVX
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2abe6e
commit ee2f0e8
Showing
42 changed files
with
1,673 additions
and
83 deletions.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2018-2019 Netbox.Global | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include "dapp.h" | ||
|
||
#include <vector> | ||
|
||
#include "univalue/lib/univalue_utffilter.h" | ||
#include "utilstrencodings.h" | ||
|
||
bool isBase64png(const std::string &data) { | ||
bool fInvalid = false; | ||
std::vector<unsigned char> tmpImg = DecodeBase64(data.c_str(), &fInvalid); | ||
if (fInvalid) | ||
return false; | ||
if (tmpImg.size() <= 8 || memcmp(tmpImg.data(), "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 8)) | ||
return false; | ||
return true; | ||
} | ||
|
||
bool isValidUtf8(const std::string &data) { | ||
std::string str; | ||
JSONUTF8StringFilter filter(str); | ||
for (const char &c : data) | ||
filter.push_back(c); | ||
if (!filter.finalize()) | ||
return false; | ||
return true; | ||
} | ||
|
||
bool DApp::CheckData(std::string *errorStr) const { | ||
if (!CheckField(name, errorStr)) { | ||
if (errorStr) | ||
*errorStr = "dApp name " + *errorStr; | ||
return false; | ||
} | ||
if (!CheckField(url, errorStr)) { | ||
if (errorStr) | ||
*errorStr = "dApp url " + *errorStr; | ||
return false; | ||
} | ||
if (!CheckField(blockchain, errorStr)) { | ||
if (errorStr) | ||
*errorStr = "dApp blockchain " + *errorStr; | ||
return false; | ||
} | ||
if (!CheckField(description, errorStr)) { | ||
if (errorStr) | ||
*errorStr = "dApp description " + *errorStr; | ||
return false; | ||
} | ||
if (!CheckImage(image, errorStr)) { | ||
if (errorStr) | ||
*errorStr = "dApp image " + *errorStr; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool DApp::IsEmpty() const { | ||
return name.empty() && url.empty() && blockchain.empty() && description.empty() && image.empty(); | ||
} | ||
|
||
bool DApp::CheckField(const std::string &str, std::string *errorStr) { | ||
if (str.empty()) { | ||
if (errorStr) | ||
*errorStr = "is empty"; | ||
return false; | ||
} | ||
if (!isValidUtf8(str)) { | ||
if (errorStr) | ||
*errorStr = "is not in UTF-8"; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool DApp::CheckImage(const std::string &str, std::string *errorStr) { | ||
if (str.empty()) { | ||
if (errorStr) | ||
*errorStr = "is empty"; | ||
return false; | ||
} | ||
if (!isBase64png(str)) { | ||
if (errorStr) | ||
*errorStr = "is not Base64-encoded PNG"; | ||
return false; | ||
} | ||
return true; | ||
} |
Oops, something went wrong.