mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-12-22 21:17:47 +00:00
0.4.4.6: Improve coin freezing
This commit is contained in:
parent
71dcdfdb99
commit
4bf9bf6ee2
7 changed files with 73 additions and 11 deletions
|
@ -9,8 +9,8 @@ android {
|
||||||
applicationId "net.mynero.wallet"
|
applicationId "net.mynero.wallet"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 34
|
targetSdkVersion 34
|
||||||
versionCode 40405
|
versionCode 40406
|
||||||
versionName "0.4.4.5 'Fluorine Fermi'"
|
versionName "0.4.4.6 'Fluorine Fermi'"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
|
|
|
@ -109,11 +109,11 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
|
this.utxoService.refreshUtxos();
|
||||||
this.historyService.refreshHistory();
|
this.historyService.refreshHistory();
|
||||||
this.balanceService.refreshBalance();
|
this.balanceService.refreshBalance();
|
||||||
this.blockchainService.refreshBlockchain();
|
this.blockchainService.refreshBlockchain();
|
||||||
this.addressService.refreshAddresses();
|
this.addressService.refreshAddresses();
|
||||||
this.utxoService.refreshUtxos();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,6 +29,7 @@ import net.mynero.wallet.R;
|
||||||
import net.mynero.wallet.model.CoinsInfo;
|
import net.mynero.wallet.model.CoinsInfo;
|
||||||
import net.mynero.wallet.model.Wallet;
|
import net.mynero.wallet.model.Wallet;
|
||||||
import net.mynero.wallet.service.PrefService;
|
import net.mynero.wallet.service.PrefService;
|
||||||
|
import net.mynero.wallet.service.UTXOService;
|
||||||
import net.mynero.wallet.util.Constants;
|
import net.mynero.wallet.util.Constants;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -150,7 +151,7 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
|
||||||
outpointTextView.setText(itemView.getResources().getString(R.string.outpoint_text, coinsInfo.getHash() + ":" + coinsInfo.getLocalOutputIndex()));
|
outpointTextView.setText(itemView.getResources().getString(R.string.outpoint_text, coinsInfo.getHash() + ":" + coinsInfo.getLocalOutputIndex()));
|
||||||
if (selected) {
|
if (selected) {
|
||||||
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_colorSecondary));
|
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_colorSecondary));
|
||||||
} else if(coinsInfo.isFrozen()) {
|
} else if(coinsInfo.isFrozen() || UTXOService.instance.isCoinFrozen(coinsInfo)) {
|
||||||
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_frozen_utxo));
|
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_frozen_utxo));
|
||||||
} else if (!coinsInfo.isUnlocked()) {
|
} else if (!coinsInfo.isUnlocked()) {
|
||||||
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_locked_utxo));
|
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_locked_utxo));
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
|
||||||
|
|
||||||
boolean frozenExists = false, unfrozenExists = false, bothExist = false;
|
boolean frozenExists = false, unfrozenExists = false, bothExist = false;
|
||||||
for(CoinsInfo selectedUtxo : adapter.getSelectedUtxos().values()) {
|
for(CoinsInfo selectedUtxo : adapter.getSelectedUtxos().values()) {
|
||||||
if(selectedUtxo.isFrozen())
|
if(selectedUtxo.isFrozen() || UTXOService.getInstance().isCoinFrozen(selectedUtxo))
|
||||||
frozenExists = true;
|
frozenExists = true;
|
||||||
else {
|
else {
|
||||||
unfrozenExists = true;
|
unfrozenExists = true;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import net.mynero.wallet.model.BalanceInfo;
|
import net.mynero.wallet.model.BalanceInfo;
|
||||||
|
import net.mynero.wallet.model.CoinsInfo;
|
||||||
import net.mynero.wallet.model.Wallet;
|
import net.mynero.wallet.model.Wallet;
|
||||||
import net.mynero.wallet.model.WalletManager;
|
import net.mynero.wallet.model.WalletManager;
|
||||||
import net.mynero.wallet.util.Constants;
|
import net.mynero.wallet.util.Constants;
|
||||||
|
@ -29,11 +30,23 @@ public class BalanceService extends ServiceBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUnlockedBalanceRaw() {
|
public long getUnlockedBalanceRaw() {
|
||||||
return WalletManager.getInstance().getWallet().getUnlockedBalance();
|
long unlocked = 0;
|
||||||
|
for(CoinsInfo coinsInfo : UTXOService.getInstance().getUtxos()) {
|
||||||
|
if(!coinsInfo.isSpent() && !coinsInfo.isFrozen() && coinsInfo.isUnlocked() && !UTXOService.getInstance().isCoinFrozen(coinsInfo)) {
|
||||||
|
unlocked += coinsInfo.getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unlocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTotalBalanceRaw() {
|
public long getTotalBalanceRaw() {
|
||||||
return WalletManager.getInstance().getWallet().getBalance();
|
long total = 0;
|
||||||
|
for(CoinsInfo coinsInfo : UTXOService.getInstance().getUtxos()) {
|
||||||
|
if(!coinsInfo.isSpent() && !coinsInfo.isFrozen() && !UTXOService.getInstance().isCoinFrozen(coinsInfo)) {
|
||||||
|
total += coinsInfo.getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLockedBalanceRaw() {
|
public long getLockedBalanceRaw() {
|
||||||
|
|
|
@ -10,6 +10,10 @@ import net.mynero.wallet.model.CoinsInfo;
|
||||||
import net.mynero.wallet.model.PendingTransaction;
|
import net.mynero.wallet.model.PendingTransaction;
|
||||||
import net.mynero.wallet.model.Wallet;
|
import net.mynero.wallet.model.Wallet;
|
||||||
import net.mynero.wallet.model.WalletManager;
|
import net.mynero.wallet.model.WalletManager;
|
||||||
|
import net.mynero.wallet.util.Constants;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -20,10 +24,16 @@ public class UTXOService extends ServiceBase {
|
||||||
public static UTXOService instance = null;
|
public static UTXOService instance = null;
|
||||||
private final MutableLiveData<List<CoinsInfo>> _utxos = new MutableLiveData<>();
|
private final MutableLiveData<List<CoinsInfo>> _utxos = new MutableLiveData<>();
|
||||||
public LiveData<List<CoinsInfo>> utxos = _utxos;
|
public LiveData<List<CoinsInfo>> utxos = _utxos;
|
||||||
|
private ArrayList<String> frozenCoins = new ArrayList<>();
|
||||||
|
|
||||||
public UTXOService(MoneroHandlerThread thread) {
|
public UTXOService(MoneroHandlerThread thread) {
|
||||||
super(thread);
|
super(thread);
|
||||||
instance = this;
|
instance = this;
|
||||||
|
try {
|
||||||
|
this.loadFrozenCoins();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UTXOService getInstance() {
|
public static UTXOService getInstance() {
|
||||||
|
@ -31,19 +41,56 @@ public class UTXOService extends ServiceBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshUtxos() {
|
public void refreshUtxos() {
|
||||||
_utxos.postValue(getUtxos());
|
_utxos.postValue(getUtxosInternal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CoinsInfo> getUtxos() {
|
public List<CoinsInfo> getUtxos() {
|
||||||
|
List<CoinsInfo> value = utxos.getValue();
|
||||||
|
return value != null ? value : List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<CoinsInfo> getUtxosInternal() {
|
||||||
return WalletManager.getInstance().getWallet().getCoins().getAll();
|
return WalletManager.getInstance().getWallet().getCoins().getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleFrozen(HashMap<String, CoinsInfo> selectedCoins) {
|
public void toggleFrozen(HashMap<String, CoinsInfo> selectedCoins) {
|
||||||
Coins coins = WalletManager.getInstance().getWallet().getCoins();
|
ArrayList<String> frozenCoinsCopy = new ArrayList<>(frozenCoins);
|
||||||
for(CoinsInfo coin : selectedCoins.values()) {
|
for(CoinsInfo coin : selectedCoins.values()) {
|
||||||
coins.setFrozen(coin.getPubKey(), !coin.isFrozen());
|
if(frozenCoinsCopy.contains(coin.getPubKey())) {
|
||||||
|
frozenCoinsCopy.remove(coin.getPubKey());
|
||||||
|
} else {
|
||||||
|
frozenCoinsCopy.add(coin.getPubKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this.frozenCoins = frozenCoinsCopy;
|
||||||
|
this.saveFrozenCoins();
|
||||||
refreshUtxos();
|
refreshUtxos();
|
||||||
|
BalanceService.getInstance().refreshBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCoinFrozen(CoinsInfo coinsInfo) {
|
||||||
|
return frozenCoins.contains(coinsInfo.getPubKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFrozenCoins() throws JSONException {
|
||||||
|
PrefService prefService = PrefService.getInstance();
|
||||||
|
String frozenCoinsArrayString = prefService.getString(Constants.PREF_FROZEN_COINS, "[]");
|
||||||
|
JSONArray frozenCoinsArray = new JSONArray(frozenCoinsArrayString);
|
||||||
|
for(int i = 0; i < frozenCoinsArray.length(); i++) {
|
||||||
|
String pubKey = frozenCoinsArray.getString(i);
|
||||||
|
frozenCoins.add(pubKey);
|
||||||
|
}
|
||||||
|
this.refreshUtxos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveFrozenCoins() {
|
||||||
|
PrefService prefService = PrefService.getInstance();
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
ArrayList<String> frozenCoinsCopy = new ArrayList<>(frozenCoins);
|
||||||
|
for(String pubKey : frozenCoinsCopy) {
|
||||||
|
jsonArray.put(pubKey);
|
||||||
|
}
|
||||||
|
prefService.edit().putString(Constants.PREF_FROZEN_COINS, jsonArray.toString()).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> selectUtxos(long amount, boolean sendAll) throws Exception {
|
public ArrayList<String> selectUtxos(long amount, boolean sendAll) throws Exception {
|
||||||
|
@ -56,7 +103,7 @@ public class UTXOService extends ServiceBase {
|
||||||
Collections.sort(utxos);
|
Collections.sort(utxos);
|
||||||
//loop through each utxo
|
//loop through each utxo
|
||||||
for (CoinsInfo coinsInfo : utxos) {
|
for (CoinsInfo coinsInfo : utxos) {
|
||||||
if (!coinsInfo.isSpent() && coinsInfo.isUnlocked() && !coinsInfo.isFrozen()) { //filter out spent, locked, and frozen outputs
|
if (!coinsInfo.isSpent() && coinsInfo.isUnlocked() && !coinsInfo.isFrozen() && !frozenCoins.contains(coinsInfo.getPubKey())) { //filter out spent, locked, and frozen outputs
|
||||||
if (sendAll) {
|
if (sendAll) {
|
||||||
// if send all, add all utxos and set amount to send all
|
// if send all, add all utxos and set amount to send all
|
||||||
selectedUtxos.add(coinsInfo.getKeyImage());
|
selectedUtxos.add(coinsInfo.getKeyImage());
|
||||||
|
|
|
@ -12,6 +12,7 @@ public class Constants {
|
||||||
public static final String PREF_STREET_MODE = "pref_street_mode";
|
public static final String PREF_STREET_MODE = "pref_street_mode";
|
||||||
public static final String PREF_MONEROCHAN = "pref_monerochan";
|
public static final String PREF_MONEROCHAN = "pref_monerochan";
|
||||||
public static final String PREF_DONATE_PER_TX = "pref_donate_per_tx";
|
public static final String PREF_DONATE_PER_TX = "pref_donate_per_tx";
|
||||||
|
public static final String PREF_FROZEN_COINS = "pref_frozen_coins";
|
||||||
|
|
||||||
public static final String URI_PREFIX = "monero:";
|
public static final String URI_PREFIX = "monero:";
|
||||||
public static final String URI_ARG_AMOUNT = "tx_amount";
|
public static final String URI_ARG_AMOUNT = "tx_amount";
|
||||||
|
|
Loading…
Reference in a new issue