use of com.samourai.whirlpool.client.tx0.Tx0 in project samourai-wallet-android by Samourai-Wallet.
the class NewPoolActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_whirlpool_cycle);
Toolbar toolbar = findViewById(R.id.toolbar_new_whirlpool);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
cycleTotalAmount = findViewById(R.id.cycle_total_amount);
cycleTotalAmount.setText(MonetaryUtil.getInstance().getBTCFormat().format(((double) getCycleTotalAmount(new ArrayList<UTXOCoin>())) / 1e8) + " BTC");
fees.add(FeeUtil.getInstance().getLowFee().getDefaultPerKB().longValue() / 1000L);
fees.add(FeeUtil.getInstance().getNormalFee().getDefaultPerKB().longValue() / 1000L);
fees.add(FeeUtil.getInstance().getHighFee().getDefaultPerKB().longValue() / 1000L);
String preselectId = null;
if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("preselected")) {
preselectId = getIntent().getExtras().getString("preselected");
}
if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
account = getIntent().getExtras().getInt("_account");
}
chooseUTXOsFragment = ChooseUTXOsFragment.newInstance(preselectId);
selectPoolFragment = new SelectPoolFragment();
reviewPoolFragment = new ReviewPoolFragment();
selectPoolFragment.setFees(this.fees);
tx0Progress = findViewById(R.id.new_pool_tx0_progress);
newPoolViewPager = findViewById(R.id.new_pool_viewpager);
setUpStepper();
newPoolViewPager.setAdapter(new NewPoolStepsPager(getSupportFragmentManager()));
newPoolViewPager.enableSwipe(false);
confirmButton = findViewById(R.id.utxo_selection_confirm_btn);
confirmButton.setVisibility(View.VISIBLE);
enableConfirmButton(false);
// Disable selection from fragment since post mix utxo's are populated by the activity
if (account != WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix())
chooseUTXOsFragment.setOnUTXOSelectionListener(this::onUTXOSelected);
selectPoolFragment.setOnPoolSelectionComplete((poolViewModel, priority) -> {
selectedPoolViewModel = poolViewModel;
selectedPoolPriority = priority;
if (tx0 != null && poolViewModel != null) {
tx0.setPool(poolViewModel.getDenomination());
}
enableConfirmButton(selectedPoolViewModel != null);
});
confirmButton.setOnClickListener(view -> {
switch(newPoolViewPager.getCurrentItem()) {
case 0:
{
newPoolViewPager.setCurrentItem(1);
initUTXOReviewButton(selectedCoins);
enableConfirmButton(selectedPoolViewModel != null);
break;
}
case 1:
{
try {
tx0.make();
} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
return;
}
calculateTx0(selectedPoolViewModel.getDenomination(), selectedPoolViewModel.getMinerFee() / 1000L);
newPoolViewPager.setCurrentItem(2);
confirmButton.setText(getString(R.string.begin_cycle));
confirmButton.setBackgroundResource(R.drawable.button_green);
reviewPoolFragment.setTx0(tx0);
break;
}
case 2:
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.block_tx0_change).setCancelable(false);
AlertDialog alert = builder.create();
alert.setTitle(R.string.doxxic_change_warning);
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), (dialog, id) -> {
dialog.dismiss();
blockChangeOutput = true;
processWhirlPool();
});
alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
blockChangeOutput = false;
processWhirlPool();
}
});
if (!isFinishing()) {
alert.show();
}
break;
}
}
});
setUpViewPager();
if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
if (account == WhirlpoolMeta.getInstance(getApplication()).getWhirlpoolPostmix()) {
selectedCoins.clear();
List<UTXOCoin> coinList = PreSelectUtil.getInstance().getPreSelected(preselectId);
try {
onUTXOSelected(coinList);
newPoolViewPager.setCurrentItem(1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of com.samourai.whirlpool.client.tx0.Tx0 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.tx0.Tx0 in project samourai-wallet-android by Samourai-Wallet.
the class AndroidWhirlpoolWalletService method computeWhirlpoolWalletConfig.
protected WhirlpoolWalletConfig computeWhirlpoolWalletConfig(TorManager torManager, WhirlpoolWalletPersistHandler persistHandler, boolean testnet, boolean onion, int mixsTarget, String scode, IHttpClient httpClient, BackendApi backendApi) {
IStompClientService stompClientService = new AndroidStompClientService(torManager);
WhirlpoolServer whirlpoolServer = testnet ? WhirlpoolServer.TESTNET : WhirlpoolServer.MAINNET;
String serverUrl = whirlpoolServer.getServerUrl(onion);
NetworkParameters params = whirlpoolServer.getParams();
WhirlpoolWalletConfig whirlpoolWalletConfig = new WhirlpoolWalletConfig(httpClient, stompClientService, persistHandler, serverUrl, params, true, backendApi);
// disable auto-tx0
whirlpoolWalletConfig.setAutoTx0PoolId(null);
// enable auto-mix
whirlpoolWalletConfig.setAutoMix(true);
whirlpoolWalletConfig.setMixsTarget(mixsTarget);
whirlpoolWalletConfig.setScode(scode);
whirlpoolWalletConfig.setMaxClients(1);
whirlpoolWalletConfig.setSecretPointFactory(AndroidSecretPointFactory.getInstance());
whirlpoolWalletConfig.setTx0Service(new AndroidTx0Service(whirlpoolWalletConfig));
for (Map.Entry<String, String> configEntry : whirlpoolWalletConfig.getConfigInfo().entrySet()) {
Log.v(TAG, "whirlpoolWalletConfig[" + configEntry.getKey() + "] = " + configEntry.getValue());
}
return whirlpoolWalletConfig;
}
use of com.samourai.whirlpool.client.tx0.Tx0 in project samourai-wallet-android by Samourai-Wallet.
the class WhirlpoolWalletTest method testTx0.
@Test
public void testTx0() throws Exception {
Collection<UnspentOutputWithKey> spendFroms = new LinkedList<>();
ECKey ecKey = bip84w.getAccountAt(0).getChain(0).getAddressAt(61).getECKey();
UnspentResponse.UnspentOutput unspentOutput = newUnspentOutput("cc588cdcb368f894a41c372d1f905770b61ecb3fb8e5e01a97e7cedbf5e324ae", 1, 500000000);
unspentOutput.addr = new SegwitAddress(ecKey, networkParameters).getBech32AsString();
spendFroms.add(new UnspentOutputWithKey(unspentOutput, ecKey.getPrivKeyBytes()));
Pool pool = whirlpoolWallet.findPoolById("0.01btc");
Tx0Config tx0Config = whirlpoolWallet.getTx0Config().setMaxOutputs(1);
Tx0Preview tx0Preview = whirlpoolWallet.tx0Preview(pool, spendFroms, tx0Config, Tx0FeeTarget.BLOCKS_2);
Tx0 tx0 = whirlpoolWallet.tx0(pool, spendFroms, tx0Config, Tx0FeeTarget.BLOCKS_2);
Assert.assertEquals("dc398c99cf9ce18123ea916d69bb99da44a3979a625eeaac5e17837f879a8874", tx0.getTx().getHashAsString());
Assert.assertEquals("01000000000101ae24e3f5dbcee7971ae0e5b83fcb1eb67057901f2d371ca494f868b3dc8c58cc0100000000ffffffff040000000000000000426a408a9eb379a44ff4d4579118c64b64bbd327cd95ba826ac68f334155fd9ca4e3acd64acdfd75dd7c3cc5bc34d31af6c6e68b4db37eac62b574890f6cfc7b904d9950c300000000000016001441021632871b0f1cf61a7ac7b6a0187e88628291b44b0f00000000001600147e4a4628dd8fbd638681a728e39f7d92ada04070e954bd1d00000000160014df3a4bc83635917ad18621f3ba78cef6469c5f5902483045022100c48f02762ab9877533b5c7b0bc729479ce7809596b89cb9f62b740ea3350068f02205ef46ca67df39d35f940e33223c5ddd56669d953b6ef4948e355c1f3430f32e10121032e46baef8bcde0c3a19cadb378197fa31d69adb21535de3f84de699a1cf88b4500000000", new String(Hex.encode(tx0.getTx().bitcoinSerialize())));
}
Aggregations