1
0

[Unit Tests] Lock/unlock wallet

This commit is contained in:
Scott E. Graves
2017-02-03 18:44:43 -06:00
parent 9dfc1a9331
commit cdaaafdb50
5 changed files with 34 additions and 8 deletions

View File

@@ -41,7 +41,7 @@ bool CSiaApi::_CSiaWallet::Refresh()
if (API_SUCCESS(SiaCurlError, error))
{
SetCreated(result["encrypted"].get<bool>());
SetLocked(result["unlocked"].get<bool>());
SetLocked(!result["unlocked"].get<bool>());
return true;
}
@@ -84,17 +84,35 @@ SiaApiError CSiaApi::_CSiaWallet::Lock()
SiaApiError error = GetCreated() ? (GetLocked() ? SiaApiError::WalletLocked : SiaApiError::Success) : SiaApiError::WalletNotCreated;
if (API_SUCCESS(SiaApiError, error))
{
error = SiaApiError::RequestError;
json result;
SiaCurlError cerror = _siaCurl.Post(L"/wallet/lock", {}, result);
if (API_SUCCESS(SiaCurlError, cerror))
{
Refresh();
error = SiaApiError::Success;
}
}
return error;
}
SiaApiError CSiaApi::_CSiaWallet::Unlock()
SiaApiError CSiaApi::_CSiaWallet::Unlock(const String& password)
{
SiaApiError error = GetCreated() ? (GetLocked() ? SiaApiError::Success : SiaApiError::WalletUnlocked) : SiaApiError::WalletNotCreated;
if (API_SUCCESS(SiaApiError, error))
{
error = SiaApiError::RequestError;
json result;
SiaCurlError cerror = _siaCurl.Post(L"/wallet/unlock", { {L"encryptionpassword", password} }, result);
if (API_SUCCESS(SiaCurlError, cerror))
{
Refresh();
error = SiaApiError::Success;
}
}
return error;
}