status-desktop/libs/StatusGoQt/src/StatusGo/Utils.cpp

50 lines
1.5 KiB
C++
Raw Normal View History

#include "Utils.h"
#include <libstatus.h>
#include <QtCore>
namespace Status::StatusGo::Utils
{
QJsonArray toJsonArray(const std::vector<Accounts::DerivationPath>& value)
{
QJsonArray array;
for(auto& v : value)
array << v.get();
return array;
}
2022-10-19 13:41:53 +00:00
const char* statusGoCallPrivateRPC(const char* inputJSON)
{
// Evil done here! status-go API doesn't follow the proper const conventions
return CallPrivateRPC(const_cast<char*>(inputJSON));
}
2022-10-19 13:41:53 +00:00
HashedPassword hashPassword(const QString& str)
{
// TODO: is utf8 the standard used by NIM also? Will it unlock DBs encrypted with NIM password hashing?
2022-10-19 13:41:53 +00:00
return HashedPassword(
"0x" +
QString::fromUtf8(QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Keccak_256).toHex().toUpper()));
}
std::optional<RpcError> getRPCErrorInJson(const QJsonObject& json)
{
auto errVal = json[Param::Error];
2022-10-19 13:41:53 +00:00
if(errVal.isNull() || errVal.isUndefined()) return std::nullopt;
if(errVal.isString() && errVal.toString().length() == 0) return std::nullopt;
RpcError response;
auto errObj = json[Param::Id].toObject();
2022-10-19 13:41:53 +00:00
if(!errObj[Param::ErrorCode].isNull() && !errObj[Param::ErrorCode].isUndefined())
response.code = errObj[Param::ErrorCode].toInt();
2022-10-19 13:41:53 +00:00
if(!errObj[Param::ErrorMessage].isNull() && !errObj[Param::ErrorMessage].isUndefined())
response.message = errObj[Param::ErrorMessage].toString();
else
response.message = errVal.toString();
return response;
}
2022-10-19 13:41:53 +00:00
} // namespace Status::StatusGo::Utils