List of usage examples for java.math BigInteger equals
public boolean equals(Object x)
From source file:de.schildbach.wallet.ui.SendCoinsFragment.java
private void handleGo() { state = State.PREPARATION;/*from ww w. java 2s. c o m*/ updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); directPay(sentTransaction); application.broadcastTransaction(sentTransaction); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); activity.setResult(Activity.RESULT_OK, result); } private void directPay(final Transaction transaction) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final String message) { final DialogBuilder dialog = new DialogBuilder(activity); dialog.setIcon(R.drawable.ic_menu_warning); dialog.setTitle(R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + message + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(transaction); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl) .send(paymentIntent.standard, transaction, returnAddress, finalAmount, paymentIntent.payeeData); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, transaction, returnAddress, finalAmount, paymentIntent.payeeData); } } } @Override protected void onInsufficientMoney(final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = new DialogBuilder(activity); dialog.setIcon(R.drawable.ic_menu_warning); dialog.setTitle(R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder( String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))); if (pending.signum() > 0) msg.append("\n\n").append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))); msg.append("\n\n").append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }
From source file:com.coinprism.model.APIClient.java
/** * Gets the list of recent transactions for a given address. * * @param address the address for which to query the recent transactions * @return a list of transactions/*ww w .j a v a 2 s . c o m*/ */ public List<SingleAssetTransaction> getTransactions(String address) throws IOException, JSONException, ParseException, APIException { String json = executeHttpGet(this.baseUrl + "/v1/addresses/" + address + "/transactions"); JSONArray transactions = new JSONArray(json); ArrayList<SingleAssetTransaction> assetBalances = new ArrayList<SingleAssetTransaction>(); for (int i = 0; i < transactions.length(); i++) { JSONObject transactionObject = (JSONObject) transactions.get(i); String transactionId = transactionObject.getString("hash"); Date date = null; if (!transactionObject.isNull("block_time")) date = parseDate(transactionObject.getString("block_time")); HashMap<String, BigInteger> quantities = new HashMap<String, BigInteger>(); BigInteger satoshiDelta = BigInteger.ZERO; JSONArray inputs = transactionObject.getJSONArray("inputs"); for (int j = 0; j < inputs.length(); j++) { JSONObject input = (JSONObject) inputs.get(j); if (isAddress(input, address)) { if (!input.isNull("asset_id")) addQuantity(quantities, input.getString("asset_id"), new BigInteger(input.getString("asset_quantity")).negate()); satoshiDelta = satoshiDelta.subtract(BigInteger.valueOf(input.getLong("value"))); } } JSONArray outputs = transactionObject.getJSONArray("outputs"); for (int j = 0; j < outputs.length(); j++) { JSONObject output = (JSONObject) outputs.get(j); if (isAddress(output, address)) { if (!output.isNull("asset_id")) addQuantity(quantities, output.getString("asset_id"), new BigInteger(output.getString("asset_quantity"))); satoshiDelta = satoshiDelta.add(BigInteger.valueOf(output.getLong("value"))); } } if (!satoshiDelta.equals(BigInteger.ZERO)) assetBalances.add(new SingleAssetTransaction(transactionId, date, null, satoshiDelta)); for (String key : quantities.keySet()) { assetBalances.add(new SingleAssetTransaction(transactionId, date, getAssetDefinition(key), quantities.get(key))); } } return assetBalances; }
From source file:org.opendaylight.vpnservice.elan.internal.ElanInterfaceManager.java
void addElanInterface(ElanInterface elanInterface, InterfaceInfo interfaceInfo, ElanInstance elanInstance) { Preconditions.checkNotNull(elanInstance, "elanInstance cannot be null"); Preconditions.checkNotNull(interfaceInfo, "interfaceInfo cannot be null"); Preconditions.checkNotNull(elanInterface, "elanInterface cannot be null"); String interfaceName = elanInterface.getName(); String elanInstanceName = elanInterface.getElanInstanceName(); List<PhysAddress> staticMacAddresses = elanInterface.getStaticMacEntries(); Elan elanInfo = ElanUtils.getElanByName(elanInstanceName); if (elanInfo == null) { ElanUtils.updateOperationalDataStore(broker, idManager, elanInstance); }//from ww w .j av a 2 s . c o m // Specific actions to the DPN where the ElanInterface has been added, for example, programming the // External tunnel table if needed or adding the ElanInterface to the DpnInterfaces in the operational DS. BigInteger dpId = (interfaceInfo != null) ? dpId = interfaceInfo.getDpId() : null; if (dpId != null && !dpId.equals(ElanConstants.INVALID_DPN)) { InstanceIdentifier<DpnInterfaces> elanDpnInterfaces = ElanUtils .getElanDpnInterfaceOperationalDataPath(elanInstanceName, dpId); Optional<DpnInterfaces> existingElanDpnInterfaces = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaces); if (!existingElanDpnInterfaces.isPresent()) { // ELAN's 1st ElanInterface added to this DPN createElanInterfacesList(elanInstanceName, interfaceName, dpId); /* * Install remote DMAC flow. * This is required since this DPN is added later to the elan instance * and remote DMACs of other interfaces in this elan instance are not present in the current dpn. */ programRemoteDmacFlow(elanInstance, interfaceInfo); // The 1st ElanInterface in a DPN must program the Ext Tunnel table, but only if Elan has VNI if (elanInstance.getVni() != null && elanInstance.getVni().longValue() != 0) { setExternalTunnelTable(dpId, elanInstance); } ElanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(dpId, elanInstance); } else { List<String> elanInterfaces = existingElanDpnInterfaces.get().getInterfaces(); elanInterfaces.add(interfaceName); if (elanInterfaces.size() == 1) {//1st dpn interface ElanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(dpId, elanInstance); } updateElanDpnInterfacesList(elanInstanceName, dpId, elanInterfaces); } } // add code to install Local/Remote BC group, unknow DMAC entry, terminating service table flow entry // call bindservice of interfacemanager to create ingress table flow enty. //Add interface to the ElanInterfaceForwardingEntires Container createElanInterfaceTablesList(interfaceName); createElanStateList(elanInstanceName, interfaceName); if (interfaceInfo != null) { installFlowsAndGroups(elanInstance, interfaceInfo); } // add the static mac addresses if (staticMacAddresses != null) { boolean isInterfaceOperational = isOperational(interfaceInfo); for (PhysAddress physAddress : staticMacAddresses) { InstanceIdentifier<MacEntry> macId = getMacEntryOperationalDataPath(elanInstanceName, physAddress); Optional<MacEntry> existingMacEntry = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, macId); if (existingMacEntry.isPresent()) { elanForwardingEntriesHandler.updateElanInterfaceForwardingTablesList(elanInstanceName, interfaceName, existingMacEntry.get().getInterface(), existingMacEntry.get()); } else { elanForwardingEntriesHandler.addElanInterfaceForwardingTableList(elanInstance, interfaceName, physAddress); } if (isInterfaceOperational) { // Setting SMAC, DMAC, UDMAC in this DPN and also in other DPNs ElanUtils.setupMacFlows(elanInstance, interfaceInfo, ElanConstants.STATIC_MAC_TIMEOUT, physAddress.getValue()); } } if (isInterfaceOperational) { // Add MAC in TOR's remote MACs via OVSDB. Outside of the loop on purpose. ElanL2GatewayUtils.scheduleAddDpnMacInExtDevices(elanInstance.getElanInstanceName(), dpId, staticMacAddresses); } } }
From source file:com.guldencoin.androidwallet.nlg.ui.SendCoinsFragment.java
private void handleGo() { state = State.PREPARATION;//from w w w.j a v a2s .c o m updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); directPay(sentTransaction); application.broadcastTransaction(sentTransaction); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); activity.setResult(Activity.RESULT_OK, result); } private void directPay(final Transaction transaction) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(transaction); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl) .send(paymentIntent.standard, transaction, returnAddress, finalAmount, paymentIntent.payeeData); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, transaction, returnAddress, finalAmount, paymentIntent.payeeData); } } } @Override protected void onInsufficientMoney(final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder( String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))); if (pending.signum() > 0) msg.append("\n\n").append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))); msg.append("\n\n").append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }
From source file:com.ethercamp.harmony.jsonrpc.EthJsonRpcImpl.java
private String sendTransaction(CallArguments args, Account account) { if (args.data != null && args.data.startsWith("0x")) args.data = args.data.substring(2); // convert zero to empty byte array // TEMP, until decide for better behavior final BigInteger valueBigInt = args.value != null ? StringHexToBigInteger(args.value) : BigInteger.ZERO; final byte[] value = !valueBigInt.equals(BigInteger.ZERO) ? ByteUtil.bigIntegerToBytes(valueBigInt) : EMPTY_BYTE_ARRAY;/*from ww w. j av a 2 s. co m*/ final Transaction tx = new Transaction( args.nonce != null ? StringHexToByteArray(args.nonce) : bigIntegerToBytes(pendingState.getRepository().getNonce(account.getAddress())), args.gasPrice != null ? StringHexToByteArray(args.gasPrice) : ByteUtil.longToBytesNoLeadZeroes(eth.getGasPrice()), args.gas != null ? StringHexToByteArray(args.gas) : ByteUtil.longToBytes(90_000), args.to != null ? StringHexToByteArray(args.to) : EMPTY_BYTE_ARRAY, value, args.data != null ? StringHexToByteArray(args.data) : EMPTY_BYTE_ARRAY); tx.sign(account.getEcKey()); validateAndSubmit(tx); return TypeConverter.toJsonHex(tx.getHash()); }
From source file:de.schildbach.wallet.ui.SendCoinsFragmentBackup.java
private void handleGo() { state = State.PREPARATION;/* w w w . j av a 2 s. c o m*/ updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress, finalAmount, null, paymentIntent.payeeData); directPay(payment); application.broadcastTransaction(sentTransaction); final ComponentName callingActivity = activity.getCallingActivity(); if (callingActivity != null) { log.info("returning result to calling activity: {}", callingActivity.flattenToString()); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); if (paymentIntent.standard == Standard.BIP70) BitcoinIntegration.paymentToResult(result, payment.toByteArray()); activity.setResult(Activity.RESULT_OK, result); } } private void directPay(final Payment payment) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(payment); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl, application.httpUserAgent()).send(paymentIntent.standard, payment); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment); } } } @Override protected void onInsufficientMoney(@Nullable final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder(); if (missing != null) msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))) .append("\n\n"); if (pending.signum() > 0) msg.append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n"); msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }
From source file:com.jculb.wallet.ui.SendCoinsFragment.java
private void handleGo() { state = State.PREPARATION;// w ww.ja va 2s. c om updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); //Emptying a wallet with less than 2 DOGE can't be possible due to min fee 2 DOGE of such a tx. /* if (amount.compareTo(BigInteger.valueOf(200000000)) < 0 && sendRequest.emptyWallet) { AlertDialog.Builder bld = new AlertDialog.Builder(activity); bld.setTitle(R.string.send_coins_error_msg); bld.setMessage(R.string.send_coins_error_desc); bld.setNeutralButton(activity.getResources().getString(android.R.string.ok), null); bld.setCancelable(false); bld.create().show(); state = State.FAILED; updateView(); return; }*/ new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress, finalAmount, null, paymentIntent.payeeData); directPay(payment); application.broadcastTransaction(sentTransaction); final ComponentName callingActivity = activity.getCallingActivity(); if (callingActivity != null) { log.info("returning result to calling activity: {}", callingActivity.flattenToString()); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); if (paymentIntent.standard == Standard.BIP70) BitcoinIntegration.paymentToResult(result, payment.toByteArray()); activity.setResult(Activity.RESULT_OK, result); } } private void directPay(final Payment payment) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(payment); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl, application.httpUserAgent()).send(paymentIntent.standard, payment); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment); } } } @Override protected void onInsufficientMoney(@Nullable final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder(); if (missing != null) msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))) .append("\n\n"); if (pending.signum() > 0) msg.append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n"); msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }
From source file:de.jdellay.wallet.ui.SendCoinsFragment.java
private void handleGo() { state = State.PREPARATION;/*from w ww . ja va2s . com*/ updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); //Emptying a wallet with less than 2 CCN can't be possible due to min fee 2 CCN of such a tx. /* if (amount.compareTo(BigInteger.valueOf(200000000)) < 0 && sendRequest.emptyWallet) { AlertDialog.Builder bld = new AlertDialog.Builder(activity); bld.setTitle(R.string.send_coins_error_msg); bld.setMessage(R.string.send_coins_error_desc); bld.setNeutralButton(activity.getResources().getString(android.R.string.ok), null); bld.setCancelable(false); bld.create().show(); state = State.FAILED; updateView(); return; }*/ new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress, finalAmount, null, paymentIntent.payeeData); directPay(payment); application.broadcastTransaction(sentTransaction); final ComponentName callingActivity = activity.getCallingActivity(); if (callingActivity != null) { log.info("returning result to calling activity: {}", callingActivity.flattenToString()); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); if (paymentIntent.standard == Standard.BIP70) BitcoinIntegration.paymentToResult(result, payment.toByteArray()); activity.setResult(Activity.RESULT_OK, result); } } private void directPay(final Payment payment) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(payment); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl, application.httpUserAgent()).send(paymentIntent.standard, payment); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment); } } } @Override protected void onInsufficientMoney(@Nullable final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder(); if (missing != null) msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))) .append("\n\n"); if (pending.signum() > 0) msg.append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n"); msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }
From source file:com.cannabiscoin.wallet.ui.SendCoinsFragment.java
private void handleGo() { state = State.PREPARATION;/*from w w w .ja va 2 s . co m*/ updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); final Payment payment = createPaymentMessage(sentTransaction, returnAddress, finalAmount, null, paymentIntent.payeeData); directPay(payment); application.broadcastTransaction(sentTransaction); final ComponentName callingActivity = activity.getCallingActivity(); if (callingActivity != null) { log.info("returning result to calling activity: {}", callingActivity.flattenToString()); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); if (paymentIntent.standard == Standard.BIP70) BitcoinIntegration.paymentToResult(result, payment.toByteArray()); activity.setResult(Activity.RESULT_OK, result); } } private void directPay(final Payment payment) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(payment); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl, application.httpUserAgent()).send(paymentIntent.standard, payment); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment); } } } @Override protected void onInsufficientMoney(@Nullable final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder(); if (missing != null) msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))) .append("\n\n"); if (pending.signum() > 0) msg.append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n"); msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }
From source file:com.bushstar.kobocoin_android_wallet.ui.SendCoinsFragment.java
private void handleGo() { state = State.PREPARATION;/* w ww.ja va 2 s.c o m*/ updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.ESTMINUSFEE)); new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress, finalAmount, null, paymentIntent.payeeData); directPay(payment); application.broadcastTransaction(sentTransaction); final ComponentName callingActivity = activity.getCallingActivity(); if (callingActivity != null) { log.info("returning result to calling activity: {}", callingActivity.flattenToString()); final Intent result = new Intent(); KobocoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); if (paymentIntent.standard == Standard.BIP70) KobocoinIntegration.paymentToResult(result, payment.toByteArray()); activity.setResult(Activity.RESULT_OK, result); } } private void directPay(final Payment payment) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(payment); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl, application.httpUserAgent()).send(payment); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, Bluetooth.getBluetoothMac(paymentIntent.paymentUrl)).send(payment); } } } @Override protected void onInsufficientMoney(@Nullable final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int HTML5Shift = config.getHTML5Shift(); final int HTML5Precision = config.getHTML5MaxPrecision(); final String HTML5Prefix = config.getHTML5Prefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder(); if (missing != null) msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg1, HTML5Prefix + ' ' + GenericUtils.formatValue(missing, HTML5Precision, HTML5Shift))) .append("\n\n"); if (pending.signum() > 0) msg.append(getString(R.string.send_coins_fragment_pending, HTML5Prefix + ' ' + GenericUtils.formatValue(pending, HTML5Precision, HTML5Shift))) .append("\n\n"); msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }