-
Notifications
You must be signed in to change notification settings - Fork 27
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
Showing
11 changed files
with
544 additions
and
227 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
12 changes: 4 additions & 8 deletions
12
app/src/main/java/com/odysee/app/callable/WalletGetUnusedAddress.java
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
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/odysee/app/supplier/ClaimRewardSupplier.java
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,87 @@ | ||
package com.odysee.app.supplier; | ||
|
||
import com.odysee.app.exceptions.ApiCallException; | ||
import com.odysee.app.exceptions.LbryioRequestException; | ||
import com.odysee.app.exceptions.LbryioResponseException; | ||
import com.odysee.app.model.Claim; | ||
import com.odysee.app.model.lbryinc.Reward; | ||
import com.odysee.app.utils.Helper; | ||
import com.odysee.app.utils.Lbry; | ||
import com.odysee.app.utils.Lbryio; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
public class ClaimRewardSupplier implements Supplier<JSONObject> { | ||
private final String type; | ||
private final String rewardCode; | ||
private final String token; | ||
|
||
public ClaimRewardSupplier(String type, String rewardCode, String token) { | ||
this.type = type; | ||
this.rewardCode = rewardCode; | ||
this.token = token; | ||
} | ||
|
||
@SneakyThrows | ||
@Override | ||
public JSONObject get() { | ||
return claimReward(); | ||
} | ||
|
||
private JSONObject claimReward() throws ApiCallException, LbryioResponseException { | ||
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); | ||
} | ||
|
||
Map<String, String> options = new HashMap<>(); | ||
options.put("reward_type", type); | ||
options.put("wallet_address", (String) Lbry.genericApiCall(Lbry.METHOD_ADDRESS_UNUSED, token)); | ||
|
||
if (!Helper.isNullOrEmpty(rewardCode)) { | ||
options.put("code", rewardCode); | ||
} | ||
if (!Helper.isNullOrEmpty(txid)) { | ||
options.put("transaction_id", txid); | ||
} | ||
if (token != null) { | ||
options.put("auth_token", token); | ||
} | ||
|
||
return (JSONObject) Lbryio.parseResponse(Lbryio.call("reward", "claim", options, Helper.METHOD_POST, null)); | ||
} catch (JSONException | LbryioRequestException ex) { | ||
ex.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
private String fetchSingleClaimTxid(String claimType) throws ApiCallException, JSONException { | ||
Map<String, Object> options = new HashMap<>(); | ||
options.put("claim_type", claimType); | ||
options.put("page", 1); | ||
options.put("page_size", 1); | ||
options.put("resolve", true); | ||
|
||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CLAIM_LIST, options); | ||
JSONArray items = result.getJSONArray("items"); | ||
if (items.length() > 0) { | ||
Claim claim = Claim.fromJSONObject(items.getJSONObject(0)); | ||
return claim.getTxid(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/odysee/app/supplier/FetchRewardsSupplier.java
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,39 @@ | ||
package com.odysee.app.supplier; | ||
|
||
import com.odysee.app.exceptions.LbryioRequestException; | ||
import com.odysee.app.exceptions.LbryioResponseException; | ||
import com.odysee.app.model.lbryinc.Reward; | ||
import com.odysee.app.utils.Lbryio; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class FetchRewardsSupplier implements Supplier<List<Reward>> { | ||
Map<String, String> options; | ||
|
||
public FetchRewardsSupplier(Map<String, String> options) { | ||
this.options = options; | ||
} | ||
|
||
@Override | ||
public List<Reward> get() { | ||
List<Reward> rewards = new ArrayList<>(); | ||
try { | ||
JSONArray results = (JSONArray) Lbryio.parseResponse(Lbryio.call("reward", "list", options, null)); | ||
rewards = new ArrayList<>(); | ||
if (results != null) { | ||
for (int i = 0; i < results.length(); i++) { | ||
rewards.add(Reward.fromJSONObject(results.getJSONObject(i))); | ||
} | ||
} | ||
} catch (LbryioResponseException | JSONException | LbryioRequestException e) { | ||
e.printStackTrace(); | ||
} | ||
return rewards; | ||
} | ||
} |
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
Oops, something went wrong.