use of com.odysee.app.exceptions.LbryioRequestException in project odysee-android by OdyseeTeam.
the class SyncGetTask method doInBackground.
protected WalletSync doInBackground(Void... params) {
try {
password = Helper.isNullOrEmpty(password) ? "" : password;
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_WALLET_STATUS, Lbryio.AUTH_TOKEN);
boolean isLocked = Helper.getJSONBoolean("is_locked", false, result);
boolean unlockSuccessful = !isLocked || (boolean) Lbry.authenticatedGenericApiCall(Lbry.METHOD_WALLET_UNLOCK, Lbry.buildSingleParam("password", password), Lbryio.AUTH_TOKEN);
if (!unlockSuccessful) {
throw new WalletException("The wallet could not be unlocked with the provided password.");
}
String hash = (String) Lbry.authenticatedGenericApiCall(Lbry.METHOD_SYNC_HASH, null, Lbryio.AUTH_TOKEN);
try {
JSONObject response = (JSONObject) Lbryio.parseResponse(Lbryio.call("sync", "get", Lbryio.buildSingleParam("hash", hash), Helper.METHOD_POST, null));
WalletSync walletSync = new WalletSync(Helper.getJSONString("hash", null, response), Helper.getJSONString("data", null, response), Helper.getJSONBoolean("changed", false, response));
if (applySyncChanges && (!hash.equalsIgnoreCase(walletSync.getHash()) || walletSync.isChanged())) {
// Lbry.sync_apply({ password, data: response.data, blocking: true });
try {
Map<String, Object> options = new HashMap<>();
options.put("password", Helper.isNullOrEmpty(password) ? "" : password);
options.put("data", walletSync.getData());
options.put("blocking", true);
JSONObject syncApplyResponse = (JSONObject) Lbry.authenticatedGenericApiCall(Lbry.METHOD_SYNC_APPLY, options, Lbryio.AUTH_TOKEN);
syncHash = Helper.getJSONString("hash", null, syncApplyResponse);
syncData = Helper.getJSONString("data", null, syncApplyResponse);
applySyncSuccessful = true;
} catch (ApiCallException | ClassCastException ex) {
// sync_apply failed
syncApplyError = ex;
}
}
if (Lbryio.isSignedIn() && !Lbryio.userHasSyncedWallet) {
// indicate that the user owns a synced wallet (only if the user is signed in)
Lbryio.userHasSyncedWallet = true;
}
return walletSync;
} catch (LbryioResponseException ex) {
// wallet sync data doesn't exist
return null;
}
} catch (ApiCallException | WalletException | ClassCastException | LbryioRequestException ex) {
error = ex;
return null;
}
}
use of com.odysee.app.exceptions.LbryioRequestException in project odysee-android by OdyseeTeam.
the class ClaimRewardTask method doInBackground.
public String doInBackground(Void... params) {
String message = null;
try {
String txid = null;
if (Reward.TYPE_FIRST_CHANNEL.equalsIgnoreCase(type)) {
// fetch a channel
txid = fetchSingleClaimTxid(Claim.TYPE_CHANNEL);
} else if (Reward.TYPE_FIRST_PUBLISH.equalsIgnoreCase(type)) {
// fetch a publish
txid = fetchSingleClaimTxid(Claim.TYPE_STREAM);
}
// Get a new wallet address for the reward
String address = (String) Lbry.genericApiCall(Lbry.METHOD_ADDRESS_UNUSED, authToken);
Map<String, String> options = new HashMap<>();
options.put("reward_type", type);
options.put("wallet_address", address);
if (!Helper.isNullOrEmpty(rewardCode)) {
options.put("code", rewardCode);
}
if (!Helper.isNullOrEmpty(txid)) {
options.put("transaction_id", txid);
}
if (authToken != null) {
options.put("auth_token", authToken);
}
JSONObject reward = (JSONObject) Lbryio.parseResponse(Lbryio.call("reward", "claim", options, Helper.METHOD_POST, null));
if (reward != null) {
amountClaimed = Helper.getJSONDouble("reward_amount", 0, reward);
message = Helper.getJSONString("reward_notification", "", reward);
}
} catch (ApiCallException | JSONException | LbryioRequestException | LbryioResponseException ex) {
error = ex;
}
return message;
}
Aggregations