1
0

Refactoring and added common utils

This commit is contained in:
Scott E. Graves
2017-02-17 18:58:06 -06:00
parent 6b425fc5ca
commit 9b44d435f8
9 changed files with 101 additions and 30 deletions

View File

@@ -38,7 +38,7 @@ bool CSiaApi::_CSiaWallet::Refresh()
{
json result;
SiaCurlError error = _siaCurl.Get(L"/wallet", result);
if (API_SUCCESS(SiaCurlError, error))
if (ApiSuccess(error))
{
SetCreated(result["encrypted"].get<bool>());
SetLocked(!result["unlocked"].get<bool>());
@@ -60,7 +60,7 @@ SiaApiError CSiaApi::_CSiaWallet::Create(const SiaSeedLanguage& seedLanguage, St
error = SiaApiError::RequestError;
json result;
SiaCurlError cerror = _siaCurl.Post(L"/wallet/init", { {L"dictionary", SeedLangToString(seedLanguage)} }, result);
if (API_SUCCESS(SiaCurlError, cerror))
if (ApiSuccess(cerror))
{
error = SiaApiError::Success;
seed = CA2W(result["primaryseed"].get<std::string>().c_str());
@@ -82,13 +82,13 @@ SiaApiError CSiaApi::_CSiaWallet::Restore(const String& seed)
SiaApiError CSiaApi::_CSiaWallet::Lock()
{
SiaApiError error = GetCreated() ? (GetLocked() ? SiaApiError::WalletLocked : SiaApiError::Success) : SiaApiError::WalletNotCreated;
if (API_SUCCESS(SiaApiError, error))
if (ApiSuccess(error))
{
error = SiaApiError::RequestError;
json result;
SiaCurlError cerror = _siaCurl.Post(L"/wallet/lock", {}, result);
if (API_SUCCESS(SiaCurlError, cerror))
if (ApiSuccess(cerror))
{
Refresh();
error = SiaApiError::Success;
@@ -101,13 +101,13 @@ SiaApiError CSiaApi::_CSiaWallet::Lock()
SiaApiError CSiaApi::_CSiaWallet::Unlock(const String& password)
{
SiaApiError error = GetCreated() ? (GetLocked() ? SiaApiError::Success : SiaApiError::WalletUnlocked) : SiaApiError::WalletNotCreated;
if (API_SUCCESS(SiaApiError, error))
if (ApiSuccess(error))
{
error = SiaApiError::RequestError;
json result;
SiaCurlError cerror = _siaCurl.Post(L"/wallet/unlock", { {L"encryptionpassword", password} }, result);
if (API_SUCCESS(SiaCurlError, cerror))
if (ApiSuccess(cerror))
{
Refresh();
error = SiaApiError::Success;
@@ -135,7 +135,7 @@ SiaApiError CSiaApi::_CSiaWallet::GetConfirmedBalance(SiaCurrency& balance) cons
json result;
SiaCurlError cerror = _siaCurl.Get(L"/wallet", result);
if (API_SUCCESS(SiaCurlError, cerror))
if (ApiSuccess(cerror))
{
balance = HastingsStringToSiaCurrency(String(CA2W(result["confirmedsiacoinbalance"].get<std::string>().c_str())));
ret = SiaApiError::Success;
@@ -151,7 +151,7 @@ SiaApiError CSiaApi::_CSiaWallet::GetUnonfirmedBalance(SiaCurrency& balance) con
json result;
SiaCurlError cerror = _siaCurl.Get(L"/wallet", result);
if (API_SUCCESS(SiaCurlError, cerror))
if (ApiSuccess(cerror))
{
balance = HastingsStringToSiaCurrency(String(CA2W(result["unconfirmedincomingsiacoins"].get<std::string>().c_str())));
ret = SiaApiError::Success;
@@ -167,7 +167,7 @@ SiaApiError CSiaApi::_CSiaWallet::GetAddress(String& address) const
json result;
SiaCurlError cerror = _siaCurl.Get(L"/wallet/address", result);
if (API_SUCCESS(SiaCurlError, cerror))
if (ApiSuccess(cerror))
{
address = CA2W(result["address"].get<std::string>().c_str());
ret = SiaApiError::Success;