tweaks + sweep

This commit is contained in:
m2049r 2017-08-19 18:59:38 +02:00
parent 408b1a68d0
commit a37ca4c0e5
10 changed files with 154 additions and 9 deletions

View File

@ -773,7 +773,12 @@ Java_com_m2049r_xmrwallet_model_Wallet_createTransactionJ(JNIEnv *env, jobject i
return reinterpret_cast<jlong>(tx);
}
//virtual PendingTransaction * createSweepUnmixableTransaction() = 0;
JNIEXPORT jlong JNICALL
Java_com_m2049r_xmrwallet_model_Wallet_createSweepUnmixableTransactionJ(JNIEnv *env, jobject instance) {
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
Bitmonero::PendingTransaction *tx = wallet->createSweepUnmixableTransaction();
return reinterpret_cast<jlong>(tx);
}
//virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename) = 0;
//virtual bool submitTransaction(const std::string &fileName) = 0;

View File

@ -51,6 +51,7 @@ public class SendFragment extends Fragment {
Spinner sMixin;
Spinner sPriority;
Button bPrepareSend;
Button bPaymentId;
LinearLayout llConfirmSend;
TextView tvTxAmount;
TextView tvTxFee;
@ -77,6 +78,7 @@ public class SendFragment extends Fragment {
etAmount = (EditText) view.findViewById(R.id.etAmount);
bSweep = (Button) view.findViewById(R.id.bSweep);
bPrepareSend = (Button) view.findViewById(R.id.bPrepareSend);
bPaymentId = (Button) view.findViewById(R.id.bPaymentId);
llConfirmSend = (LinearLayout) view.findViewById(R.id.llConfirmSend);
tvTxAmount = (TextView) view.findViewById(R.id.tvTxAmount);
@ -177,6 +179,22 @@ public class SendFragment extends Fragment {
}
});
bPaymentId.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
etPaymentId.setText((activityCallback.generatePaymentId()));
}
});
bSweep.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
Helper.hideKeyboard(getActivity());
prepareSweep();
}
});
bSend.setOnClickListener(new View.OnClickListener()
@ -212,8 +230,8 @@ public class SendFragment extends Fragment {
}
private boolean paymentIdOk() {
String spendKey = etPaymentId.getText().toString();
return ((spendKey.length() == 0) || ((spendKey.length() == 64) && (spendKey.matches("^[0-9a-fA-F]+$"))));
String paymentId = etPaymentId.getText().toString();
return paymentId.isEmpty() || activityCallback.isPaymentIdValid(paymentId);
}
private void prepareSend() {
@ -236,12 +254,22 @@ public class SendFragment extends Fragment {
activityCallback.onPrepareSend(txData);
}
private void prepareSweep() {
etAddress.setText(activityCallback.getWalletAddress());
etPaymentId.setText("");
etAmount.setText("");
disableEdit();
showProgress();
activityCallback.onPrepareSweep();
}
private void disableEdit() {
sMixin.setEnabled(false);
sPriority.setEnabled(false);
etAddress.setEnabled(false);
etPaymentId.setEnabled(false);
etAmount.setEnabled(false);
bPaymentId.setEnabled(false);
bSweep.setEnabled(false);
bPrepareSend.setEnabled(false);
}
@ -252,11 +280,13 @@ public class SendFragment extends Fragment {
etAddress.setEnabled(true);
etPaymentId.setEnabled(true);
etAmount.setEnabled(true);
bPaymentId.setEnabled(true);
bSweep.setEnabled(true);
bPrepareSend.setEnabled(true);
}
private void send() {
disableEdit(); // prevent this being sent more than once
activityCallback.onSend();
}
@ -265,8 +295,16 @@ public class SendFragment extends Fragment {
public interface Listener {
void onPrepareSend(TxData data);
void onPrepareSweep();
void onSend();
String generatePaymentId();
boolean isPaymentIdValid(String paymentId);
String getWalletAddress();
}
@Override

View File

@ -66,7 +66,6 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart()");
this.synced = false; // init syncing logic
}
private void startWalletService() {
@ -137,6 +136,13 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
mBoundService = ((WalletService.WalletServiceBinder) service).getService();
//Log.d(TAG, "setting observer of " + mBoundService);
mBoundService.setObserver(WalletActivity.this);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String walletId = extras.getString(REQUEST_ID);
if (walletId != null) {
setTitle(walletId);
}
}
updateProgress();
//TODO show current pbProgress (eg. if the service is already busy saving last wallet)
Log.d(TAG, "CONNECTED");
@ -421,6 +427,33 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
}
}
@Override
public void onPrepareSweep() {
if (mIsBound) { // no point in talking to unbound service
Intent intent = new Intent(getApplicationContext(), WalletService.class);
intent.putExtra(WalletService.REQUEST, WalletService.REQUEST_CMD_SWEEP);
startService(intent);
Log.d(TAG, "SWEEP TX request sent");
} else {
Log.e(TAG, "Service not bound");
}
}
@Override
public String generatePaymentId() {
return getWallet().generatePaymentId();
}
@Override
public boolean isPaymentIdValid(String paymentId) {
return getWallet().isPaymentIdValid(paymentId);
}
@Override
public String getWalletAddress() {
return getWallet().getAddress();
}
void popFragmentStack(String name) {
if (name == null) {
getFragmentManager().popBackStack();

View File

@ -106,7 +106,9 @@ public class WalletFragment extends Fragment implements TransactionInfoAdapter.O
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("Transaction details");
infoItem.txKey = activityCallback.getTxKey(infoItem.hash);
if (infoItem.txKey == null) {
infoItem.txKey = activityCallback.getTxKey(infoItem.hash);
}
builder.setPositiveButton("Copy TX ID", new DialogInterface.OnClickListener() {
@Override

View File

@ -40,7 +40,7 @@ public class TransactionInfo {
public long confirmations;
public List<Transfer> transfers;
public String txKey;
public String txKey = null;
public TransactionInfo(
int direction,

View File

@ -188,7 +188,15 @@ public class Wallet {
long mount, int mixin_count,
PendingTransaction.Priority priority);
//virtual PendingTransaction * createSweepUnmixableTransaction() = 0;
public PendingTransaction createSweepUnmixableTransaction() {
disposePendingTransaction();
long txHandle = createSweepUnmixableTransactionJ();
pendingTransaction = new PendingTransaction(txHandle);
return pendingTransaction;
}
private native long createSweepUnmixableTransactionJ();
//virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename) = 0;
//virtual bool submitTransaction(const std::string &fileName) = 0;

View File

@ -50,6 +50,8 @@ public class WalletService extends Service {
public static final String REQUEST_CMD_TX = "createTX";
public static final String REQUEST_CMD_TX_DATA = "data";
public static final String REQUEST_CMD_SWEEP = "sweepTX";
public static final String REQUEST_CMD_SEND = "send";
public static final int START_SERVICE = 1;
@ -295,6 +297,20 @@ public class WalletService extends Service {
} else {
myWallet.disposePendingTransaction();
}
} else if (cmd.equals(REQUEST_CMD_SWEEP)) {
Wallet myWallet = getWallet();
Log.d(TAG, "SWEEP TX for wallet: " + myWallet.getName());
PendingTransaction pendingTransaction = myWallet.createSweepUnmixableTransaction();
PendingTransaction.Status status = pendingTransaction.getStatus();
Log.d(TAG, "transaction status " + status);
if (status != PendingTransaction.Status.Status_Ok) {
Log.d(TAG, "Create Transaction failed: " + pendingTransaction.getErrorString());
}
if (observer != null) {
observer.onCreatedTransaction(pendingTransaction);
} else {
myWallet.disposePendingTransaction();
}
} else if (cmd.equals(REQUEST_CMD_SEND)) {
Wallet myWallet = getWallet();
Log.d(TAG, "SEND TX for wallet: " + myWallet.getName());

View File

@ -158,4 +158,42 @@
android:text="@string/generate_button_accept"
android:visibility="gone" />
<LinearLayout
android:id="@+id/llFunctions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:orientation="vertical"
android:visibility="gone">
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="@color/colorPrimary" />
<Button
android:id="@+id/bBackup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@color/colorPrimaryDark"
android:text="@string/generate_button_backup" />
<Button
android:id="@+id/bExport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@color/colorPrimaryDark"
android:text="@string/generate_button_export" />
<Button
android:id="@+id/bDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:background="@color/colorAccent"
android:text="@string/generate_button_delete" />
</LinearLayout>
</LinearLayout>

View File

@ -63,7 +63,8 @@
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="@color/colorPrimary"
android:enabled="false"
android:enabled="true"
android:textSize="12sp"
android:text="@string/send_generate_paymentid_hint" />
</LinearLayout>
@ -92,7 +93,7 @@
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="@color/colorPrimary"
android:enabled="false"
android:enabled="true"
android:text="@string/send_sweep_hint" />
</LinearLayout>

View File

@ -59,6 +59,10 @@
<string name="generate_seed">Mnemonic Seed</string>
<string name="generate_button_accept">I have noted the above\nNow, I want to loose all my money!</string>
<string name="generate_button_backup">Backup</string>
<string name="generate_button_export">Export Keys</string>
<string name="generate_button_delete">DELETE</string>
<string name="generate_wallet_watchonly">&lt;Watch Only Wallet&gt;</string>
<string name="generate_wallet_exists">Wallet exists! Choose another name</string>