use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class WhirlpoolNotificationService method setMixState.
private void setMixState(NotificationCompat.Builder builder) {
Optional<WhirlpoolWallet> whirlpoolWalletOpt = androidWhirlpoolWalletService.getWhirlpoolWallet();
if (whirlpoolWalletOpt.isPresent()) {
MixingState mixingState = whirlpoolWalletOpt.get().getMixingState();
builder.setContentTitle("Whirlpool online: ".concat(String.valueOf(mixingState.getNbMixing())).concat(" MIXING :").concat(String.valueOf(mixingState.getNbQueued())).concat(" QUEUED"));
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
for (WhirlpoolUtxo whirlpoolUtxo : mixingState.getUtxosMixing()) {
if (whirlpoolUtxo.getUtxoState().getMessage() != null && whirlpoolUtxo.getUtxoConfig().getPoolId() != null)
inboxStyle.addLine(whirlpoolUtxo.getUtxoConfig().getPoolId().concat(" : ").concat(whirlpoolUtxo.getUtxoState().getMessage()));
}
builder.setStyle(inboxStyle);
} else {
builder.setContentText("Whirlpool");
}
}
use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class APIFactory method initWalletAmounts.
private synchronized void initWalletAmounts() {
APIFactory.getInstance(context).reset();
List<String> addressStrings = new ArrayList<String>();
String[] s = null;
try {
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUB44REG, false) == false) {
registerXPUB(HD_WalletFactory.getInstance(context).get().getAccount(0).xpubstr(), 44, null);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUB49REG, false) == false) {
registerXPUB(BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr(), 49, null);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUB84REG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr(), 84, null);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUBPREREG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPremixAccount()).xpubstr(), 84, PrefsUtil.XPUBPREREG);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUBPOSTREG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPostmix()).xpubstr(), 84, PrefsUtil.XPUBPOSTREG);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUBBADBANKREG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolBadBank()).xpubstr(), 84, PrefsUtil.XPUBPOSTREG);
}
xpub_txs.put(HD_WalletFactory.getInstance(context).get().getAccount(0).xpubstr(), new ArrayList<Tx>());
addressStrings.addAll(Arrays.asList(BIP47Meta.getInstance().getIncomingAddresses(false)));
for (String _s : Arrays.asList(BIP47Meta.getInstance().getIncomingLookAhead(context))) {
if (!addressStrings.contains(_s)) {
addressStrings.add(_s);
}
}
for (String pcode : BIP47Meta.getInstance().getUnspentProviders()) {
for (String addr : BIP47Meta.getInstance().getUnspentAddresses(context, pcode)) {
if (!addressStrings.contains(addr)) {
addressStrings.add(addr);
}
}
List<Integer> idxs = BIP47Meta.getInstance().getUnspent(pcode);
for (Integer idx : idxs) {
String receivePubKey = BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), idx);
BIP47Meta.getInstance().getIdx4AddrLookup().put(receivePubKey, idx);
BIP47Meta.getInstance().getPCode4AddrLookup().put(receivePubKey, pcode.toString());
if (!addressStrings.contains(receivePubKey)) {
addressStrings.add(receivePubKey);
}
}
}
if (addressStrings.size() > 0) {
s = addressStrings.toArray(new String[0]);
// info("APIFactory", addressStrings.toString());
utxoObj0 = getUnspentOutputs(s);
}
debug("APIFactory", "addresses:" + addressStrings.toString());
HD_Wallet hdw = HD_WalletFactory.getInstance(context).get();
if (hdw != null && hdw.getXPUBs() != null) {
String[] all = null;
if (s != null && s.length > 0) {
all = new String[hdw.getXPUBs().length + 2 + s.length];
all[0] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
all[1] = BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr();
System.arraycopy(hdw.getXPUBs(), 0, all, 2, hdw.getXPUBs().length);
System.arraycopy(s, 0, all, hdw.getXPUBs().length + 2, s.length);
} else {
all = new String[hdw.getXPUBs().length + 2];
all[0] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
all[1] = BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr();
System.arraycopy(hdw.getXPUBs(), 0, all, 2, hdw.getXPUBs().length);
}
APIFactory.getInstance(context).getXPUB(all, true);
String[] xs = new String[3];
xs[0] = HD_WalletFactory.getInstance(context).get().getAccount(0).xpubstr();
xs[1] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
xs[2] = BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr();
utxoObj1 = getUnspentOutputs(xs);
getDynamicFees();
}
try {
List<JSONObject> utxoObjs = new ArrayList<JSONObject>();
if (utxoObj0 != null) {
utxoObjs.add(utxoObj0);
}
if (utxoObj1 != null) {
utxoObjs.add(utxoObj1);
}
PayloadUtil.getInstance(context).serializeUTXO(utxoObjs);
} catch (IOException | DecryptionException e) {
;
}
//
//
//
List<String> seenOutputs = new ArrayList<String>();
List<UTXO> _utxos = getUtxos(false);
for (UTXO _u : _utxos) {
for (MyTransactionOutPoint _o : _u.getOutpoints()) {
seenOutputs.add(_o.getTxHash().toString() + "-" + _o.getTxOutputN());
}
}
for (String _s : BlockedUTXO.getInstance().getNotDustedUTXO()) {
// debug("APIFactory", "not dusted:" + _s);
if (!seenOutputs.contains(_s)) {
BlockedUTXO.getInstance().removeNotDusted(_s);
// debug("APIFactory", "not dusted removed:" + _s);
}
}
for (String _s : BlockedUTXO.getInstance().getBlockedUTXO().keySet()) {
// debug("APIFactory", "blocked:" + _s);
if (!seenOutputs.contains(_s)) {
BlockedUTXO.getInstance().remove(_s);
// debug("APIFactory", "blocked removed:" + _s);
}
}
String strPreMix = BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPremixAccount()).xpubstr();
String strPostMix = BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPostmix()).xpubstr();
String strBadBank = BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolBadBank()).xpubstr();
JSONObject preMultiAddrObj = getRawXPUB(new String[] { strPreMix });
JSONObject preUnspentObj = getRawUnspentOutputs(new String[] { strPreMix });
debug("APIFactory", "pre-mix multi:" + preMultiAddrObj.toString(2));
debug("APIFactory", "pre-mix unspent:" + preUnspentObj.toString());
boolean parsedPreMultiAddr = parseMixXPUB(preMultiAddrObj);
boolean parsedPreUnspent = parseMixUnspentOutputs(preUnspentObj.toString());
JSONObject postMultiAddrObj = getRawXPUB(new String[] { strPostMix });
JSONObject postUnspentObj = getRawUnspentOutputs(new String[] { strPostMix });
debug("APIFactory", "post-mix multi:" + postMultiAddrObj.toString());
debug("APIFactory", "post-mix unspent:" + postUnspentObj.toString());
boolean parsedPostMultiAddr = parseMixXPUB(postMultiAddrObj);
boolean parsedPostUnspent = parseMixUnspentOutputs(postUnspentObj.toString());
// debug("APIFactory", "post-mix multi:" + parsedPostMultiAddr);
// debug("APIFactory", "post-mix unspent:" + parsedPostUnspent);
// debug("APIFactory", "post-mix multi:" + getXpubPostMixBalance());
// debug("APIFactory", "post-mix unspent:" + getUtxosPostMix().size());
JSONObject badbankMultiAddrObj = getRawXPUB(new String[] { strBadBank });
JSONObject badbankUnspentObj = getRawUnspentOutputs(new String[] { strBadBank });
debug("APIFactory", "bad bank multi:" + badbankMultiAddrObj.toString());
debug("APIFactory", "bad bank unspent:" + badbankUnspentObj.toString());
boolean parsedBadBankMultiAddr = parseMixXPUB(badbankMultiAddrObj);
boolean parsedBadBanktUnspent = parseMixUnspentOutputs(badbankUnspentObj.toString());
//
//
//
List<String> seenOutputsPostMix = new ArrayList<String>();
List<UTXO> _utxosPostMix = getUtxosPostMix(false);
for (UTXO _u : _utxosPostMix) {
for (MyTransactionOutPoint _o : _u.getOutpoints()) {
seenOutputsPostMix.add(_o.getTxHash().toString() + "-" + _o.getTxOutputN());
}
}
for (String _s : UTXOUtil.getInstance().getTags().keySet()) {
if (!seenOutputsPostMix.contains(_s) && !seenOutputs.contains(_s)) {
UTXOUtil.getInstance().remove(_s);
UTXOUtil.getInstance().removeNote(_s);
}
}
List<String> seenOutputsBadBank = new ArrayList<String>();
List<UTXO> _utxosBadBank = getUtxosBadBank(false);
for (UTXO _u : _utxosBadBank) {
for (MyTransactionOutPoint _o : _u.getOutpoints()) {
seenOutputsBadBank.add(_o.getTxHash().toString() + "-" + _o.getTxOutputN());
}
}
for (String _s : UTXOUtil.getInstance().getTags().keySet()) {
if (!seenOutputsBadBank.contains(_s) && !seenOutputs.contains(_s)) {
UTXOUtil.getInstance().remove(_s);
}
}
/*
for(String _s : BlockedUTXO.getInstance().getNotDustedUTXO()) {
// debug("APIFactory", "not dusted:" + _s);
if(!seenOutputsPostMix.contains(_s)) {
BlockedUTXO.getInstance().removeNotDusted(_s);
// debug("APIFactory", "not dusted removed:" + _s);
}
}
*/
for (String _s : BlockedUTXO.getInstance().getBlockedUTXOPostMix().keySet()) {
debug("APIFactory", "blocked post-mix:" + _s);
if (!seenOutputsPostMix.contains(_s)) {
BlockedUTXO.getInstance().removePostMix(_s);
debug("APIFactory", "blocked removed:" + _s);
}
}
// refresh Whirlpool utxos
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (whirlpoolWalletOpt.isPresent()) {
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.DEPOSIT);
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.PREMIX);
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.POSTMIX);
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.BADBANK);
}
} catch (IndexOutOfBoundsException ioobe) {
ioobe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
walletInit = true;
}
use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class WhirlpoolMain method loadMixes.
private void loadMixes(boolean loadSilently) {
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (!whirlpoolWalletOpt.isPresent()) {
return;
}
if (loadSilently)
progressBar.setVisibility(View.VISIBLE);
WhirlpoolWallet wallet = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet().get();
try {
Disposable disposable = filter(wallet, new ArrayList<>(wallet.getMixingState().getUtxosMixing())).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(whirlpoolUtxoViewModelList -> {
adapter.updateList(whirlpoolUtxoViewModelList);
progressBar.setVisibility(View.INVISIBLE);
balanceIndex = balanceIndex - 1;
switchBalance();
}, er -> {
er.printStackTrace();
progressBar.setVisibility(View.INVISIBLE);
});
compositeDisposable.add(disposable);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class WhirlpoolMain method listenPoolState.
private void listenPoolState() throws Exception {
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (!whirlpoolWalletOpt.isPresent()) {
return;
}
WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
Disposable mixStateDisposable = whirlpoolWallet.getMixingState().getObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(mixingState -> {
loadMixes(true);
}, Throwable::printStackTrace);
compositeDisposable.add(mixStateDisposable);
}
use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class SelectPoolFragment method loadPools.
private void loadPools() {
poolViewModels.clear();
this.tx0Amount = NewPoolActivity.getCycleTotalAmount(coins);
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (!whirlpoolWalletOpt.isPresent()) {
return;
}
if (poolsAdapter == null) {
poolsAdapter = new PoolsAdapter(getContext(), poolViewModels);
}
WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
Disposable disposable = Single.fromCallable(whirlpoolWallet::getPools).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((whirlpoolPools) -> {
for (com.samourai.whirlpool.client.whirlpool.beans.Pool whirlpoolPool : whirlpoolPools) {
PoolViewModel poolViewModel = new PoolViewModel(whirlpoolPool);
Long fee = fees.get(1);
;
switch(this.poolCyclePriority) {
case HIGH:
fee = fees.get(2);
break;
case NORMAL:
fee = fees.get(1);
break;
case LOW:
{
fee = fees.get(0);
break;
}
}
poolViewModel.setMinerFee(fee, this.coins);
poolViewModels.add(poolViewModel);
if (poolViewModel.getDenomination() + poolViewModel.getFeeValue() + poolViewModel.getMinerFee() > this.tx0Amount) {
poolViewModel.setDisabled(true);
} else {
poolViewModel.setDisabled(false);
}
}
poolsAdapter.notifyDataSetChanged();
}, Throwable::printStackTrace);
compositeDisposable.add(disposable);
}
Aggregations