use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class WhirlpoolNotificationService method listenService.
private void listenService() {
try {
Optional<WhirlpoolWallet> whirlpoolWalletOpt = androidWhirlpoolWalletService.getWhirlpoolWallet();
if (!whirlpoolWalletOpt.isPresent()) {
// whirlpool wallet not opened yet
return;
}
// whirlpool wallet is opened
WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
updateNotification();
Disposable stateDisposable = whirlpoolWallet.getMixingState().getObservable().observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(mixingState -> updateNotification());
Disposable repeatedChecks = Observable.fromCallable(() -> true).repeatWhen(completed -> completed.delay(3, TimeUnit.SECONDS)).subscribe(aBoolean -> {
updateNotification();
notifySuccessMixes(whirlpoolWallet.getMixingState());
}, er -> {
});
compositeDisposable.add(repeatedChecks);
compositeDisposable.add(stateDisposable);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class NewPoolActivity method beginTx0.
private Completable beginTx0(List<UTXOCoin> coins) {
return Completable.fromCallable(() -> {
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (!whirlpoolWalletOpt.isPresent()) {
return true;
}
WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
Collection<UnspentOutputWithKey> spendFroms = new ArrayList<UnspentOutputWithKey>();
for (UTXOCoin coin : coins) {
UnspentResponse.UnspentOutput unspentOutput = new UnspentResponse.UnspentOutput();
unspentOutput.addr = coin.address;
unspentOutput.script = Hex.toHexString(coin.getOutPoint().getScriptBytes());
unspentOutput.confirmations = coin.getOutPoint().getConfirmations();
unspentOutput.tx_hash = coin.getOutPoint().getTxHash().toString();
unspentOutput.tx_output_n = coin.getOutPoint().getTxOutputN();
unspentOutput.value = coin.amount;
unspentOutput.xpub = new UnspentResponse.UnspentOutput.Xpub();
unspentOutput.xpub.path = "M/0/0";
ECKey eckey = SendFactory.getPrivKey(coin.address, account);
UnspentOutputWithKey spendFrom = new UnspentOutputWithKey(unspentOutput, eckey.getPrivKeyBytes());
spendFroms.add(spendFrom);
}
if (selectedPoolPriority == PoolCyclePriority.HIGH) {
tx0FeeTarget = Tx0FeeTarget.BLOCKS_2;
} else if (selectedPoolPriority == PoolCyclePriority.NORMAL) {
tx0FeeTarget = Tx0FeeTarget.BLOCKS_6;
} else if (selectedPoolPriority == PoolCyclePriority.LOW) {
tx0FeeTarget = Tx0FeeTarget.BLOCKS_24;
}
com.samourai.whirlpool.client.whirlpool.beans.Pool pool = whirlpoolWallet.findPoolById(selectedPoolViewModel.getPoolId());
Tx0Config tx0Config;
if (account == WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix()) {
tx0Config = whirlpoolWallet.getTx0Config().setChangeWallet(WhirlpoolWalletAccount.POSTMIX);
} else {
tx0Config = whirlpoolWallet.getTx0Config().setChangeWallet(WhirlpoolWalletAccount.DEPOSIT);
}
Tx0 tx0 = null;
try {
tx0 = whirlpoolWallet.tx0(pool, spendFroms, tx0Config, tx0FeeTarget);
final String txHash = tx0.getTx().getHashAsString();
// tx0 success
if (tx0.getChangeOutput() != null) {
Log.i("NewPoolActivity", "change:" + tx0.getChangeOutput().toString());
Log.i("NewPoolActivity", "change index:" + tx0.getChangeOutput().getIndex());
UTXOUtil.getInstance().add(txHash + "-" + tx0.getChangeOutput().getIndex(), "\u2623 tx0 change\u2623");
UTXOUtil.getInstance().addNote(txHash, "tx0");
if (blockChangeOutput) {
if (account == WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix()) {
BlockedUTXO.getInstance().addPostMix(txHash, tx0.getChangeOutput().getIndex(), tx0.getChangeValue());
} else {
BlockedUTXO.getInstance().add(txHash, tx0.getChangeOutput().getIndex(), tx0.getChangeValue());
}
}
}
NewPoolActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(NewPoolActivity.this, txHash, Toast.LENGTH_SHORT).show();
}
});
Log.i("NewPoolActivity", "result:" + txHash);
} catch (Exception e) {
// tx0 failed
NewPoolActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(NewPoolActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
Log.i("NewPoolActivity", "result:" + e.getMessage());
}
return true;
});
}
use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet in project samourai-wallet-android by Samourai-Wallet.
the class CycleDetail method setMixStatus.
private void setMixStatus() {
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (!whirlpoolWalletOpt.isPresent()) {
// wallet not opened
return;
}
WhirlpoolWallet wallet = whirlpoolWalletOpt.get();
try {
for (WhirlpoolUtxo utxo : wallet.getUtxosPremix()) {
if (utxo.getUtxo().toString().equals(hash)) {
getSupportActionBar().setTitle(utxo.getUtxoConfig().getPoolId());
whirlpoolUtxo = utxo;
makeTxNetworkRequest();
transactionId.setText(utxo.getUtxo().tx_hash);
updateState(whirlpoolUtxo.getUtxoState());
}
}
} 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 onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == NEWPOOL_REQ_CODE && resultCode == Activity.RESULT_OK) {
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (!whirlpoolWalletOpt.isPresent()) {
return;
}
WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
try {
whirlpoolWallet.getUtxosPremix(true);
whirlpoolWallet.getUtxosPostmix(true);
} catch (Exception e) {
e.printStackTrace();
}
new Handler().postDelayed(() -> {
Intent intent = new Intent(this, JobRefreshService.class);
intent.putExtra("notifTx", false);
intent.putExtra("dragged", true);
intent.putExtra("launch", false);
JobRefreshService.enqueueWork(getApplicationContext(), intent);
}, 800);
progressBar.setVisibility(View.VISIBLE);
}
super.onActivityResult(requestCode, resultCode, data);
}
Aggregations